GPU Gems 2

GPU Gems 2

GPU Gems 2 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: Shading, Lighting, and Shadows

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


Copyright

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.

NVIDIA makes no warranty or representation that the techniques described herein are free from any Intellectual Property claims. The reader assumes all risk of any such claims based on his or her use of these techniques.

The publisher offers excellent discounts on this book when ordered in quantity for bulk purchases or special sales, which may include electronic versions and/or custom covers and content particular to your business, training goals, marketing focus, and branding interests. For more information, please contact:

U.S. Corporate and Government Sales
(800) 382-3419
corpsales@pearsontechgroup.com

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

International Sales
international@pearsoned.com

Visit Addison-Wesley on the Web: www.awprofessional.com

Library of Congress Cataloging-in-Publication Data

GPU gems 2 : programming techniques for high-performance graphics and general-purpose
computation / edited by Matt Pharr ; Randima Fernando, series editor.
p. cm.
Includes bibliographical references and index.
ISBN 0-321-33559-7 (hardcover : alk. paper)
1. Computer graphics. 2. Real-time programming. I. Pharr, Matt. II. Fernando, Randima.

T385.G688 2005
006.66—dc22
2004030181

GeForce™ and NVIDIA Quadro® are trademarks or registered trademarks of NVIDIA Corporation.

Nalu, Timbury, and Clear Sailing images © 2004 NVIDIA Corporation.

mental images and mental ray are trademarks or registered trademarks of mental images, GmbH.

Copyright © 2005 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 in the United States on recycled paper at Quebecor World Taunton in Taunton, Massachusetts.

Second printing, April 2005

Dedication

To everyone striving to make today's best computer graphics look primitive tomorrow