GPU Gems

GPU Gems

GPU Gems is now available, right here, online. You can purchase a beautifully printed version of this book, and others in the series, at a 30% discount courtesy of InformIT and Addison-Wesley.

The CD content, including demos and content, is available on the web and for download.

Part II: Lighting and Shadows

From surface shaders that determine how surface parameters and scene parameters are combined to produce color, to algorithms that organize scene objects in an efficient manner, the choice of a lighting and shadowing algorithm often has the single greatest impact on the design of your rendering engine. Choosing an algorithm influences more than just the look of your scenes: it affects the way content is authored and how complex and interactive your scenes can be. The chapters in this part of the book describe various algorithms for lighting and shadowing, along with techniques for making these algorithms more efficient and robust.

In Chapter 9, "Effective Shadow Volume Rendering," Morgan McGuire thoroughly covers the popular stencil shadow volume technique for rendering real-time shadows. Stencil shadow volumes, although often simple to implement initially, are notoriously difficult to make robust and fast. This chapter focuses on getting the corner cases right and reducing the geometry and fill-rate costs of the technique.

Fabio Pellacini and Kiril Vidimce, in Chapter 10, "Cinematic Lighting," present a general lighting shader based on a shader used by Pixar Animation Studios but simplified for real-time lighting. This uberlight shader, as it is known, was written with the fundamental goal of giving control over as many lighting parameters as possible to the artist lighting the scene.

One of the most popular general real-time lighting algorithms today is shadow maps. A major issue that arises when using shadow maps is aliasing. In Chapter 11, "Shadow Map Antialiasing," Mike Bunnell and Fabio Pellacini describe how to reduce shadow map aliasing efficiently through percentage-closer filtering.

Chapter 12, "Omnidirectional Shadow Mapping" by Philipp S. Gerasimov, extends the shadow map idea to correctly handle omnidirectional (point) light sources. Implementation details, including fallbacks depending on hardware capabilities, are included.

Most shadows in real-time games are hard-edged and aliased, due to their being approximated as simple point lights without area. In the real world, all lights have nonzero area, and therefore all shadows have varying degrees of softness. In Chapter 13, "Generating Soft Shadows Using Occlusion Interval Maps," Will Donnelly and Joe Demers introduce a new technique for accurately rendering soft shadows in static scenes with lights that move along predetermined paths. This technique was used in the NVIDIA GeForce FX 5900 launch demo, "Last Chance Gas."

Simon Kozlov continues the antialiasing crusade in Chapter 14, "Perspective Shadow Maps: Care and Feeding." He presents new ideas on optimizing perspective shadow maps, a new kind of shadow map introduced by Stamminger and Drettakis at SIGGRAPH 2002. Perspective shadow maps strive to reduce or eliminate shadow map aliasing artifacts by maximizing shadow map texel density for objects that are projected to large pixel areas.

Finally, in Chapter 15, "Managing Visibility for Per-Pixel Lighting," John O'Rorke observes that techniques that increase visual complexity also tend to increase the number of batches being sent to the hardware—a crucial metric to minimize if you want to get the best performance out of modern GPUs. This chapter uses a number of visibility techniques to find an optimal set of batches to submit, resulting in large performance gains. The techniques have the nice side effect of reducing both CPU load and GPU load.

Cem Cebenoyan, NVIDIA


Many of the designations used by manufacturers and sellers to distinguish their products are claimed as trademarks. Where those designations appear in this book, and Addison-Wesley was aware of a trademark claim, the designations have been printed with initial capital letters or in all capitals.

The authors and publisher have taken care in the preparation of this book, but make no expressed or implied warranty of any kind and assume no responsibility for errors or omissions. No liability is assumed for incidental or consequential damages in connection with or arising out of the use of the information or programs contained herein.

The publisher offers discounts on this book when ordered in quantity for bulk purchases and special sales. For more information, please contact:

U.S. Corporate and Government Sales
(800) 382-3419

For sales outside of the U.S., please contact:

International Sales

Visit Addison-Wesley on the Web:

Library of Congress Control Number: 2004100582

GeForce™ and NVIDIA Quadro® are trademarks or registered trademarks of NVIDIA Corporation.
RenderMan® is a registered trademark of Pixar Animation Studios.
"Shadow Map Antialiasing" © 2003 NVIDIA Corporation and Pixar Animation Studios.
"Cinematic Lighting" © 2003 Pixar Animation Studios.
Dawn images © 2002 NVIDIA Corporation. Vulcan images © 2003 NVIDIA Corporation.

Copyright © 2004 by NVIDIA Corporation.

All rights reserved. No part of this publication may be reproduced, stored in a retrieval system, or transmitted, in any form, or by any means, electronic, mechanical, photocopying, recording, or otherwise, without the prior consent of the publisher. Printed in the United States of America. Published simultaneously in Canada.

For information on obtaining permission for use of material from this work, please submit a written request to:

Pearson Education, Inc.
Rights and Contracts Department
One Lake Street
Upper Saddle River, NJ 07458

Text printed on recycled and acid-free paper.

5 6 7 8 9 10 QWT 09 08 07

5th Printing September 2007