Graphics Reference
In-Depth Information
The following diagram shows the coordinate systems for texture and tangent space:
Texture space in Direct3D (left) and tangent space (right). The completed project for this recipe maps
the N key to toggle rendering of the normal, tangent, and bitangent vectors.
The tangents for the compiled mesh object (CMO) models are calculated during compilation.
From the normal vector and tangent vector, we are able to determine the bitangent vector
(also known as binormal), and therefore our Tangent Bitangent Normal (TBN) matrix for
transforming from the normal map tangent space into world/object space or vice versa.
The meshes also include the handedness of the bitangent vector within the tangent vector,
allowing us to correctly calculate the direction of the bitangent vector as can be seen in point
B in the following calculations:
A) Orthogonalization of tangent vector T to normal vector N, B) Calculating the bitangent vector, C)
Resulting TBN matrix
The Microsoft .cmo file format stores a fourth component in the tangent vector to indicate the
handedness of the tangent. Therefore, we have used float4 instead of float3 . This would
not be used within a streamlined asset workflow. Instead, all shaders and assets would be
built with the same handedness in mind.
By using a normal map that is stored in tangent space, we sample the red, green, and blue
channels (x, y, and z respectively); and then transform the sample into world space using the
current pixel's normal and tangent vectors. We first remap the normal sample from the range
(0, 1) to (-1, 1) as the color data stored in the texture is packed between 0 and 1.
// Remap normalSample to the range -1,1
normalSample = (2.0 * normalSample) - 1.0;
 
Search WWH ::




Custom Search