Following on from the Screen Position experiments, I'm starting a new project series centered around the Absolute World Position node. The first experiment on the list is a Scan Pulse effect, a sweeping pulse that propagates outward through the world, lighting up geometry as it passes, commonly used in games for world scanning mechanics.
We're going to be achieving this through a post process material, so the first step is to set the material domain to Post Process. Next we're going to set up the parameters for the material. We're using three scalar parameters, Pulse Time, Pulse Speed, and Pulse Width, and two vector parameters, Pulse Origin and Pulse Color. I'm going to set a default value of 2400 for Pulse Speed and 360 for Pulse Width.
As the title suggests, we're first going to add an Absolute World Position node. This returns the world space position of each pixel being processed. We then subtract the Pulse Origin parameter from this result and pass it through a VectorLength node to get the distance from the origin to each pixel in world units.
The next step is to get the current radius of the expanding pulse. We multiply the Pulse Time parameter by Pulse Speed and then Subtract the result from the VectorLength output. This gives us the distance of each pixel from the pulse surface, with pixels on the surface returning 0, inside returning negative, and outside returning positive. Next we're going to pass this value through Abs to mirror the negative values to positive so the ring appears symmetrically on both sides of the surface.
The Abs value is then divided by the Pulse Width parameter, giving us a 0 to 1 range where 0 is the center of the ring and 1 is the edge. We then pass this through OneMinus to invert it so the ring center is brightest and the edges fade to 0. A Clamp (0 to 1) cuts off anything beyond the ring edges.
Now that we have the ring mask, we can multiply it with the Pulse Color parameter to apply the desired color for the scan effect. Next we add a SceneTexture node set to PostProcessInput0, which provides the existing rendered scene. Finally we add the colored ring result to this and connect it to Emissive Color to blend the effect over the scene.
To drive this effect at runtime, we first need a Post Process Volume in the level. If one doesn't exist already, add one and set it to Infinite Extent so it affects the entire scene. Next we're going to use a Blueprint to activate the effect and control its parameters at runtime.
We start by creating a Dynamic Material Instance from the scan pulse material on Begin Play. When the pulse is triggered, the Pulse Origin parameter of the material instance is set to the world position of the triggering actor, the material is added to the post process volume, and a timeline begins driving the Pulse Time parameter over its duration to expand the pulse outward. Once the timeline finishes the material is removed from the post process.
The result is a scan pulse that expands outward from the trigger point and lights up geometry as it passes through the scene as shown below.
The project files for this and other Absolute World Position experiments are available on Github: https://github.com/RohitKotiveetil/UnrealEngine--WorldPositionExperiments







Comments
Post a Comment