[Tech Art] Need help to create a gradient in world space
1597366611 08007a81095d58e2d2de1a1a20a74f8347048f25.jpg

Okay, so let's break this down a little further:

1 – The WorldPosition node returns the absolute world position of each vertex (or pixel if executed in the pixel shader). This means that the position is centered around the world 0,0,0. By subtracting the object's position, you are basically centering these coordinates around the object's position rather than the world 0,0,0.
In your example, you transform 0,0,0 from the object into space, which basically returns the object's position in the world. The same value is returned for all vertices / pixels.

2 – In Unreal, the ObjectBounds node returns the xyz size of the bounding box. Dividing your position above by this will bring your values ​​to -1.1 relative to the size of the field.

3 – Since the above result is in the range of -1, 1, we need this additional step to map it back to 0, 1.

4 – The saturated node only clamps all values ​​to the range 0, 1. It is good practice to saturate things for safety reasons, there are no performance costs. If you plug a value outside of the 0, 1 range into an Lerp node, the values ​​will be extrapolated and you will get really weird results. Frac does what you describe, but between 0 and 1, and returns to 0 when it reaches 1 (Fmod wraps any value instead of 1 for later reference). I hooked up a frac to visualize things as this makes it more visually clear when your values ​​are going out of range.

5 – If you plug the result from me into a lerp you will get the same results!

LEAVE A REPLY

Please enter your comment!
Please enter your name here