Game Development Reference
number of lights is relatively small (e.g., a few thousand). On the CPU, a simple
implementation is to find the screen-space axis-aligned bounding boxes (AABBs)
for each light source and loop over all the tiles that are contained in the 2D region
of the AABB. If we have computed the minimum and maximum depths for each
tile, we need to perform an additional test to discard lights that are outside of
the tile in the Z-direction.
On the GPU, a simple brute-force variant works for moderate amounts of
lights (up to around 10,000 lights). In the brute-force variant, each tile is checked
against all light sources. If each tile gets its own thread group, the implementa-
tion is fairly simple and performs relatively well. Obviously, the brute-force algo-
rithm does not scale very well. In our clustered shading implementation [Olsson
et al. 12b], we build a simple light hierarchy (a BVH) each frame and test the
tiles (clusters) against this hierarchy. We show that this approach can scale up
to at least one million lights in real time. The same approach is applicable for
tiled shading as well.
Rendering and shading. The final step is to render all geometry. The pipeline for
this looks almost like a standard forward rendering pipeline; different shaders and
related resources may be attached to different chunks of geometry. There are no
changes to the stages other than the fragment shader.
The fragment shader will, for each generated sample, look up which lights
ing 4.1 ).
As mentioned in the beginning of this article, deferred techniques have some
diculty dealing with transparency since traditional G-buffers only can store
attributes from a single sample at each buffer location [Thibieroz and Grun 10].
However, with forward rendering, we never need to store attributes for samples.
Instead we can simply blend the resulting colors using standard alpha-blending.
Note that we are not solving the order-dependent transparency problem.
Rather, we support, unlike many deferred techniques, standard alpha-blending
where each layer is lit correctly. The application must, however, ensure that
transparent objects are drawn in the correct back-to-front order.
We need to make the following changes, compared to the basic tiled forward
Optional minimum or maximum Z-bounds. We need to consider transparent geom-
etry here, as nonoccluded transparent objects will affect a tile's bounds inasmuch
that it moves a tile's minimum Z-bound (“near plane”) closer to the camera.
We ended up using two different sets of tiles for opaque and transparent
geometries, rather than extending a single set of tiles to include both opaque and