i
i
i
i
i
i
i
i
7.9. Combining Lights and Materials 281
Since the light shader is separate from the surface shader, each shader can
be used for a longer string of objects, improving efficiency [1410].
Another important advantage has to do with programming and assets
management costs. With the traditional approach, the vertex and pixel
shader programs retrieve each light’s and material’s parameters and com-
pute the effect of one on the other. The deferred shading method of ren-
dering allows a strong separation between lighting and material definition.
In our example application, a deferred shading approach would need 11
shaders (one for each material type to compute the effect of the material
and store the relevant parameters in the G-buffers, plus one for each light
source type) instead of the 25 shaders required by a multipass lighting
approach or the 1050 required by an ¨ubershader approach. The separa-
tion of lighting and material should not be undervalued. This split makes
experimentation simple, as instead of numerous combinations, only one
new shader needs to be added to the system for a new light or material
type [691].
Another advantage of deferred shading is that the time-consuming pro-
cess of determining exactly which lights affect which objects is avoided. In
deferred shading, the model is established in space and lights are applied to
it. Shading can be optimized to be computed only in areas where the light
source has any possible effect. Local light sources affect only small areas
of the screen, and various geometric entities and rendering modes can be
used to determine which pixels to shade. For example, point lights can be
treated as spheres and spotlights as cones to determine what pixels they
affect. Only those pixels where surfaces are inside of the volume of effect
need to be shaded [503, 1288]. Even a directional light (e.g., the sun) can
be optimized by marking the stencil buffer on the initial draw to shade
only pixels affected by it [1174]. Local light sources can be culled based on
area of effect or amount of contribution, or can be combined if found to
affect similar areas of the screen [1018]. Fifty or more dynamic lights in a
scene can easily be handled by deferred shading; a traditional renderer can
handle only a fraction of that number at the same frame rate [691].
Deferred shading does have some drawbacks. The video memory re-
quirements and fill rate costs for the G-buffers are significant, especially
when programming for consoles.
23
The most significant technical limita-
tions are in the areas of antialiasing and transparency. Antialiasing is not
performed and stored for rendered surfaces. To overcome this limitation,
Shishkovtsov [1174] uses an edge-detection method for approximating edge
coverage computations. Supersampling to perform antialiasing is also pos-
sible, but the increase in fill rate makes this approach expensive [1018].
Transparent objects must be drawn using screen-door transparency or ren-
23
For example, the Xbox 360 has 10 megabytes of render-to-texture memory.
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
i
i
i
i
i
i
i
i
7.9. Combining Lights and Materials 283
over deferred shading is that surface materials are not limited by what is
stored in the G-buffers. Also, storing light source descriptions can take
considerably less space than storing a full material description, so memory
and fill rate costs can be reduced.
Further Reading and Resources
A valuable reference for information on BRDFs, global illumination meth-
ods, color space conversions, and much else is Dutr´e’s free online Global
Illumination Compendium [287]. Advanced Global Illumination by Dute
et al. [288] provides a strong foundation in radiometry. Glassner’s Princi-
ples of Digital Image Synthesis [408, 409] discusses the physical aspects of
the interaction of light and matter. The book Color Imaging by Reinhard
et al. [1060] also covers this area, with a focus on the practical use of color
in various fields. Digital Modeling of Material Appearance [275] by Dorsey,
Rushmeier, and Sillion is a comprehensive reference work on all aspects of
modeling material appearance for rendering purposes. Although it is older,
Hall’s Illumination and Color in Computer Generated Imagery is a concise
and thorough explanation of illumination and BRDFs in rendering.
Engel’s book [314] gives implementations for a wide range of shading
models, including Cook-Torrance, Oren-Nayar, Ashikmin-Shirley, and oth-
ers. Since shaders draw so heavily on RenderMan, the two books about
this scene description language [30, 1283] can still be useful for ideas and
inspiration. The book Real-Time Shading by Olano et al. [958], while pre-
dating true shader programming, discusses some BRDF representations in
detail, as well as many other related topics.
Though a relatively new idea, there is already a sizeable literature about
using deferred shading in applications. The interested reader should consult
Koonce [691], Placeres [1018], and Valient [1288] to start; each article has
references to earlier presentations and resources. Please check this book’s
website, http://www.realtimerendering.com, for newer works.
For the reader curious to learn still more about light and color, In-
troduction to Modern Optics by Fowles [361] is a short and accessible in-
troductory text. The colorimetry “bible” is Color Science by Wyszecki
and Stiles [1390]. The Physics and Chemistry of Color by Nassau [921]
describes the physical phenomena behind color in great thoroughness and
detail.
i
i
i
i
i
i
i
i
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset