depth
In a TSL fragment shader, provides the depth information of the already-rendered scene at the current pixel's location, abstracting access to the underlying depth texture.
Core Advantages
Drastically simplifies the process of accessing scene depth by fully automating the complex setup of depth pre-passes, render targets, and coordinate transformations. Developers can efficiently get depth data on-demand just by using this node.
Common Uses
Implementing soft particles by comparing particle depth with scene depth to fade out hard intersections.
Serving as the core data source for Screen-Space Ambient Occlusion (SSAO) to analyze geometric occlusion.
Calculating water depth to create effects like shore-line foam or underwater light attenuation.
As a blur radius controller in custom Depth of Field (DOF) post-processing effects.
How to adjust
This node itself is not adjustable. Its value is determined by the scene's geometry and the camera's position. TSL provides different types of depth nodes (e.g., `depth` for non-linear depth, `viewportLinearDepth` for linear depth), and developers should choose the appropriate one based on their calculation needs.
Code Examples
1// Get the linearized scene depth (e.g., depth of the sea floor)
2const sceneDepth = viewportLinearDepth;
3// Get the linearized depth of the current water surface
4const surfaceDepth = linearDepth( position, camera );
5
6// Calculate water depth and use it to mix in a fog effect
7const waterDepth = sceneDepth.sub( surfaceDepth ).max( 0 );
8const fogFactor = smoothstep( 0, 20, waterDepth );
9const finalColor = mix( originalColor, fogColor, fogFactor );