Clustered Deferred Rendering is a technical term that is extremely important in rendering and optimizing game graphics (technical art). In addition to dividing the screen into 2D tiles, it also divides the screen in the ``depth (Z-axis)'' direction, and is a cutting-edge drawing method that optimizes light calculations on a 3D spatial block (cluster) basis.
Limitations of conventional rendering methods and background of the Clustered method
With the development of 3D graphics, there has been a demand for placing numerous real-time lights such as street lights, magic lights, and explosions within the game screen. With conventional "Forward Rendering", the rendering load increases in proportion to the number of lights. "Deferred Rendering" was born to overcome this. The Deferred method achieves efficient lighting that does not depend on the number of objects by writing the shape, color, normal information, etc. of all objects to an intermediate screen called the "G Buffer (Geometry Buffer)" and then delaying the light calculations only for pixels on the screen.
However, the conventional Deferred method also had weaknesses. With "Tiled Deferred," which processes the screen by dividing it into vertical and horizontal 2D grids (tiles), if a wall in the foreground and a background far in the background exist within the same tile, all lights from the foreground to the back must be included in the calculation target list, resulting in unnecessary calculations in scenes with large depths. The ultimate solution to this problem is **Clustered Deferred Rendering**. This makes it possible to perform light culling that effectively uses the depth of 3D space.
Real world example: Precise home delivery including building floor and room number
I will explain this advanced space division process by comparing it to a mail delivery system to an apartment.
It is necessary to deliver a large amount of luggage (effect of lights) to an apartment district (game screen). In the conventional Deferred method (Tiled Deferred), packages were sorted together based only on vertical and horizontal area information such as "XX address (2D screen position)". The delivery person arrives at the address, which is occupied by residents from the first floor to the 50th floor. The delivery person has to check and sort through all the piles of packages destined for that area, whether it's for residents on the 1st floor or the 50th floor. The baggage in the front and the baggage in the back are mixed together, resulting in poor efficiency.
On the other hand, **Clustered Deferred** pre-classifies luggage by taking into consideration not only the length and width, but also the height and depth (Z-axis) of ``floor 0 of address XX (3D space block)''. When a delivery person goes to a room on the first floor, he only needs to take the luggage for the residents on the first floor (the light that can actually reach that depth space), and he doesn't have to worry about the luggage on the upper floor. By partitioning the 3D space into finely grid-like boxes (clusters), unnecessary checks and lighting calculations can be eliminated to the extreme, allowing processing to be completed smartly. This makes it much more efficient than conventional 2D area sorting.
Advantages and disadvantages of Clustered Deferred Rendering
| Advantages (what you're good at) | Disadvantages (things I don't like) |
|---|---|
| Can process thousands of dynamic real-time light sources simultaneously | G buffer storage and reading consumes a huge amount of memory bandwidth (VRAM access) |
| Completely eliminates unnecessary light calculations in deep scenes | Translucent cannot be drawn directly with this pass, so the Forward pass must be used in combination. |
| Fast parallel light culling using compute shaders | Not compatible with MSAA (multi-sample anti-aliasing), needs to be devised for blurring process |
Selection criteria in practice
The main indicator for choosing Clustered Deferred Rendering for your project.
- Titles for hardware with plenty of memory bandwidth and powerful GPUs, such as PC and PlayStation 5.
- Scenes with an extremely large number of light sources, such as a science fiction city at night or a cave in a fantasy world where countless torches and magic bullets fly.
- A drawing system that wants to express a sense of atmosphere and beautifully display the interaction of large amounts of light, such as fog or volumetric light.
The following is a code example of a light control manager that assumes Unity's high-end drawing system, obtains the current rendering settings from a script, and prevents and monitors performance degradation due to excessive placement of real-time lights in the scene.
using UnityEngine;
public class ClusteredLightManager : MonoBehaviour
{
[SerializeField] private int maxAllowedRealtimeLights = 200;
void Update()
{
Light[] allLights = FindObjectsOfType<Light>();
int activeRealtimeLights = 0;
foreach (Light lit in allLights)
{
if (lit.enabled && lit.lightmapBakeType == LightmapBakeType.Realtime)
{
activeRealtimeLights++;
}
}
if (activeRealtimeLights > maxAllowedRealtimeLights)
{
Debug.LogWarning($"[Light Warning] Too many realtime lights ({activeRealtimeLights}).");
}
}
}
Cluster deferred is one of the important technologies that supports the visual beauty of modern open world games and AAA titles. Understanding the harmony between the overwhelming visual expression of light and darkness and the smart memory optimization technology that supports it behind the scenes can be said to be essential knowledge in game development.