The Texture Matrix Stack (Texture Mapping) (OpenGL Programming)

Advanced

Just as your model coordinates are transformed by a matrix before being rendered, texture coordinates are multiplied by a 4 χ 4 matrix before any texture mapping occurs. By default, the texture matrix is the identity, so the texture coordinates you explicitly assign or those that are automatically generated remain unchanged. By modifying the texture matrix while redrawing an object, however, you can make the texture slide over the surface, rotate around it, stretch and shrink, or any combination of the three. In fact, since the texture matrix is a completely general 4×4 matrix, effects such as perspective can be achieved.

The texture matrix is actually the top matrix on a stack, which must have a stack depth of at least two matrices. All the standard matrix-manipulation commands such as glPushMatrix(), glPopMatrix(), glMultMatrix(), and glRotate*() can be applied to the texture matrix. To modify the current texture matrix, you need to set the matrix mode to GL_TEXTURE, as follows:

tmp1cfe147_thumb

The «/-Coordinate


The mathematics of the fourth texture coordinate,tmp1cfe148_thumbare similar to the w-coordinate of the (x, y, z, w) object coordinates. When the four texture coordinates (5, t, r, q) are multiplied by the texture matrix, the resulting vectortmp1cfe149_thumbis    interpreted as homogeneous texture coordinates. In other words, the texture map is indexed bytmp1cfe150_thumb

You can make use oftmp1cfe151_thumbin cases where more than one projection or perspective transformation is needed. For example, suppose you want to model a spotlight that has some nonuniform pattern—brighter in the center, perhaps, or noncircular, because of flaps or lenses that modify the shape of the beam. You can emulate shining such a light onto a flat surface by making a texture map that corresponds to the shape and intensity of a light, and then projecting it onto the surface in question using projection transformations. Projecting the cone of light onto surfaces in the scene requires a perspective transformation (q^ 1), since the lights might shine on surfaces that aren’t perpendicular to them. A second perspective transformation occurs because the viewer sees the scene from a different (but perspective) point of view. (See Plate 28 for an example; and see "Fast Shadows and Lighting Effects Using Texture Mapping" by Mark Segal, Carl Korobkin, Rolf van Widenfelt, Jim Foran, and Paul Haeberli, SIGGRAPH 1992 Proceedings [Computer Graphics, 26:2, July 1992, pp. 249-252] for more details.)

Another example might arise if the texture map to be applied comes from a photograph that itself was taken in perspective. As with spotlights, the final view depends on the combination of two perspective transformations.

Nate Robins’ Texture Tutorial

In Nate Robins’ texture tutorial, you can use the popup menu to view the 4×4 texture matrix, make changes in matrix values, and then see their effects.

Next post:

Previous post: