attenuationDistance
Provides a standardized float value representing the direct distance from the light source to the surface point being shaded, serving as the core input for light attenuation calculations.
Core Advantages
Completely abstracts the low-level "get distance" operation, freeing developers from manually managing position uniforms and writing GLSL math, which greatly simplifies custom lighting and all distance-based effects.
Common Uses
Implementing custom, non-physical light attenuation functions.
Driving distance-based visual effects (VFX) like proximity glows or revealing magic runes.
Dynamically switching shader logic (LOD) based on the distance to a light source.
Visualizing a distance field as a grayscale map for debugging purposes.
How to adjust
This node's value is not set directly. It updates automatically when the physical distance between the light source and the rendered object changes in the scene. It is typically used as a direct input variable for mathematical formulas or visual effects.
Code Examples
1// Create a sonar pulse effect expanding from the light source
2const expandingRadius = timerLocal( 1.0 ); // Radius expands and resets over 1 second
3const ringWidth = 0.1;
4
5// Calculate a soft ring based on the difference from the expanding radius
6const pulse = smoothstep( ringWidth, 0.0, abs( attenuationDistance.sub( expandingRadius ) ) );
7emissive = vec3( pulse );