*Understanding `World Position.y - Object Position (World Space).y`*
This expression computes the signed vertical offset of every pixel or vertex relative to the object's pivot using the world's Y axis.
*Formula*
```
relativeHeight = WorldPosition.y - ObjectPositionWS.y
```
The calculation is performed independently for every vertex or fragment:
`WorldPosition.y` is the world-space Y coordinate of the current point being shaded.
`ObjectPositionWS.y` is the world-space Y coordinate of the object's pivot.
The result is the difference between the two values.
Behavior
Returns *0* at the pivot's world height.
Returns *positive values* above the pivot.
Returns *negative values* below the pivot.
Produces a smooth linear gradient along the world's vertical axis.
Every point on the object receives its own value based on its world-space height.
What affects the result?
*Object Translation*
Moving the object up or down does *not* change the relative values.
Both `WorldPosition.y` and `ObjectPositionWS.y` increase or decrease by the same amount, so their difference remains constant.
*Object Rotation*
Rotating the object changes the values because the calculation always references the world's Y axis.
The gradient does not rotate with the object.
*Object Scaling*
Scaling the mesh changes the world-space positions of its vertices, causing the height values to stretch or compress.
*World Deformation*
If vertices are displaced or bent in world space (such as curved-world shaders), the calculation uses the displaced world positions.
As a result, the height field bends with the deformation instead of remaining a perfectly flat world-space plane.
Mathematical Properties
Linear subtraction of two scalar values.
Continuous across the object's surface.
Independent of the object's absolute world height.
Dependent on the final world-space position of each shaded point.
Represents a signed distance only along the world's Y axis, *not* the true Euclidean distance from the pivot.
This expression is commonly used for height masks, clipping planes, dissolves, vertical gradients, snow accumulation, shoreline effects, and other shaders that require a value representing height relative to an object's pivot.
IN CURVED WORLD SPACE.
#unity #shaders #gamedev #gamedevelopment