lightViewPosition
In TSL, automatically provides the position (vec3) of a specified light in the current camera's view space, which is key for view-space lighting calculations.
Core Advantages
Guarantees coordinate-space correctness for lighting and fully automates the complex transformation process. It performs the transform efficiently on the CPU, avoiding per-vertex matrix multiplications on the GPU, while making shader code cleaner and more intentional.
Common Uses
In view space, combined with the vertex's view position to calculate the light direction vector (L) for standard lighting models.
Used for calculating accurate specular highlights, especially the halfway vector in the Blinn-Phong model.
Calculating the distance between a fragment and the light in view space for observer-independent distance attenuation.
For debugging, by visualizing the light's view-space position as a color to verify coordinate transformations.
How to adjust
This node's value is not adjusted directly. It is determined by two factors: the light's position in world space, and the camera's position and orientation in world space. Moving either the light or the camera will change this node's output value.
Code Examples
1// In view space, calculate the direction vector from the surface to the light
2const lightVector = lightViewPosition( myLight ).sub( positionView ).normalize();
3
4// In view space, calculate the halfway vector for specular highlights
5const viewVector = positionView.negate().normalize();
6const halfway = lightVector.add( viewVector ).normalize();