Game Development Reference
In-Depth Information
indicates the usual orientation, and −1 indicates the mirrored state. It's
common to conveniently tuck away this flag in the w component of the one
basis vector we are keeping. Now when we need to compute the dropped
basis vector, we take the appropriate cross product (for example v = n × u ),
and then multiply by our flag to flip the basis vector if necessary. This flag
is calculated by the triple product n × u v , which is the same thing as the
determinant of the transform matrix in Equation (10.18).
10.9.2 Calculating Tangent Space Basis Vectors
Finally, let's talk about how to compute basis vectors. Our development
follows Lengyel [42]. We are given a triangle with vertex positions p 0 =
(x 0 ,y 0 ,z 0 ), p 1 = (x 1 ,y 1 ,z 1 ), and p 2 = (x 2 ,y 2 ,z 2 ), and at those vertices
we have the UV coordinates (u 0 ,v 0 ), (u 1 ,v 1 ), and (u 2 ,v 2 ). Under these
circumstances, it is always possible to find a planar mapping, meaning the
mapping gradient is constant over the entire triangle.
Looking ahead, the math will be simplified if we shift the origin to p 0
by introducing
q 1 = p 1
p 0 ,
s 1 = u 1
− u 0 ,
t 1 = v 1
− v 0 ,
q 2 = p 2 p 0 ,
s 2 = u 2 − u 0 ,
t 2 = v 2 − v 0 .
We seek basis vectors that lie in the plane of the triangle, and thus we
can express the triangle edge vectors q 1 and q 2 as a linear combination of
the basis vectors, where the known u and v displacements on those edges
are the coordinates:
u s 1 + v t 1 = q 1
u s 2 + v t 2 = q 2 .
Normalizing u and v produces the unit vectors we seek. We can write these
equations more compactly in matrix notation as
s 1 t 1
s 2 t 2
u
q 1
=
,
v
q 2
whence an elegant solution presents itself. By multiplying both sides by
the inverse of the s,t matrix on the left, we have
−1
u
v
s 1 t 1
s 2 t 2
q 1
q 2
=
1
s 1 t 2 − s 2 t 1
t 2 −t 1
−s 2 s 1
q 1
q 2
=
.
Search WWH ::




Custom Search