How glTF Handles Infinite Point Light Range
This article provides an overview of how the glTF 2.0 format
processes point light ranges through the
KHR_lights_punctual extension. While real-world point
lights follow an inverse-square falloff that mathematically extends to
infinity, real-time renderers require finite bounds to remain
performant. Below, we examine the mathematical and structural methods
glTF uses to handle pure inverse-square attenuation, how it deals with
undefined boundaries, and how it smoothly truncates light when a cutoff
range is defined.
Physical Attenuation and the Inverse-Square Law
In physical lighting, light emitted from an idealized point spreads radially outward, causing its intensity to diminish according to the inverse-square law:
\[\text{Attenuation} = \frac{1}{\text{distance}^2}\]
Under this formula, the intensity approaches zero as distance increases, but it mathematically never reaches zero. Consequently, a purely physical light source has an infinite attenuation distance.
The glTF Punctual Light Representation
glTF manages point, spot, and directional lights via the
KHR_lights_punctual extension. Within this extension, a
point light defines intrinsic properties such as color
(linear RGB) and intensity (measured in candela for point
lights).
To control how far the light reaches, the extension provides an
optional range property:
- When
rangeis omitted (or undefined): The light is treated as having an infinite range. - When
rangeis defined: The light specifies a cutoff distance measured in meters.
Handling Lights with Infinite Range
When the range property is omitted in a glTF asset, the
specification dictates that the light strictly follows the
inverse-square decay without any artificial distance-based cutoff:
\[\text{Attenuation} = \frac{1}{\max(\text{distance}^2, \epsilon)}\]
Here, \(\epsilon\) represents a small positive value to avoid division by zero when the distance is zero.
Because glTF dictates the interchange format rather than runtime engine architecture, handling an infinite light falls onto the target rendering engine:
- Analytical Calculation: Forward renderers compute the light's contribution for every surface rendered, allowing the mathematical falloff to naturally diminish into imperceptible values.
- Engine-Side Thresholding: Clustered, deferred, or tiled forward renderers typically establish an engine-specific cutoff threshold. An engine will calculate the distance at which the light's irradiance drops below a negligible threshold (such as 1/255th of an 8-bit color value) and internally assign a bounding radius for culling purposes.
Truncating Infinite Range with the glTF Windowing Function
To prevent the performance penalty of evaluating lights across the
entire scene, glTF provides a standardized formula when the
range parameter is specified.
Rather than abruptly cutting off the light at the boundary—which would cause hard, visible edges across surfaces—glTF applies a smooth windowing function derived from common real-time rendering practices:
\[\text{SmoothFactor} = \max\left(\min\left(1.0 - \left(\frac{\text{distance}}{\text{range}}\right)^4, 1.0\right), 0.0\right)^2\]
The overall attenuation is calculated by multiplying the standard inverse-square attenuation by this smoothing factor:
\[\text{Total Attenuation} = \left( \frac{1}{\max(\text{distance}^2, \epsilon)} \right) \times \text{SmoothFactor}\]
How This Balances Physics and Performance
- Near the Light Source: At distances close to the light origin, the ratio of \(\text{distance} / \text{range}\) is small, making the smoothing factor close to \(1.0\). This ensures the falloff remains virtually identical to pure physical inverse-square decay.
- Near the Range Boundary: As distance approaches the
specified
range, the factor smoothly transitions to \(0.0\). At the exact boundary and beyond, the factor becomes zero, eliminating hard artifacts and allowing renderers to safely cull the light using a spherical bounding volume of radius equal torange.