[TRIAL VERSION] PART I: NATURAL EFFECTS
[TRIAL VERSION] CHAPTER 1. EFFECTIVE WATER SIMULATION FROM PHYSICAL MODELS
[TRIAL VERSION] CHAPTER 2. RENDERING WATER CAUSTICS
[TRIAL VERSION] CHAPTER 3. SKIN IN THE "DAWN" DEMO
[TRIAL VERSION] CHAPTER 4. ANIMATION IN THE "DAWN" DEMO
[TRIAL VERSION] CHAPTER 5. IMPLEMENTING IMPROVED PERLIN NOISE
[TRIAL VERSION] CHAPTER 6. FIRE IN THE "VULCAN" DEMO
[TRIAL VERSION] CHAPTER 7. RENDERING COUNTLESS BLADES OF WAVING GRASS
[TRIAL VERSION] CHAPTER 8. SIMULATING DIFFRACTION
[TRIAL VERSION] PART II: LIGHTING AND SHADOWS
[TRIAL VERSION] CHAPTER 9. EFFICIENT SHADOW VOLUME RENDERING
[TRIAL VERSION] CHAPTER 10. CINEMATIC LIGHTING
[TRIAL VERSION] CHAPTER 11. SHADOW MAP ANTIALIASING
[TRIAL VERSION] CHAPTER 12. OMNIDIRECTIONAL SHADOW MAPPING
[TRIAL VERSION] CHAPTER 13. GENERATING SOFT SHADOWS USING OCCLUSION INTERVAL MAPS
[TRIAL VERSION] CHAPTER 14. PERSPECTIVE SHADOW MAPS: CARE AND FEEDING
[TRIAL VERSION] CHAPTER 15. MANAGING VISIBILITY FOR PER-PIXEL LIGHTING
[TRIAL VERSION] PART III: MATERIALS
[TRIAL VERSION] CHAPTER 16. REAL-TIME APPROXIMATIONS TO SUBSURFACE SCATTERING
[TRIAL VERSION] CHAPTER 17. AMBIENT OCCLUSIO
[TRIAL VERSION] CHAPTER 18. SPATIAL BRDFS
[TRIAL VERSION] CHAPTER 19. IMAGE-BASED LIGHTING
[TRIAL VERSION] CHAPTER 20. TEXTURE BOMBING
[TRIAL VERSION] PART IV: IMAGE PROCESSING
[TRIAL VERSION] CHAPTER 21. REAL-TIME GLOW
[TRIAL VERSION] CHAPTER 22. COLOR CONTROLS
[TRIAL VERSION] CHAPTER 23. DEPTH OF FIELD: A SURVEY OF TECHNIQUES
[TRIAL VERSION] CHAPTER 24. HIGH-QUALITY FILTERING
[TRIAL VERSION] CHAPTER 25. FAST FILTER-WIDTH ESTIMATES WITH TEXTURE MAPS
[TRIAL VERSION] CHAPTER 26. THE OPENEXR IMAGE FILE FORMAT
[TRIAL VERSION] CHAPTER 27. A FRAMEWORK FOR IMAGE PROCESSING
[TRIAL VERSION] PART V: PERFORMANCE AND PRACTICALITIES
[TRIAL VERSION] CHAPTER 28. GRAPHICS PIPELINE PERFORMANCE
[TRIAL VERSION] CHAPTER 29. EFFICIENT OCCLUSION CULLING
[TRIAL VERSION] CHAPTER 30. THE DESIGN OF FX COMPOSER
[TRIAL VERSION] CHAPTER 31. USING FX COMPOSER
[TRIAL VERSION] CHAPTER 32. AN INTRODUCTION TO SHADER INTERFACES
[TRIAL VERSION] CHAPTER 33. CONVERTING PRODUCTION RENDERMAN SHADERS TO REAL-TIME
[TRIAL VERSION] CHAPTER 34. INTEGRATING HARDWARE SHADING INTO CINEMA 4D
[TRIAL VERSION] CHAPTER 35. LEVERAGING HIGH-QUALITY SOFTWARE RENDERING EFFECTS IN
REAL-TIME APPLICATIONS
[TRIAL VERSION] CHAPTER 36. INTEGRATING SHADERS INTO APPLICATIONS
[TRIAL VERSION] PART VI: BEYOND TRIANGLES
[TRIAL VERSION] CHAPTER 37. A TOOLKIT FOR COMPUTATION ON GPUS
[TRIAL VERSION] CHAPTER 38. FAST FLUID DYNAMICS SIMULATION ON THE GPU
[TRIAL VERSION] CHAPTER 39. VOLUME RENDERING TECHNIQUES
[TRIAL VERSION] CHAPTER 40. APPLYING REAL-TIME SHADING TO 3D ULTRASOUND VISUALIZATION
[TRIAL VERSION] CHAPTER 41. REAL-TIME STEREOGRAMS
[TRIAL VERSION] CHAPTER 42. DEFORMERS
[TRIAL VERSION] APPENDIX
[TRIAL VERSION] PART I: NATURAL EFFECTS
[TRIAL VERSION] NEW ITEM
[TRIAL VERSION] NEW ITEM
[AMBER DEMO]
Part I: Natural Effects
Special effects have differentiated real-time applications throughout the history of
consumer-level graphics accelerators, and more important, they have helped immerse users
into the virtual settings envisioned by designers. In games and in visualization applications,
special effects greatly enhance the user's experience, portraying environments from the surreal
to the photorealistic. Good special effects convince users to suspend their disbelief and
become absorbed in the story or setting. This part of the book collects numerous practical
techniques for creating natural effects that have traditionally been difficult to render properly
and robustly.
Water animation and lighting are some of the most difficult tasks in computer graphics, and two
chapters are dedicated to water rendering. Chapter 1, "Effective Water Simulation from
Physical Models" by Mark Finchof Cyan Worlds¡ªcreators of classic games such as Myst¡ªexplores
animating and lighting water surfaces and provides useful tricks for improving reflections. In Chapter 2,
"Rendering Water Caustics," Daniel S¨¢nchez-Crespo
and I show how to incorporate convincing caustics using a similar basis for water animation.
In Chapter 3, "Skin in the 'Dawn' Demo," Curtis Beeson and Kevin Bjorke
detail the shading techniques used for the fairy in the "Dawn" demo, which was written for the launch
of the NVIDIA GeForce FX 5800 GPU. The chapter provides valuable insights into the development
process¡ªespecially the critical shading decisions influenced by the design goals¡ªwhen NVIDIA created
this cinematic-quality demo that is now synonymous with photorealistic, real-time rendering.
Chapter 4, "Animation in the 'Dawn' Demo," goes on to describe how Dawn was brought to life.
Curtis Beeson
explains how the programmers were able to give the artists control over blend shapes to create a diverse
range of expressions. The chapter also discusses the various trade-offs that were made to perform the
animation in real time.
The versatility of Ken Perlin's Academy Award¨Cwinning Noise algorithm has been shown repeatedly
in real-time and offline computer graphics, starting from its first use in the film Tron. In Chapter 5,
"Implementing Improved Perlin Noise,"
Ken elaborates on recent advancements, as described at SIGGRAPH 2002, which correct two particular
defects of Ken's original work. The chapter also provides an efficient and robust framework for an
implementation of Noise on modern programmable graphics hardware.
In Chapter 6, "Fire in the 'Vulcan' Demo," Hubert Nguyen describes the fire rendering used in the
GeForce FX 5900 launch demo, "Vulcan." Though the effect, like most of the others in this part of the
book, is not a true physical simulation, it does follow in the steps of offline techniques such as the one
used in The Lord of the Rings. The realistic and convincing fiery imagery is made possible through some
enhancements to overcome the performance limitations when rasterizing mass amounts of particles.
Rounding off the focus on the natural elements is Chapter 7, "Rendering Countless Blades of Waving
Grass." Kurt Pelzer
tackles the challenge of depicting vast fields of waving grass using a tried and tested method whose
first incarnation was seen in the "Codecreatures" real-time demo. He expands on this technique to enable
higher-performance rendering that better suits the needs of a game engine, and he details the
content-creation requirements.
Finally, in Chapter 8, "Simulating Diffraction," Jos Stam
considers submicron-scale detail, such as the grooves on compact discs. The chapter describes a
simplification of Jos's diffraction lighting model, first presented at SIGGRAPH 1999. The model has its
foundations on the physical properties of light, which when modeled as a wave, can create colorful
interference patterns.
Juan Guardado, NVIDIA
[AMBER DEMO]
Chapter 1. Effective Water Simulation from Physical Models
Mark Finch
Cyan Worlds
This chapter describes a system for simulating and rendering large bodies of water on the GPU. The
system combines geometric undulations of a base mesh with generation of a dynamic normal map. The
system has proven suitable for real-time game scenarios, having been used extensively in Cyan W orlds'
Uru: Ages Beyond Myst
, as shown in Figure 1-1.
Figure 1-1
Tranquil Pond
1.1 Goals and Scope
Real-time rendering techniques have been migrating from the offline-rendering world over the last few
years. Fast Fourier Transform (FFT) techniques, as outlined in Tessendorf 2001, produce incredible
realism for sufficiently large sampling grids, and moderate-size grids may be processed in real time on
consumer-level PCs. Voxel-based solutions to simplified forms of the Navier-Stokes equations are also
viable (Yann 2003). Although we have not yet reached the point of cutting-edge, offline fluid simulations,
as in Enright et al. 2002, the gap is closing. By the time this chapter is published, FFT libraries will likely
be available for vertex and pixel shaders, but as of this writing, even real-time versions of these
techniques are limited to implementation on the CPU.
At the same time, water simulation models simple enough to run on the GPU have been evolving
upward as well. Isidoro et al. 2002 describes summing four sine waves in a vertex shader to compute
surface height and orientation. Laeuchli 2002 presents a shader calculating surface height using three
Gerstner waves.
We start with summing simple sine functions, then progress to slightly more complicated functions, as
appropriate. We also extend the technique into the realm of pixel shaders, using a sum of periodic wave
functions to create a dynamic tiling bump map to capture the finer details of the water surface.
This chapter focuses on explaining the physical significance of the system parameters, showing that
approximating a water surface with a sum of sine waves is not as ad hoc as often presented. We pay
special attention to the math that takes us from the underlying model to the actual implementation; the
math is key to extending the implementation.
This system is designed for bodies of water ranging from a small pond to the ocean as viewed from a
cove or island. Although not a rigorous physical simulation, it does deliver convincing, flexible, and
dynamic renderings of water. Because the simulation runs entirely on the GPU, it entails no struggle
over CPU usage with either artificial intelligence (AI) or physics processes. Because the system
parameters do have a physical basis, they are easier to script than if they were found by trial and error.
Making the system as a whole dynamic¡ªin addition to its component waves¡ªadds an extra level of life.
1.2 The Sum of Sines Approximation
We run two surface simulations: one for the geometric undulation of the surface mesh, and one for the
ripples in the normal map on that mesh. Both simulations are essentially the same. The height of the
water surface is represented by the sum of simple periodic waves. We start with summing sine functions
and move to more interesting wave shapes as we go.
The sum of sines
gives a continuous function describing the height and surface orientation of the water at all points. In
processing vertices, we sample that function based on the horizontal position of each vertex, conforming
the mesh to the limits of its tessellation to the continuous water surface. Below the resolution of the
geometry, we continue the technique into texture space. We generate a normal map for the surface by
sampling the normals of a sum of sines approximation through simple pixel shader operations in
rendering to a render target texture. Rendering our normal map for each frame allows our limited set of
sine waves to move independently, greatly enhancing the realism of the rendering.
In fact, the fine waves in our water texture dominate the realism of our simulation. The geometric
undulations of our wave surface provide a subtler framework on which to present that texture. As such,
we have different criteria for selecting geometric versus texture waves.
1.2.1 Selecting the Waves
We need a set of parameters to define each wave. As shown in Figure 1-2, the parameters are:
Figure 1-2
The Parameters of a Single Wave Function
Wavelength (L): the crest-to-crest distance between waves in world space. Wavelength L
relates to frequency w as w = 2/L.
Amplitude (A): the height from the water plane to the wave crest.
Speed (S): the distance the crest moves forward per second. It is convenient to express speed
as phase-constant
, where
= S x 2/L.
Direction (D ): the horizontal vector perpendicular to the wave front along which the crest travels.
Then the state of each wave as a function of horizontal position (x, y) and time (t
) is defined as:
Equation 1
And the total surface is:
Equation 2
over all waves i
.
To provide variation in the dynamics of the scene, we will randomly generate these wave parameters within
constraints. Over time, we will continuously fade one wave out and then fade it back in with a different set of
parameters. As it turns out, these parameters are interdependent. Care must be taken to generate an entire set of
parameters for each wave that combine in a convincing manner.
1.2.2 Normals and Tangents
Because we have an explicit function for our surface, we can calculate the surface orientation at any given point
directly, rather than depend on finite-differencing techniques. Our binormal B and tangent T vectors are the partial
derivatives in the x and ydirections, respectively. For any (x, y) in the 2D horizontal plane, the 3D position P
on the surface is:
Equation 3
The partial derivative in the x
direction is then:
Equation 4a
Equation 4b
Similarly, the tangent vector is:
Equation 5a
Equation 5b
The normal is given by the cross product of the binormal and tangent, as:
Equation 6a
Equation 6b
Before putting in the partials of our function H, note how convenient the formulas in Equations 3¨C6 happen to
be. The evaluation of two partial derivatives has given us the nine components of the tangent-space basis. This is a
direct consequence of our using a height field to approximate our surface. That is, P(x, y).x = x and P(x, y).y = y,
which become the zeros and ones in the partial derivatives. It is only valid for such a height field, but is general for
any function H(x, y, t
) we choose.
For the height function described in Section 1.2.1, the partial derivatives are particularly convenient to compute.
Because the derivative of a sum is the sum of the derivatives:
Equation 7
over all waves i
.
A common complaint about waves generated by summing sine waves directly is that they have too much "roll,"
that real waves have sharper peaks and wider troughs. As it turns out, there is a simple variant of the sine function
that quite controllably gives this effect. We offset our sine function to be nonnegative and raise it to an exponent k.
The function and its partial derivative with respect to x
are:
Equation 8a
Equation 8b
Figure 1-3 shows the wave shapes generated as a function of the power constant k
. This is the function we actually use for our texture waves, but for simplicity, we continue to express the waves in
terms of our simple sum of sines, and we note where we must account for our change in underlying wave shape.
Figure 1-3
Various Wave Shapes
1.2.3 Geometric Waves
We limit ourselves to four geometric waves. Adding more involves no new concepts, just more of the same
vertex shader instructions and constants.
Directional or Circular
We have a choice of circular or directional waves, as shown in Figure 1-4. Directional waves require slightly
fewer vertex shader instructions, but otherwise the choice depends on the scene being simulated.
Figure 1-4
Directional and Circular Waves
For directional waves, each of the D i in Equation 1 is constant for the life of the wave. For circular waves, the
direction must be calculated at each vertex and is simply the normalized vector from the center C i
of the wave to the vertex:
For large bodies of water, directional waves are often preferable, because they are better models of wind-driven
waves. For smaller pools of water whose source of waves is not the wind (such as the base of a waterfall), circular
waves are preferable. Circular waves also have the nice property that their interference patterns never repeat. The
implementations of both types of waves are quite similar. For directional waves, wave directions are drawn
randomly from some range of directions about the wind direction. For circular waves, the wave centers are drawn
randomly from some finite range (such as the line along which the waterfall hits the water surface). The rest of this
discussion focuses on directional waves.
Gerstner Waves
For effective simulations, we need to control the steepness of our waves. As previously discussed, sine waves
have a rounded look to them¡ªwhich may be exactly what we want for a calm, pastoral pond. But for rough seas,
we need to form sharper peaks and broader troughs. We could use Equations 8a and 8b, because they produce the
desired shape, but instead we choose the related Gerstner waves
. The Gerstner wave function was originally developed long before computer graphics to model ocean water on a
physical basis. As such, Gerstner waves contribute some subtleties of surface motion that are quite convincing
without being overt. (See Tessendorf 2001 for a detailed description.) We choose Gerstner waves here because
they have an often-overlooked property: they form sharper crests by moving vertices toward each crest. Because
the wave crests are the sharpest (that is, the highest-frequency) features on our surface, that is exactly where we
would like our vertices to be concentrated, as shown in Figure 1-5.
Figure 1-5
Gerstner Waves
The Gerstner wave function is:
Equation 9
Here Qi is a parameter that controls the steepness of the waves. For a single wave i, Qi of 0 gives the usual rolling
sine wave, andQi = 1/(wi Ai ) gives a sharp crest. Larger values of Qi should be avoided, because they will cause
loops to form above the wave crests. In fact, we can leave the specification of Q as a "steepness" parameter for the
production artist, allowing a range of 0 to 1, and using Qi = Q/(wi Ai x numWaves
) to vary from totally smooth waves to the sharpest waves we can produce.
Note that the only difference between Equations 3 and 9 is the lateral movement of the vertices. The height is the
same. This means that we no longer have a strict height function. That is,