Game Development Reference
In-Depth Information
This is a linear system with six unknowns (three for each T and B ) and six equa-
tions (the x , y , and z components of the two equations). We can write this in ma-
trix form as follows.
() () ()
(
QQQ
QQQ
t
TTT
s
 

1
x
1
y
1
z
1
1
x
y
z
=
(7.35)
 

)
(
)
(
)
s
t
BBB
 

2
x
2
y
2
z
2
2
x
y
z
Multiplying both sides by the inverse of the
s t matrix, we have
() () ()
(
TTT
t
t
QQQ
QQQ .
1

x
y
z
2
1
1
x
1
y
1
z
=
(7.36)

)
(
)
(
)
BBB
st
s t
s s

x
y
z
12
21
2
1
2
x
2
y
2
z
This gives us the (unnormalized) T and B tangent vectors for the triangle whose
vertices are P , P , and P . To find the tangent vectors for a single vertex, we av-
erage the tangents for all triangles sharing that vertex in a manner similar to the
way in which vertex normals are commonly calculated. In the case that neighbor-
ing triangles have discontinuous texture mapping, vertices along the border are
generally already duplicated since they have different mapping coordinates any-
way. We do not average tangents from such triangles because the result would
not accurately represent the orientation of the bump map for either triangle.
Once we have the normal vector N and the tangent vectors T and B for a ver-
tex, we can transform from tangent space into object space using the matrix
TBN
TBN
TBN
x
x
x
.
(7.37)
y
y
y
z
z
z
To transform in the opposite direction (from object space to tangent space—what
we want to do to the light direction), we can simply use the inverse of this matrix.
It is not necessarily true that the tangent vectors are perpendicular to each other
or to the normal vector, so the inverse of this matrix is not generally equal to its
transpose. It is safe to assume, however, that the three vectors will at least be
close to orthogonal, so using the Gram-Schmidt algorithm (see Algorithm 2.16)
to orthogonalize them should not cause any unacceptable distortions. Using this
process, new (still unnormalized) tangent vectors
T and
B are given by
(
)
TT NTN
B
′ =− ⋅
(
)
(
)
=− ⋅
BNBNTBT .
− ⋅
(7.38)
Search Nedrilad ::




Custom Search