i
i
i
i
i
i
i
i
282 7. Advanced Shading
dered into the scene after all deferred shading passes are done, since only
one object per pixel can be stored in the G-buffer. From an efficiency
standpoint, if the lighting computations desired are relatively simple, over-
all speed can be worse because the costs of writing and reading the render
targets outweigh any gains from deferring lighting computations.
Even with these caveats, deferred shading is a practical rendering
method used in shipping programs. It can handle large numbers of complex
light sources and naturally separates lighting from materials. In deferred
shading, the whole process of rendering becomes a series of post-processing
effects, once the G-buffers are established.
Variants on the G-buffer approach are possible. One problem with
deferred shading is the limitation on what can be stored per pixel. Even
with the greater number of render targets available with newer GPUs,
there is an imbalance in how much is needed at each pixel. Some surfaces
may need only 6 values stored to evaluate their shader formulae, while
others could use 20 or more. To compute and store 20 values for all visible
surfaces is then a waste of bandwidth. One hybrid approach is to save
out some limited set of values, e.g., depth, normal, diffuse, and specular
contributions. Apply lighting, then render the geometry in the scene again,
this time with shaders that draw upon these common results. In this way,
some of the performance increase from deferred shading can be achieved,
while also providing a wider range of shader choices.
For more flexibility and little additional rework to existing code, an-
other approach is to perform an early z pass. Applications with complex,
expensive shaders and high depth complexity can benefit by performing an
initial pass and establishing the Z-buffer [484, 946, 1065, 1341]. After the
Z-buffer is created, the scene is rendered normally with full shading. In this
way, there is only one shader evaluation performed per pixel, for that of
the closest surface; no time is wasted evaluating shaders for fragments that
are hidden by surfaces rendered later. The cost is that the scene’s geom-
etry is rendered an additional time, though the prepass z-depth rendering
is so simple that it can be extremely rapid. There are some limitations
on pixel shaders for this optimization to work. See Section 18.3.6 for de-
tails. Obtaining and storing the z-depths also turns out to be useful for
other rendering techniques [887, 1341]. For example, fog and soft particle
techniques, discussed in Chapter 10, use the z-depth.
An interesting variant is presented by Zioma [1410]. Instead of first
evaluating the geometry, the areas of effect of local light sources are ren-
dered to and stored in buffers. Depth peeling can be used to handle storing
the information for overlapping light sources. The scene’s geometry is then
rendered, using these stored light representations during shading. Simi-
lar to traditional deferred shading, efficiency is improved by minimizing
switching between shaders. One major advantage that this approach has