orthographicDepthToViewZ
Converts a depth value from an orthographic camera's [0, 1] range into a linear, physically meaningful view-space Z coordinate.
Core Advantages
Encapsulates the orthographic projection's inverse depth calculation into a single node, allowing developers to implement effects based on true linear distance without manual math, improving code readability and reducing errors.
Common Uses
Custom distance fog
Reconstructing world position (for SSAO, deferred rendering, etc.)
Implementing screen-space volumetric effects or decals
How to adjust
The node's effect depends on the accuracy of its inputs. The `near` and `far` values must exactly match the camera parameters used to generate the depth map. For example, providing a smaller `far` value in post-processing than the original camera's will "compress" the reconstructed distance, causing distant fog effects to fail or disappear prematurely.
Code Examples
1// Use uv().x to simulate a depth input from near [0] to far [1]
2const simulatedDepth = uv().x;
3
4// Convert the simulated depth to a linear view-space Z coordinate
5const viewZ = orthographicDepthToViewZ( simulatedDepth, cameraNear, cameraFar );
6
7// For visualization, remap viewZ from [-near, -far] back to the [0, 1] color range
8const visualizedZ = remap( viewZ, cameraNear.negate(), cameraFar.negate(), 0, 1 );
9material.colorNode = visualizedZ;