If you want to get to the cutting edge of game or computer graphics programming, and stay there, you need to understand programmable shading. No lie: This stuff’s challenging. But if you’re comfortable with C++, Direct3D ShaderX: Vertex and Pixel Shader Tips and Tricks will get you the rest of the way.
First, a little background. As Wolfgang F. Engel notes at the very beginning of this book, PC graphics are a whole lot faster since 3dfx introduced its breakthrough Voodoo cards back in ’95 -- but they haven’t gotten as much better as they should have. One big reason: Conventional PC graphics accelerators have been “fixed function” -- their graphics algorithms are hard-coded into silicon. (It’s one reason PC computer graphics tend to look alike.)
While PC game designers have struggled with the inflexibility of these video systems, the rest of the world hasn’t stood still. Take a look at Toy Story or Monsters, Inc., and you’ll see photorealistic graphics of breathtaking quality. Pixar’s RenderMan software made them possible. RenderMan is thoroughly programmable and can evolve as new rendering techniques arrive. Wouldn’t it be wonderful if the same flexibility were available in cheap PC hardware and in Windows?
Well, finally, it is. In addition to the Direct 3D fixed-function Transform & Lighting (T&L) pipeline that graphics designers have used for years, DirectX 8 (and beyond) offer vertex shaders, allowing you to evade the pipeline and write programs that execute directly on your graphics hardware. Recent boards like the nVIDIA GeForce3/4TI and ATI RADEON 8x00 not only support vertex shaders, but also provide hardware support for pixel shaders, small programs that execute on individual pixels to control color, lighting, and texture.
If you’ve got the gear and the programming chops, all you need is this book, and you’re in business. Engel (whose previous titles include Beginning Direct3D Game Programming) starts with the fundamentals: what it takes to start programming both vertex and pixel shaders in Windows environments, including techniques for lighting, transformations, texture mapping and effects, and per-pixel lighting. (Yes, this stuff can be done with OpenGL, too, but that’s a different book.)
Engel helps you build your skills incrementally. For example, he starts with a simple example program, then evolves it to incorporate a Bézier patch class with a diffuse, specular reflection model and a point light source. Section I ends with a thorough introduction to a powerful new shader development tool, Shader Studio, written by its developer, John Schwab. (You’ll find Release 1.0 on CD-ROM.)
In the book’s remaining 33 chapters, Engel gathers more than two dozen 3D graphics pros to show you all that can be done with vertex and pixel shaders. They’re an impressive crowd: both game designers and the engineers who are implementing programmable shaders for ATI, nVIDIA, et al. Folks like ATI’s Jason Mitchell, who worked with Microsoft in Redmond to help define the very pixel shader features introduced in this book.
There’s a full section on vertex shader tricks, including vertex decompression, shadow volume extrusion, lighting a single-surface object, and using Perlin Noise, Ken Perlin’s classic technique for producing natural appearing textures on computer generated surfaces.
Next, Engel’s team moves on to pixel shader tricks -- and this is the real heart of the book. You’ll find case studies and code that demonstrate how to blend textures for terrain; emulate geometry with shaders; create smooth lighting effects; and build more accurate environment-mapped reflections and refractions by adjusting for object distance. Kenneth Hurley, now at nVIDIA but with 17 years of game development experience at the likes of Activision, EA, and Intel, shows how to use vertex and pixel shaders to create photorealistic faces. There are chapters on rendering animated grass, texture perturbations, ocean water, rippling water, crystal and candy, particle flows, and much more.
A shorter section focuses on using 3D textures with shaders, and finally, you’ll find three full chapters on incorporating shaders in the design of advanced game engines.
These days, it’s not easy to set yourself above the pack as a game programmer, but with this book’s techniques, you will. (Bill Camarda)
Bill Camarda is a consultant, writer, and web/multimedia content developer. His 15 books include Special Edition Using Word 2000 and Upgrading & Fixing Networks For Dummies®, Second Edition.