lightPosition
In TSL, automatically provides the world-space position (vec3) of a specified THREE.Light object, which is essential for all lighting calculations.
Core Advantages
It completely automates passing a light's position to the shader, eliminating manual uniform creation and per-frame updates in JavaScript. This decouples shader logic from scene management, making code cleaner and more robust.
Common Uses
Calculating the light direction vector (L) for custom diffuse and specular lighting models.
Calculating the distance to a point light to implement correct light attenuation.
Serving as the geometric origin for volumetric effects like light beams or god rays.
For debugging, by visualizing the light's position as a color to verify data transfer.
How to adjust
This node's value is not adjusted directly. It is controlled by manipulating the position of the associated THREE.Light object in your JavaScript scene graph (e.g., by changing `myLight.position` or moving its parent). The node automatically updates to reflect these changes.
Code Examples
1// Get the direction vector from the surface to the light, for lighting calculations
2const lightDirection = lightPosition( myLight ).sub( positionWorld ).normalize();