The subject of shading, lighting, and shadows is a broad one, which touches many areas of real-time 3D applications, from the low-level instructions that determine how a pixel is colored or a vertex is positioned, to the higher-level ideas that govern the content creation and art pipeline.
Each year, GPUs with more and more features and higher performance become available; much of that extra power and flexibility is poured into "solving" the problem of creating realistic shading, lighting, and shadows. But we are decidedly not there yet, and we may never be. Every current algorithm for real-time shadows, for example, has artifacts in certain cases, or performance problems in others, or most likely both. Similarly with lighting: you often have to trade interactivity or scene complexity for quality. This part of the book is all about making good choices among these trade-offs and creating great-looking and fast real-time renderings.
In Chapter 9, "Deferred Shading in S.T.A.L.K.E.R.," Oles Shishkovtsov of GSC Game World details the deferred shading architecture developed for the game S.T.A.L.K.E.R. Deferred shading has gained popularity lately, but there are a number of nonobvious pitfalls when one goes to implement this approach. This chapter covers solutions to these problems and explains how to create a robust, flexible, and fast deferred renderer.
Irradiance environment maps enable fast, high-quality diffuse and specular lighting, with one significant caveat: the lighting environment must be static. Gary King of NVIDIA shows how to avoid this limitation in Chapter 10, "Real-Time Computation of Dynamic Irradiance Environment Maps" by using newer GPU features to dramatically accelerate irradiance map creation, making it feasible in real time for use with dynamic scenes.
Accurately rendering complex materials such as denim and wool is a tricky business; the usual texture-mapping approaches don't give realistic results for such materials. In Chapter 11, "Approximate Bidirectional Texture Functions," Jan Kautz of the Massachusetts Institute of Technology presents a method for approximating BTFs (which are a very general description of a material's properties) using precomputation combined with a runtime calculation that is just a fairly simple pixel shader looking up into a volume texture.
The amount of texture detail possible in a scene often has the single greatest impact on the overall visual quality; however, texture detail is often fundamentally limited by hardware texture-size constraints and texture memory space issues. In Chapter 12, "Tile-Based Texture Mapping," Li-Yi Wei of NVIDIA works around these restrictions by synthesizing larger virtual textures at runtime from a smaller set of texture tiles using pixel shaders.
The increased flexibility of modern GPUs is rapidly narrowing the gap between renderings that traditionally could only be done using software algorithms and those that are fully hardware-accelerated. In Chapter 13, "Implementing the mental images Phenomena Renderer on the GPU," Martin-Karl Lefrançois of mental images introduces the architecture of the mental ray renderer, used in the production of numerous feature films, and describes the implementation of its GPU-accelerated components.
The algorithms usually employed for ambient occlusion and indirect lighting are confined to limited environments that cannot be animated, thus limiting their usefulness. In Chapter 14, "Dynamic Ambient Occlusion and Indirect Lighting," Michael Bunnell of NVIDIA describes a technique for accelerating the computation of ambient occlusion and indirect lighting using the GPU, turning the algorithms into real-time solutions.
When visualizing complex objects and architectures, perfect photorealism is often not ideal for understanding structures and object relationships, and nonphotorealistic techniques are necessary to aid comprehension. Marc Nienhaus and Jürgen Döllner of the University of Potsdam explain some techniques that make good use of the latest features of modern GPUs for achieving this goal in real time in Chapter 15, "Blueprint Rendering and 'Sketchy Drawings.'"
In Chapter 16, "Accurate Atmospheric Scattering," Sean O'Neil presents a flexible real-time hardware-accelerated technique for simulating atmospheric scattering that works as well on the ground as it does from space, producing some truly gorgeous visuals.
In GPU Gems (Addison-Wesley, 2004), efficient, high-quality soft shadows were the focus of a number of chapters. Yury Uralsky of NVIDIA shows there's still a lot of life left in the topic in Chapter 17, "Efficient Soft-Edged Shadows Using Pixel Shader Branching." Yury covers techniques for rendering high-quality soft shadow edges as well as optimization techniques based on using pixel shader early-outs to minimize shadow computation cost.
Yuri Kryachko of 1C:Maddox Games presents an overview of the water effect from the game Pacific Fighters in Chapter 18, "Using Vertex Texture Displacement for Realistic Water Rendering." The technique uses the ability of newer GPUs to perform texture fetches at the vertices of a mesh to do true displacement mapping on the water surface, resulting in very high quality and efficient animated water that looks incredibly realistic.
Finally, Tiago Sousa of Crytek introduces a technique for simulating refractive surfaces such as water or glass in Chapter 19, "Generic Refraction Simulation." This technique is a generalization of an effect used in the popular game Far Cry.
Looking back on the year since writing my introduction to the Lighting and Shadows section of the original GPU Gems, it's clear that the pace of innovation has not slowed. Indeed, many of the techniques in this section were simply impossible to achieve a year ago, and many others were impractical. I, for one, can't wait to see what new techniques people come up with in the year ahead!
Cem Cebenoyan, NVIDIA