Game Development Reference
In-Depth Information
squeezed, squashed, or twisted. Two instructive examples can be found in
Figure 10.19 on page 396. The left side shows an example of “squishing.”
In this case, the tangent vector u would be pointing to the right, parallel to
the horizontal polygon edges, while the binormal v would be locally parallel
to the vertical (curving) polygon edges at each vertex. To determine the
basis vectors at any given point in the interior of the face, we interpolate
the basis vectors from the vertices, just like we do with the surface normal.
Compare this with the texture mapping on the right side, where the tex-
ture mapping is planar. In this example, the binormal at every vertex (and
every interior point) points directly down.
Notice that in the texture mapping used in the left side of the figure, the
tangent and binormal vectors are not perpendicular. Despite this possibil-
ity, it's common to assume the basis vectors form an orthonormal basis (or
to adjust them so that they do), even if the texture is being manhandled.
We make this assumption in order to facilitate two optimizations. The first
optimization is that we can perform our lighting calculations in tangent
space rather than in model space. If we do the lighting in model space,
we must interpolate the three basis vectors across the face, and then in the
pixel shader we must transform our tangent-space normal into model space.
When we do the lighting in tangent space, however, we can instead trans-
form the vectors needed for lighting ( l and h ) into tangent space once in
the vertex shader, and then during rasterization the interpolation is done
in tangent space. In many circumstances, this is faster. If we have an
orthonormal basis, then the inverse of the transform matrix is simply its
transpose, and we can transform from model space to tangent space just
by using the dot product. (If this isn't making sense, see Section 3.3.3 and
Section 6.3.) Of course, we are free to rotate vectors into tangent space
by using the dot product even if our basis isn't orthonormal; in fact, after
interpolating basis vectors and renormalizing them, it's likely that it will
be slightly out of orthogonality. In this case, our transform is not com-
pletely correct, but usually this doesn't cause any problems. It's important
to remember that the whole idea of interpolating surface normals and basis
vectors is an approximation to begin with.
The second optimization we can make by assuming perpendicular basis
vectors is to completely avoid storing one of the two basis vectors (usually
we drop the binormal) and compute it on the fly. This can be faster when
the performance bottleneck is the shu ing around of memory rather than
per-vertex calculations. There's just one complication: mirrored bump
maps. It is very common on symmetrical objects for texture maps, in-
cluding the bump map, to be used twice; on one side the “regular” way,
and mirrored on the other side. Essentially, we need to know whether the
texture is applied in its regular orientation or mirrored. This is done by
storing a flag that indicates whether the texture is mirrored. A value of +1
Search WWH ::




Custom Search