INFINITY
A large floating-point constant (typically 1e6) representing a 'practical infinity', used to signify infinite distance or range, or as an initial maximum value in algorithms, while ensuring numerical stability.
Core Advantages
It provides a unified, stable, and readable standard for the concept of 'infinity', preventing inconsistent 'magic numbers' scattered across the code and avoiding computational pitfalls like NaN (Not-a-Number) that can arise from using true mathematical infinity.
Common Uses
Algorithm Initialization: Used as the initial value for the 'closest distance found so far' in search algorithms like ray tracing.
Infinite Range Representation: Sets a practical, large range for conceptually infinite light sources like DirectionalLight.
Camera Far Plane: Serves as a sensible default for a camera's far clip plane to prevent premature clipping of distant objects.
GPGPU Algorithms: Used as the initial distance for unvisited nodes in GPU-implemented algorithms like shortest path finding.
How to adjust
INFINITY is a compile-time constant whose value is a trade-off between 'range' and 'depth precision'. A value too large (e.g., 1e10) severely degrades depth buffer precision, causing Z-fighting. A value too small (e.g., 1e4) will prematurely clip distant objects. The default of 1e6 is a practical balance between rendering large scenes and maintaining sufficient depth precision.
Code Examples
1// In a ray tracing algorithm, initialize the closest hit distance to a very large value
2let minDistance = TSL.INFINITY;
3
4// ... inside a loop, update if a closer intersection is found
5if ( newHitDistance < minDistance ) {
6 minDistance = newHitDistance;
7}