JavaScript EditorFree JavaScript Editor     Ajax Editor 



Main Page
Previous Page
Next Page

Chapter 10. Stored Texture Shaders

Texture mapping is a powerful mechanism built into OpenGL. At the time OpenGL was initially defined (1992), texture-mapping hardware was just starting to be available on commercial products. Nowadays, texture mapping is available on graphics hardware at all price points, even entry-level consumer graphics boards.

When OpenGL 1.0 was defined, texture mapping had a fairly narrow definition. It was simply a way to apply an image to the surface of an object. Since then, hardware has become capable of doing much more in this area, and researchers have come up with a lot of interesting things to do with textures other than just plastering images on surfaces. The scope of texture mapping has also been extended in OpenGL. Texture objects were one of the key additions in OpenGL 1.1. Three-dimensional textures were made part of the standard in OpenGL 1.2. The capability of hardware to access two or more textures simultaneously was exposed in OpenGL 1.3, along with cube map textures and a framework for supporting compressed textures formats. OpenGL 1.4 added support for depth textures and shadows, automatic mipmap generation, and another texture wrap mode (mirrored repeat). If you need a quick review of how texturing works in OpenGL, refer to Section 1.10.

The programmability introduced with the OpenGL Shading Language allows for a much broader definition of texture mapping. With programmable shaders, an application can read values from any number of textures and use them in any way that makes sense. This includes supporting sophisticated algorithms that use the results of one texture access to define the parameters of another texture access. Textures can also store intermediate rendering results; they can serve as lookup tables for complex functions; they can store normals, normal perturbation factors, gloss values, visibility information, and polynomial coefficients; and do many other things. These things could not be done nearly as easily, if at all, in unextended OpenGL, and this flexibility means that texture maps are coming closer to being general-purpose memory that can be used for arbitrary purposes. (Filtering and wrapping behavior still differentiate texture-map access from normal memory access operations.)

This chapter describes several shaders that, at their core, rely on looking up values in texture memory and using those values to achieve interesting effects. We start by talking a little bit about how textures are accessed from within a shader, and then we look at several examples of shaders that access texture memory for various purposes other than just the straightforward application of an image to the surface of a 3D object.


Previous Page
Next Page




JavaScript EditorAjax Editor     JavaScript Editor