getDistanceAttenuation
Calculates the light intensity attenuation factor (0-1) based on distance, using a physically plausible model with a smooth visual cutoff at its boundary.
Core Advantages
Encapsulates an industry-standard, high-quality, and performant light attenuation algorithm, freeing developers from handling complex math (like inverse-square law, singularity avoidance, and smooth windowing functions) to achieve a high-quality falloff effect.
Common Uses
Serving as a core component for PointLights and SpotLights to calculate their distance attenuation.
Providing the physical basis for rendering engine optimizations like Light Culling.
Creating non-physical, stylized lighting effects by adjusting the decay exponent.
Approximating the attenuation for ranged AreaLights.
How to adjust
Effects are changed by adjusting its input parameters. `cutoffDistance` controls 'how far the light can reach,' defining its effective radius. `decayExponent` controls 'how fast the light's energy is lost during travel'; a value of 2 simulates realistic physical attenuation (bright center, fast falloff), 1 provides a linear falloff (more uniform), and higher values cause a much sharper decay.
Code Examples
1// Calculate the distance-based attenuation factor (0-1)
2const attenuation = getDistanceAttenuation( {
3 lightDistance: length( light.position.sub( positionWorld ) ), // distance from surface to light
4 cutoffDistance: light.distance, // light's cutoff range
5 decayExponent: light.decay // decay rate (2=physical)
6} );