
Advanced_Renderman_Book[torrents.ru]
.pdf428 15 Volumetric Shaders for Visual Effect
Listing 15.5 (continued)
illuminance (Pcur) { extern color Cl; extern vector L; color Cscat = Cl; if (density > 0)
Cscat *= 1 - volumeshadow (Pobj, vtransform("object",L), radius, density, noisefreq, stepsize, thresh)
vector LN = normalize(L); vector H = normalize (LN + V);
Lscatter += Kd * Cscat °Y max (LN . N, 0)
+ Ks * Cscat * specularbrdf (LN, N, V, 0.1);
}
return Lscatter * volumecolor(Pobj, stepsize);
}
surface
hypertexture (float Ka = 0.127, Kd = 1, Ks = 0.3; float radius = 10.0;
float opacdensity = 1, lightdensity = 1, shadowdensity = 1; float stepsize = 0.1, shadstepsize = 0.5;
float noisefreq = 2.0; float thresh = 0.5;)
{
Ci = Oi = 0;
/* Do not shade the front of the sphere -- only the back! */ if (N.I > 0) {
/* Find the segment to trace through. The far endpoint is simply
*P. The other endpoint can be found by ray tracing against the
*sphere (in the opposite direction).
*/
point Pobj = transform ("object", P);
vector Iobj = normalize (vtransform ("object", I));
float t0, tl; float hits = raysphere (Pobj, -Iobj, radius, 1.Oe-4, t0, tl); float end = (hits > 0) ? t0 : 0; /* distance to march */
point origin = Pobj - t0*Iobj;
point Worigin = transform ("object", "current", origin);
/* Integrate forwards from the start point */ float d = random()*stepsize;
/* Calculate a reasonable step size */ float ss = min (stepsize, end-d);
429
15.2Ray Marching Techniques
Listing 15.5 (continued)
point Psamp = origin + d*Iobj;
float last dtau = volumedensity (Psamp, radius, noisefreq,stepsize); color last li = volumelight (transform ("object", "current", Psamp),
Psamp, I, last dtau, Kd, Ks, radius, shadowdensity,
noisefreq, shadstepsize, thresh);
/* Sharpen at boundary */
last_dtau = smoothstep (thresh, thresh+0.01, last dtau);
while (d <= end && (comp(Oi,O)<0.1 || comp(Oi,l)<1 || comp(Oi,2)<1))
{
/* Take a step and get the scattered light and density */ ss = clamp (ss, 0.005, end-d);
d += ss;
/* Get the scattered light and density */ Psamp = origin + d*Iobj;
float dtau = volumedensity (Psamp, radius, noisefreq, stepsize); color li = 0;
if (dtau > thresh)
li = volumelight (transform ("object", "current", Psamp),
Psamp, I, dtau, Kd, Ks, radius, shadowdensity, noisefreq, shadstepsize, thresh);
dtau = smoothstep (thresh, thresh+0.01, dtau);
float tau = opacdensity * ss/2 * (dtau + last dtau); color lighttau = lightdensity * ss/2 * (li*dtau +
last_li*last dtau); lighttau = lightdensity * (li + last_li)/2;
float alpha = 1 - exp(-tau);
/* Composite with exponential extinction of background light */
Ci += (1-0i) * lighttau * alpha;
Oi += (1-0i) * alpha; last dtau = dtau; last li = li;
}
}
}
you will want to draw the frontside of the object if objects overlap, or you will get unwanted results. You can build up more complex objects using primitives in this way for use with this volume technique, as the example image in Figure 15.8 illustrates.

430 15 Volumetric Shaders for Visual Effects
Figure 15.7 Image taken from within the volume of a sphere cloud shader.
Figure 15.8 Overlapping solid hypertextures.

431
15.3In the Real World (Volumetric Effects for Production)
Figure 15.9 Teapot in clouds.
1 5.2.4 Holding Out Volumes with Depth Maps
Sometimes we want to embed a solid object in a volume, as illustrated in Figure 15.9. When marching through an object, as we do in shadowclouds, RenderMan does not directly provide us with z-depth values for other objects. But we can get them simply by using shadow maps. We can render a shadow map from the camera's view and incorporate a shadow() call in the surface shader to check if the current point is in shadow. If the shadow() call indicates we are in shadow from the camera depth view, then we set its opacity and color to 0, or just stop tracing the ray after this point.
15.3In the Real World (Volurnetric Effects for Production)
This section describes the process behind creating several of the CG effects shots in Contact, with an emphasis on atmospheric and volumetric effects. Specifically, we
432 15 Volumetric Shaders for Visual Effects
address the opening shot, which begins the movie, and the machine glow sequence, which occurs just before Ellie is hurled through space by the machine.
Contact was a production that had a great number of diverse CG effects shots. The opening shot was conceived halfway through production and was originally planned to be 90 seconds long. By the end of the show, in order to impress upon the audience the awe and immensity of space, the shot had grown to 3 minutes and 27 seconds of full film-resolution CG animation. When we began the opening shot, half the show's production schedule was behind us and the artwork for the shot had not been worked on yet. Initial efforts for the opening shot revolved around gathering existing astrophotographs from NASA, Hubble Space Telescope pictures, and generating images from within our own art department. Long-time concept artists for Carl Sagan, Jon Lomberg and Don Davis, also provided initial reference images. Robert Zemekis, Ken Ralston, and Stephen Rosenbaum chose from the best of these reference images, and sequence supervisor Jay Redd modeled and choreographed a 3D animatic wireframe pull-out of our universe using accurate scale.
At this point, I started work on the Eagle Nebula and during the rest of the production the shots I worked on in some way or another involved volumetric effects. In this section I would like to share some of the wisdom we gained while creating these shots.
15.3.1 Opening Shot
When I first joined the opening shot team I was excited about the possibilities, until they assigned me the Eagle Nebula and dropped stacks of reference photos on my desk, all depicting nebulous volumes of stellar gas being lit by the hundreds of stars around it and buried within it. I have to admit it wasn't until several weeks later that it really hit me how hard it was to do lit gas in the time frame we had for the shot. As you can see by the Hubble Space Telescope image (Figure 15.10), the task was a little daunting.
We began with the ray marching idea of the previous section. We progressed pretty far before hitting several roadblocks, mainly related to controlling the shape of the noise. After struggling for a while, we chose a particle approach instead, for several reasons.
First, it is common to come up with a brilliant method for doing an effect beautifully only to have the director request changes to several parts of the image, all of which you have almost no control over with the method you are using. Noise is notoriously difficult to control in a precise way-like taking away this cloud piece or toning down this area of the pillar-but particles allow this kind of control naturally.
The second major reason we went with particles was the fact that we knew we would be able to make it work, and with the ray marching method there were simply too many unknowns at that time. With the deadline approaching, we had no leeway for taking a blind alley and having nothing to show the director at the end.

433
15.3 In the Real World (Volumetric Effects for Production)
Figure 15.10 Hubble telescope image of the Eagle Nebula. (Image courtesy of NASA.)
Finally, the techniques to compute volumetric lit gas take far too long to render with the detail we needed for this scene. In the beginning of the shot, we pass very close to one of the pillars, and by the end of the shot we translate out until we can see the whole of the nebula. This is the worst case, going from very high detail close in to a very wide shot where that detail cannot still exist without aliasing. With the ray marching method, we were scared that the rendering times would be unmanageable. We also knew we would need to render the shot many times before we got the look the director wanted.
15.3.2 The Eagle: How We Did It
Rik Stringfellow, then senior technical director at Sony Imageworks, and I achieved the Eagle Nebula effect using the following method.
First, we broke the gas down into three major sections: the three main pillars of dense stellar gas, the inner gas surrounding those pillars, and the far-reaching oyster-shell-shaped nebulous cloud surrounding the other two elements.
434 15 Volumetric Shaders for Visual Effects
For the main pillars we used tens of thousands of spheres, each with a cloud shader similar to that in Listing 15.1. We built a model around the volume of the inner pillars (see Figure 15.11) and then shot sphere particles into the center of those pillars using Houdini's particle system. We managed this by emitting particles from all points on the tessellated geometry in the direction of their inverted normals (i.e., into the inside of the volume of the three pillars).
We tried to keep the shaders for the particles as simple as possible. We basically used a glow shader with turbulence functions to add variation to the color of the surface. We added in the ability to light this gas as well as controls for the detail level, color, density, and antialiasing of the gas. Because we needed to fly through the volume of gas, and we didn't want the gas to suddenly pop on-screen, we faded the opacity on with distance from the camera to produce a feeling that the gas was slowly building up. The stars were done by building lights with carefully controlled attenuation. To get some level of shadowing, we used attenuation away from the light sources, darkened particles based on which side of the pillar they were emitted from, and used 2D compositing tricks. All of this helped add to the dense feeling of the gas when we had passed the pillars and were viewing them from far away.
For the inner gas, we used even more spheres, all with the same basic shader used for the pillars, and varied the density of the spheres throughout the volume. This seemed to work well, producing random spots of dense dark matter that had a much more natural placement than if we had placed those dense spots by hand. But we did add and remove some dark matter by hand, just as we predicted we would need to do.
We built the shape of the outer gas by emitting particle spheres around basic geometry, which was actually never included in the final render. Then we modified the shaders to take a percentage of their color values from projection lights in the scene. In this way we could more easily approach the general color and look of the reference photos we had. A simple texture map would not have produced the perspective shift that helps to sell the scale of the shot. The addition of noise, in addition to the projected color, helped to break up any streaking that might have occurred had we used only the projected maps for color. The outer gas by itself, as included in the composite for the film, is shown in Figure 15.12.
We have found that the general technique of combining painted and procedural textures works extremely well. To achieve the overall look of the Eagle Nebula would have taken a lot longer had we used procedural methods alone. In addition, this technique gave us some fine control over the color of the scene very rapidly. It is faster and easier to predict the result of modifying colors in 2D than it is with purely procedural color changes. We also added procedurally defined stars within the gas. Finally, an extra layer of dark matter on the outside of the shell helped to achieve some of the backlit effect in the overhanging lip of the outer shell of stellar gas. Rik Stringfellow composited the elements together to form the

435
15.3 In the Real World (Volumetric Effects for Production)
Figure 15.11 Modeling the Eagle Nebula. An actual NASA photograph of the Eagle Nebula (top). CG models of the nebula (middle and bottom). (Top photograph courtesy of NASA. Middle and bottom images Sony Pictures Imageworks, Inc. © 1997). See also color plate 15.11.

436 15 Volumetric Shaders for Visual Effects
Figure 15.12 CG rendering of the Eagle Nebula. (CONTACT © 1997 Warner Bros., a division of Time Warner Entertainment Company L.P. All Rights Reserved.) See also color plate 15.12.
Figure 1 5.13 CG rendering a close-up of the Eagle Nebula. (CONTACT ©1997 Warner Bros., a division of Time Warner Entertainment Company L.P. All Rights Reserved.) See also color plate 15.13.
finished look, and Jay Redd composited the Eagle into the Milky Way (see Figure 15.13).
15.3.3 Machine Glow Sequence
The ray marching technique we had originally planned for the Eagle Nebula (before switching to the particle method) eventually paid off, though, because we were able to use the shader in another sequence to produce electrical-like effects around the core of the machine. Laurence Treweek expanded the basic ray marching shader to produce the effect of the machine glow. The electrical pattern inside the volume was produced by using spherical coordinates to create a 3D texture function that, when animated, moved inwards toward the center of the sphere. This created the chaotic turbulent core as seen in the movie (Figure 15.14). We used the shadow