Normal Mapping
Idea #
Store surface normal vectors in a RGB texture. Normals can be stored in two coodinate spaces.
- Object space:
- Normal can be applied as it is read from the texture.
- Not reusable between objects: They were baked for one specific geometry, so it only works for one mesh, and also no character animation is possible.
- Tangent space:
- Reusable maps
Using tangent space normals #
To convert the tangent-space normals to object-space normals we need the Tangent Fram Matrix. The TSM is then just a transformation matrix from tangent space to object space. It looks like this:
With:
Tangent vector
Binormal vector
Normal vector
,
and
are unit length and orthogonal onto each other
-
Tangent vector points in the
direction
-
Binormal points in the
direction
Getting the Tangent and Binormal #
Similar to the vertex normal, the tangent and bitangent are stored as vertex attributes and then get interpolated for the fragment shader. Like the vertex normal, the the tangent and bitangent also need to be renormalized to have unit length, since the interpolation messes with the length.
How normal maps are created #
- Have a high resolution mesh
- Create a lower resolution mesh from it
- Calculate the “delta” and strore as a normal map