lightShadowMatrix
In TSL, provides an auto-updating transformation matrix (mat4) that transforms a vertex from world space into a specified light's shadow clip space, forming the mathematical basis for custom shadow mapping.
Core Advantages
It perfectly synchronizes and automates the shadow matrix update process, completely encapsulating the complex internal matrix composition and update logic. Developers get a guaranteed-correct transformation matrix for shadow calculations without manually managing and syncing uniforms.
Common Uses
In the vertex shader, calculating a vertex's coordinate in the light's clip space (shadowCoord) for custom dynamic shadows.
In the fragment shader, providing the correct projective coordinates for sampling a shadow map.
Serving as a projector's transformation matrix to achieve projective texturing effects with a spotlight.
For debugging, by visualizing shadow coordinates as color to inspect the shadow camera's frustum.
How to adjust
This node's value is not adjusted directly. It is controlled by configuring the `shadow` properties of its associated `THREE.Light` object in JavaScript, such as adjusting the `light.shadow.camera` frustum (left, right, near, far) or moving the light itself.
Code Examples
1// In Vertex Shader: Transform vertex from world space to the light's shadow clip space
2vShadowCoord = lightShadowMatrix( myLight ).mul( positionWorld );
3
4// In Fragment Shader: Use the transformed coordinate for a projective sample to determine if in shadow
5const shadow = textureProj( shadowMap, vShadowCoord );