linearDepth
The linearDepth node converts the GPU's internal non-linear depth buffer value into a linear value within the [0, 1] range, which is directly proportional to the actual distance from the camera to a surface.
Core Advantages
Greatly simplifies developing distance-based visual effects (like fog, DoF). It provides an intuitive, predictable value, removing the need for complex math and enabling smooth, artistically controllable results.
Common Uses
Distance Fog
Underwater/Volumetric Effects
Depth of Field (DoF) Calculation
Soft Particle & Scene Blending
How to adjust
The linearDepth node itself has no parameters; adjustments are made by manipulating its output. You can alter the response curve of depth-based effects by applying math functions to its output, such as `pow()` for an exponential effect or `smoothstep()` to precisely control the transition range.
Code Examples
1// Get the linear depth value of the current pixel (0.0 for near, 1.0 for far)
2const fogFactor = linearDepth();
3
4// Directly use this linear value as the mix factor to blend scene and fog colors
5return mix(sceneColor, fogColor, fogFactor);