- Two angles for Lumen
- Trace
- Cost of the light calculation
- Fall-back
- Caches
- Screen space
- Short-range Surface Cache
- World Space Radiance Cache
Two angles for Lumen
To better understand the design philosophy of Lumen, I recommend imagining its working principles from two perspectives:
- Trace: Lumen employs ray tracing technology for global illumination calculations.
- Fall-back: In order to make the most of existing information and save computational resources, Lumen is designed with a series of fallback processes from screen-space tracing to global distance field tracing. Instead of performing tracing entirely, this approach helps to save resources.
Among them, Trace is the core method used by Lumen. However, ray tracing inevitably needs to solve the problem of excessive consumption. That is:
- If ray tracing is performed on the entire scene for every frame and every pixel, Lumen will not be able to achieve 30 frames per second performance on mainstream GPUs.
In order to meet the performance requirements, Lumen's choice is simplification. That is:
- Sacrificing a certain degree of accuracy → reducing computational complexity → improving performance
In terms of reducing computational complexity, Lumen adopts two approaches:
- It utilizes the common sampling technique in ray tracing algorithms to replace the calculation of multiple pixels with the calculation of key sample points.
- It employs the fall-back concept, which we will discuss in the following process.
Trace
When we discuss Ray Tracing, we should actually discuss two main topics:
- How to determine if a ray hits an object and determine the point of intersection.
- How to calculate the lighting information at the intersection point.
The first topic is about Hit checking, while the second topic is about lighting calculations.
Cost of the light calculation
It should be noted that the calculation of the lighting for the hit points is a very resource-intensive process.
This consumption mainly comes from the following points:
- The materials of the hit points may be completely different, which means that we need to load corresponding material shaders, textures, and other resources in order to calculate the lighting result for a point.
- Light rays will bounce repeatedly in the environment, so the hit points may be distributed in various areas of the scene, and the number of hit points may even exceed the number of pixels on the screen.
Therefore, it is necessary to introduce a Cache system to cache the results of this calculation. Different Fall-back mechanisms use different Cache solutions. This will be further discussed in the Fall-back section.
Fall-back
I have divided Lumen's Fall-back into 4 stages:
- Screen Space: The current Ray hits a pixel in screen space that has already been rasterized.
- Short Range: The current Ray does not hit a pixel in screen space, but instead hits some nearby cache information for short-range distances. In the case of SWRT, it is Mesh SDF, and in the case of HWRT, it is TLAS/BLAS.
- Mid Range: The cache for Short Range is not hit, but instead hits a cache for a slightly farther region. This distance range is larger than Short Range, but we can afford more precision loss due to the greater distance.
- Not Hit: Farther than Mid Range, at this point, it can be determined that there is no hit at all, and Skylight is directly sampled as the lighting result.
Caches
As mentioned earlier, in order to reduce the cost of calculating illumination for hit points, Lumen has multiple levels of Cache.
Screen space
For screen space, we already have the GBuffer information for the current position, so this information is the best Cache.
Short-range Surface Cache
For slightly further distances, Lumen precomputes the Mesh and caches the illumination information in the form of Surface Cache.
World Space Radiance Cache
For even further distances, even the Surface Cache becomes costly to compute and store. Therefore, Lumen uses a sparser cache.