Dr. Dobb's Journal August, 2004
OpenGL Shading Language
Randi Rost
Addison-Wesley, 2004
608 pp., $59.99
ISBN 0321197895
OpenGL Shading Language, by Randi Rost, describes the OpenGL Shading Languagethe first shading language designed as a cross-platform open standard by a group of graphics hardware and software vendors. Rost is a veteran of the computer graphics industry. He started programming graphics on an Apple II in the late 1970s and was working on programmable graphics hardware as early as 1983, when programmable graphics hardware meant little more than a framebuffer with a microcode interface.
Graphics hardware has advanced dramatically since then and continues to advance rapidly today. Most modern 3D hardware supports some type of programmable interface, and should support the Architectural Review Board (ARB)-approved OpenGL Shading Language in the near future.
The first chapter is a whirlwind overview of OpenGL. You might be tempted to skip this chapter. But before you do, consider that Rost is one of only a few who have contributed to every major revision of OpenGL. If you're a beginner or intermediate OpenGL programmer, you'll certainly learn something in this brief review.
Chapters 2 through 7 introduce you to the OpenGL Shading Language, covering topics such as language semantics and OpenGL entry points for specifying shaders.
Chapter 8 discusses shader development and performance issues. As you might expect from a book on a shading language, much of the performance discussion concerns shaving cycles from vertex- and pixel-shaders. The information is practical and not obvious even to intermediate programmers; for example, using min() or max() instead of clamp() when you know the variable will only exceed one end of a range. However, I found little discussion on how developers might determine which stage of the rendering pipeline is the performance bottleneck. Since this subject is considered black magic by many young and enthusiastic graphics developers, Rost could have added value to his book with a short section on this subject.
Chapter 9 provides shader listings for implementing core OpenGL functionality. The OpenGL Specification is the ultimate definition of OpenGL internal functionality, but the spec is mostly text and formulas, with only a few code listings. These well-written, concise, and efficient examples of shader code are both illuminating and instructive.
Chapters 10 through 16 provide computer graphics developers with real-time working OpenGL Shading Language source code for implementing several major computer-graphics algorithms and techniques. Topic areas include lighting, Phong shading, texture mapping, bump mapping, multitexturing, procedural texture mapping, lattice shaders, noise, turbulence, shadows, animation, particle systems, antialiasing, hatching and other nonphotorealistic techniques, vertex and image blending, image convolution, and more.
These examples demonstrate the range of OpenGL Shading Language applications, and give you a basis for writing new shaders. Rost's explanations of the algorithms are easy to read and comprehend, and demonstrate the depth and breadth of knowledge he has accumulated during his 25-year career in graphics.
Conspicuously missing is any mention of global-illumination algorithms such as ray tracing and radiosity. Such scene-based algorithms present obvious challenges to vertex- and pixel-based shading languages. Rost confessed to having a rough ray-tracing demo that was not ready for publication when this book went to press. He expressed optimism about the OpenGL Shading Language's ability to accelerate programs of this type: "In future revisions of hardware, we'll be able to implement more interesting algorithms [than currently appear in this book]."
While reading OpenGL Shading Language, I often found myself noting similarities and differences between the OpenGL Shading Language and interfaces to other programmable graphics hardware I've used. The book's final chapter covers this topic by comparing and contrasting the OpenGL Shading Language to current commercial shading languages such as RenderMan, ISL, HLSL, and Cg.
Two appendices serve as useful reference material. Appendix A covers OpenGL Shading Language grammar, and Appendix B documents OpenGL entry points for creating and managing shaders.
In general, the computer industry often provides two solutionsone proprietary and the other an open standard. As the only open standard shading language available that is designed for modern graphics hardware, the OpenGL Shading Language is certain to be around for several years to come. OpenGL Shading Language stands on its own as both a programming guide and reference manual for this significant new industry standard. However, this book goes further by providing real-time examples of classic computer graphics techniques. OpenGL Shading Language is a must-have algorithm book that should be on every computer graphics developer's bookshelf.
DDJ