lightTargetDirection
Calculates the direction vector from a light's target to the light itself and transforms it from world space to view space.
Core Advantages
Highly abstracts the vector calculation for directional lights, automatically handling the coordinate transformation from world to view space, which ensures correctness in lighting calculations and avoids manual multi-step computations.
Common Uses
Providing the view-space light direction for directional and spotlights to calculate diffuse and specular lighting.
Serving as the basis for determining lighting steps in toon shading.
Providing the core light vector for advanced shading models like anisotropic lighting.
For debugging, by visualizing the light direction as a color.
How to adjust
Its effect is adjusted by moving the light object or its `target` object in JavaScript. Moving the `target` changes the beam's orientation, while keeping the `target` fixed and moving the light changes the angle at which the light hits a surface.
Code Examples
1// Get the view-space direction vector for a targeted light (e.g., a spotlight)
2const lightDirectionInView = lightTargetDirection( mySpotLight );