logarithmicDepthToViewZ
Converts a non-linear depth value stored in a logarithmic depth buffer back into its corresponding linear, view-space Z coordinate (viewZ).
Core Advantages
Encapsulates the complex logarithmic depth decoding process into a single function, enabling developers to easily implement post-processing effects that rely on linear depth (like SSAO, DoF) while using logarithmic depth to solve Z-fighting.
Common Uses
Screen Space Ambient Occlusion (SSAO)
Depth of Field (DoF)
Volumetric Fog and Light
Debugging and visualizing depth maps
How to adjust
This node's effect is seen in how its output `viewZ` influences other effects. For example, in a fog effect, even if the input `depth` value is constant, increasing the camera's `far` clipping plane distance (one of the inputs) from 1,000 to 100,000 will result in a much larger calculated `viewZ`, making the point appear orders of magnitude farther away and causing the fog to become dramatically denser.
Code Examples
1// In a post-processing pass with logarithmic depth, convert sampled depth to linear viewZ
2const logDepth = depthTexture.sample( uv ).r;
3const viewZ = logarithmicDepthToViewZ( logDepth, cameraNear, cameraFar );