viewportLinearDepth
viewportLinearDepth
Converts the GPU's internal non-linear depth value into a linear depth value (ranging from 0 to 1) that is directly proportional to the actual world distance.
Core Advantages
Provides an intuitive depth value proportional to real distance, making distance-based calculations for effects like fog or underwater scenes simple and visually smooth, avoiding the banding artifacts of non-linear depth.
Common Uses
Distance Fog
Underwater Effects
Atmospheric Scattering
How to adjust
This is a read-only node. Its effect is 'adjusted' by applying math functions to its output linear value in the shader, such as using `pow()` to alter the fog's density curve or `smoothstep()` to create volumetric effects with sharp boundaries.
Code Examples
1// Get the linear depth value (0 to 1), proportional to distance
2const linearDepth = viewportLinearDepth;
3
4// Mix the object's color with the fog color based on linear depth
5return objectColor.mix( fogColor, linearDepth );