Game Development Reference
In-Depth Information
In general, normals must be transformed with the inverse transpose of the
matrix used to transform positions. This can safely be ignored if the trans-
form matrix is without scale. If the matrix contains uniform scale, then all
that is required is to renormalize the normals after transformation. If the
matrix contains nonuniform scale, then we must use the inverse transpose
transform and renormalize after transforming.
10.5
Texture Mapping
There is much more to the appearance of an object than its shape. Different
objects are different colors and have different patterns on their surface.
One simple yet powerful way to capture these qualities is through texture
mapping. A texture map is a bitmap image that is “pasted” to the surface
of an object. Rather than controlling the color of an object per triangle or
per vertex, with texture mapping we can control the color at a much finer
level—per texel. (A texel is a single pixel in a texture map. This is a handy
word to know, since in graphics contexts, there are lots of different bitmaps
being accessed, and it's nice to have a short way to differentiate between a
pixel in the frame buffer and a pixel in a texture.)
So a texture map is just a regular bitmap that is applied onto the surface
of a model. Exactly how does this work? Actually, there are many different
ways to apply a texture map onto a mesh. Planar mapping projects the
texture orthographically onto the mesh. Spherical, cylindrical, and cubic
mapping are various methods of “wrapping” the texture around the ob-
ject. The details of each of these techniques are not important to us at the
moment, since modeling packages such as 3DS Max deal with these user in-
terface issues. The key idea is that, at each point on the surface of the mesh,
we can obtain texture-mapping coordinates, which define the 2D location in
the texture map that corresponds to this 3D location. Traditionally, these
coordinates are assigned the variables (u,v), where u is the horizontal coor-
dinate and v is the vertical coordinate; thus, texture-mapping coordinates
are often called UV coordinates or simply UV s.
Although bitmaps come in different sizes, UV coordinates are normal-
ized such that the mapping space ranges from 0 to 1 over the entire width
(u) or height (v) of the image, rather than depending on the image dimen-
sions. The origin of this space is either in the upper left-hand corner of
the image, which is the DirectX-style convention, or in the lower left-hand
corner, the OpenGL conventions. We use the DirectX conventions in this
book. Figure 10.16 shows the texture map that we use in several examples
and the DirectX-style coordinate conventions.
 
Search WWH ::




Custom Search