Chapter 9. Emulating OpenGL Fixed Functionality
The programmability of OpenGL opens many new possibilities for never-before-seen rendering effects. Programmable shaders can provide results that are superior to OpenGL fixed functionality, especially in the area of realism. Nevertheless, it can still be instructive to examine how some of OpenGL's fixed functionality rendering steps could be implemented with OpenGL shaders. While simplistic, these code snippets may be useful as stepping stones to bigger and better things.
This chapter describes OpenGL shader code that mimics the behavior of the OpenGL fixed functionality vertex and fragment processing. The shader code snippets are derived from the Full OpenGL Pipeline and Pixel Pipeline shaders developed by Dave Baldwin for inclusion in the white paper OpenGL 2.0 Shading Language. Further refinement of this shader code occurred for the first edition of this book. These code snippets were then verified and finalized with a tool called ShaderGen that takes a description of OpenGL's fixed functionality state and automatically generates the equivalent shaders. ShaderGen was implemented by Inderaj Bains and Joshua Doss and is available from the 3Dlabs Web site.
The goal of the shader code in this chapter is to faithfully represent OpenGL fixed functionality. The code examples in this chapter reference existing OpenGL state wherever possible through built-in variables. In your own shaders, feel free to provide these values as user-defined uniform variables rather than accessing existing OpenGL state. By doing this, you will be prepared to throw off the shackles of the OpenGL state machine and extend your shaders in exciting and different new ways. But don't get too enamored with the shaders presented in this chapter. In later chapters of this book, we explore a variety of shaders that provide better results than those discussed in this chapter.