Col 0200
Col 0200
T
he goal of computer graphics has always been to create increasingly realis-
tic images. Faster processors and more sophisticated rendering techniques
have allowed computer artists to create scenes that come very close to sim-
ulating reality. In particular, computer graphics are good at rendering
architectural scenes. Raytracing and in these terms. However, even the most if I could simply upload a small pro-
radiosity renderings often fool me into basic 3D rendered scene can be gram that handled all my procedural 1
believing I am seeing actual photo- described in these {the preceding or textures? Then all I would need to pro-
graphs. Even in the real-time game the following terms?} terms. A texture vide to the rendering hardware would
market, techniques such as multi-pass map that is applied to a 3D polygon be a few variable settings for each dif-
rendering and precomputed lighting simply describes the color of the light ferent material. Sounds kind of futuris-
have enabled game players to run that leaves that polygon at any point tic, right?
around in a world complete with reflec- on its surface. Likewise, the Gouraud It is not as far out as you think. Shad-
tions, shadows, dynamic lights, and an shading model is a series of parameters ing languages have been around for
impressive amount of texture detail. that controls the interaction of the quite a while. The first, and still most
As I write this, QUAKE 3: ARENA has lights in the scene with the color and commonly used, is Renderman. First
been unleashed upon the world. This roughness of the polygon surface. The described in the late 1980s, this render-
impressive game takes real-time render- power of a shader language, however, ing language has been used to create
ing technology to a new high. Once goes way beyond what we have tradi- some of the most memorable computer
again, the graphics capabilities of this tionally done with real-time 3D render- graphics scenes of all time, including
game {Do you mean as each of id’s ing. Since a shader describes the color the recent movie Toy Story 2. While it
games has done before it? } stretch leaving the surface of polygon, it can may seem that we are a long way from
real-time rendering to its limit, bringing be used to generate a complex pattern creating scenes this complex for real-
even the latest “graphics processing of colors without texture maps. time games, you may be surprised.
units” to their knees. QUAKE 3 also Most of you are familiar with proce- Listing 1 describes a Renderman shad-
marks the industry debut of program- dural textures. This is where a texture er that creates a checkerboard pattern
mable “shaders,” which are used for map is created by some form of mathe- on a surface. The shader takes three float
describing the look of a real-time ren- matical formula instead of being drawn variables and two colors and creates a
dered image. in an art package. Procedural textures checkerboard of any size and frequency.
A shader is a form of programming are commonly used for patterns such This is done without any texture map.
language that describes the look of a as noise (like TV “snow”), lava, water, For a checkerboard, this may not seem
particular surface in a rendered world. marble, or fire. UNREAL implemented very impressive; however, it’s the idea of
In its most abstract sense, it is a func- procedural texture techniques for sev- controlling the look of an individual
tion that is given a series of properties eral effects used throughout its envi- pixel on an individual surface that
and then returns the color of the light ronments. This allowed the designers makes Renderman so powerful. A shader
leaving any position on the shaded sur- to have a nearly unlimited variety of doesn’t need to be as simple as a
face. Normally, the properties given to certain types of textures without hav- checkerboard. Shaders can be used to
a shader include such things as the ing to store all those bitmaps on the create all kinds of surfaces, everything
lights in the scene, the color of the sur- game CD. However, the textures still from highly-detailed wood, marble, and
face, and some measure of the rough- needed to be generated in order to load fire to even a moldy cue ball (my
ness of the surface. them onto the 3D card for rendering. favorite Renderman shader).
Game programmers and artists don’t Wouldn’t it be nice if those textures A closer examination of the checker-
normally think of the rendered world never had to be generated at all? What board shader reveals that the only other
thing the shader really needs to know
When not ditching work to catch the latest animated feature film, Jeff can be found about is the position of the view and
at Darwin 3D trying to convince clients that things can’t look any better. Tell him the lights in the scene. Interestingly,
how wrong he is at [email protected]. the new generation of 3D graphics
hardware such as Nvidia’s GeForce 256
GL to the Rescue
(N • (V − E))(N • (V − E)) ≤ 0
1 2
where Ni are the two face normals for the adjacent polygons,
V is a vertex on the edge, and E is the eye point. When this F I G U R E 2 . A more styl- F I G U R E 3 . Reducing the
statement is true, the edge is part of the silhouette. ized, cartoonish version of depth of colors gives a
As you can imagine, this would be a rather time-consum- the character. more 2D look.
ing process on a model that had any significant number of
model using
glPolygonOffset(). Howev-
er, this can lead to a
mess, so you need to be
careful.
Another approach
that may make cleaner
lines requires the use of
an extra pass and the
stencil buffer. In this
technique, the algo-
rithm is:
1. Draw front facing
textured polygons
2. Set draw mode to
stencil only
3. Draw front facing
edges in line mode
4. Draw back facing
4 lines where stencil
is set.
This will ensure that
only edges that are F I G U R E 4 . To complete the cartoon look of the charac- F I G U R E 5 . Finally, shading is added
shared front and back ter, black outlines were added with OpenGL. with our lighting model.
are drawn. However,
since the stencil buffer
is not commonly available across con- Some Shadier Business tain threshold, ε, the vertex is shaded
sumer hardware, it may be wise simply with the “dark” color. Otherwise, the
standard color is used. The ε value can
to test for it and use it when possible.
In addition to the silhouette lines, I N ow that I have a nice method for
creating cartoon-style characters
probably want to add interior lines that with silhouette lines, I need to think
be changed to allow for more or less
shading on the character. You can see
define changes in the material of the about shading. Applying typical the results of this shading in Figure 5.
character. This cannot really be done Gouraud shading to these characters
easily with just rendering tricks. This would ruin the effect I am trying to
requires a pass through the object to achieve. I need to change the lighting The Squashy and Stretchy Show
detect edges that share polygons with model to make this work.
different materials. These edges are
marked as material boundaries and are
drawn after the render. Luckily, the
In the Gouraud shading system, the
angles between the viewer, light, and
surface normal are used to determine
I think these techniques provide a
new way of thinking about real-time
3D animation. It’s a classic example of
material edges are not viewer-depen- the shade of the vertex. For my simple embracing your limitations. There is
dent so they can be calculated only cartoon rendering, I only want two lots of room for experimentation and
once as a preprocess. shades for each material, light and exploration. Creating the ideal texture
dark. In order to do this, I need to cal- to work with non-photorealistic render-
FOR FURTHER INFO
culate the vertex colors myself. The for- ing will require some creativity on the
Siggraph 1999 had an entire course on mula I applied is: part of artists. Some experimentation
Non-Photorealistic Rendering. If you are (N • (V − E)) < ε
V
with brush patterns and other artistic
styles might be interesting as well.
interested in the topic you should defi-
nitely get the notes or the courses CD: where NV is the vertex normal, V is the Another intriguing idea would be to
“Non-Photorealistic Rendering,” Course vertex position, E is the eye point, and apply some of the soft-body deforma-
17 (Siggraph 1999, ACM Siggraph). ε is the shading threshold. This is very tion techniques that I described in my
similar to the silhouette-detection for- March 1999 column to the models
• Markosian, Lee, and others. “Real- mula. However, in this case, when the (“Collision Response: Bouncy, Trouncy,
Time Non-Photorealistic Rendering,” result of the formula is less than a cer- Fun”). These new squishy objects can
be rendered using NPR techniques to
Proceedings of Siggraph 97. New
York: ACM Siggraph, pp. 415–420.
Acknowledgements get a real Road Runner feel. For this
Thanks to Lisa Washburn at Vector month, play around with the simple
• Uphill, Steve. The Renderman Com- Graphics (http://www.vectorg.com) and cell shader and begin exploring the
panion. New York: Addison Wesley, Tom Knight at Imagination Works (http:// world of the less-than-realistic. Grab
1990. www.imagination-works.com) for the the source code and the application
models and textures used in this article. from the Game Developer web site at
http://www.gdmag.com. ■