getViewPosition
Reconstructs the 3D position of a point in camera view space based on its screen coordinate and depth value, commonly used in post-processing effects.
Core Advantages
It encapsulates the complex inverse coordinate transformation, including automatically handling WebGL/WebGPU depth differences, into a single function, serving as a foundational block for advanced post-processing effects like SSAO, SSR, and volumetric lighting.
Common Uses
Screen Space Ambient Occlusion (SSAO)
Screen Space Reflections (SSR)
High-Quality Depth of Field (DOF)
Distance-based Fog (based on camera distance)
How to adjust
This node's effect is adjusted by manipulating its inputs, particularly `depth`. For instance, multiplying the depth value sampled from a depth texture by a factor less than 1 will cause all reconstructed positions to be closer to the camera, making distance-based effects like fog appear to recede.
Code Examples
1// In a post-processing shader, reconstruct view position from a depth texture
2const depth = depthTexture.sample( screenUV );
3const viewPosition = getViewPosition( screenUV, depth, cameraProjectionMatrixInverse );