skip to content

How does a tangent-space normal map fake surface detail, what is the TBN basis, and why do mismatched tangents cause lighting seams?

level: middleimportance: should knowfreq 56%

answer

  1. shading changes, silhouette does not
  2. a frame that follows the UVs
  3. why the map looks light blue
  4. handedness on mirrored islands
  5. baker and renderer must agree

basics

~20 s

A tangent-space normal map stores per-texel normals in the surface's local frame: tangent along u, bitangent along v, normal outward. The TBN basis rotates them to world space; baker and renderer tangents that differ break lighting at seams.

solid answer

~50 s

A normal map replaces the interpolated vertex normal per pixel, so a flat, low-polygon surface lights as if it had bricks and cracks, while its silhouette stays flat. In **tangent space** each texel is relative to a frame on the surface: `T` points where `u` increases, `B` where `v` increases, `N` outward, and an unperturbed normal (0, 0, 1) is stored as (0.5, 0.5, 1.0), hence the blue. The **TBN** matrix rotates the decoded normal into world space. Tangents come from solving each triangle's positions against its UV differences, averaging per vertex, orthogonalising against `N`, and storing a handedness sign for mirrored UVs. Because the map is relative, it tiles, mirrors, deforms with skinning and compresses to two channels. The baker encodes normals in its own tangent frame, so a renderer that builds a different frame, flips the green convention or loses the sign decodes them rotated: seams and inverted lighting.

code

pseudocode · 22 lines
pseudocode
// per triangle: positions p0, p1, p2 and texture coordinates t0, t1, t2
e1 = p1 - p0
e2 = p2 - p0
du1 = t1.u - t0.u;  dv1 = t1.v - t0.v
du2 = t2.u - t0.u;  dv2 = t2.v - t0.v
det = du1 * dv2 - du2 * dv1
if abs(det) < EPSILON:
    continue                       // degenerate UVs: this triangle adds nothing
r = 1 / det
T = (e1 * dv2 - e2 * dv1) * r      // direction of increasing u
B = (e2 * du1 - e1 * du2) * r      // direction of increasing v
add T to Tacc and B to Bacc of vertices 0, 1 and 2

// per vertex, after all triangles: unit normal N, accumulators Tacc, Bacc
t = Tacc - N * dot(N, Tacc)        // Gram-Schmidt against the normal
if length(t) < EPSILON:
    t = any unit vector perpendicular to N    // no UV gradient here
t = normalize(t)
sign = 1
if dot(cross(N, t), Bacc) < 0:
    sign = -1                      // mirrored UVs
store tangent = (t, sign)          // at runtime: B = sign * cross(N, t)

go deeper

for a junior

Know that a normal map changes per-pixel shading but not geometry, that tangent-space maps look blue because unperturbed normals point along z, and what T, B and N stand for.

for a middle

Explain how tangents are derived from positions and UVs, why a handedness sign is stored, how the TBN basis rotates the normal, and why tangent space suits tiling, skinning and two-channel compression.

for a senior

Diagnose seams, inverted lighting on one axis and mirrored-half errors to their cause: mismatched tangent algorithms, green-channel conventions, lost handedness or sRGB decoding, and fix the contract between baker and runtime.

for a principal

Set the tangent-space convention as a studio-wide contract across baking tools and the runtime, and decide where parallax techniques are worth their per-pixel cost.

## What a normal map replaces Lighting depends on the surface normal at each pixel. Without a normal map, the normal is interpolated across each triangle from the vertex normals, so a flat wall lights like a flat wall. A **normal map** replaces that interpolated normal per pixel with one baked from a detailed sculpt or authored by hand, so the low-polygon wall shades as if it had cracks and bricks. The geometry does not change: silhouettes, the shadows the mesh casts and the depth buffer all still see the flat surface. Each texel stores a unit vector with components in -1..1, packed into 0..1 as `n * 0.5 + 0.5`. In **tangent space**, an unperturbed normal is (0, 0, 1), stored as (0.5, 0.5, 1.0), which is why these maps look mostly light blue. ## The TBN basis Tangent space is a frame attached to the surface at every point: - **T**, the tangent, points in the direction the texture's `u` coordinate increases; - **B**, the bitangent, points where `v` increases; - **N** is the surface normal. Used as the columns of a 3x3 matrix, the three vectors form the **TBN basis**. Multiplying a tangent-space normal by it gives the normal in world or object space; when the basis is orthonormal its transpose goes the other way, which lets a renderer move light and view vectors into tangent space per vertex instead. The tangents come from the mesh's positions and UVs: 1. For each triangle, the two edge vectors equal combinations of `T` and `B` weighted by the UV differences along those edges; solving that 2x2 system gives a `T` and `B` per triangle. 2. Each vertex accumulates the `T` and `B` of the triangles that share it, often weighted by angle or area. 3. `T` is made perpendicular to the vertex normal (Gram-Schmidt) and normalised. 4. Instead of storing `B`, a **handedness sign** is stored with `T`: +1 or -1, saying whether `cross(N, T)` points along `B` or against it. Mirrored UV islands flip that sign, and without it the mirrored half reads its normal map with one axis reversed. At each pixel the program unpacks the texel, rebuilds `B` from `N`, `T` and the sign, and rotates the normal into the space where lighting is computed. ## Why tangent space | Property | Tangent-space map | Object-space map | |---|---|---| | Reuse on tiled or mirrored UVs | yes | no; each texel belongs to one place on one mesh | | Survives skinning and deformation | yes; the basis deforms with the mesh | needs the deformation applied to the normal | | Compressible to two channels | yes; z is rebuilt as positive | no; all three components vary | | Needs per-vertex tangents | yes | no | | Sensitive to tangent mismatches | yes | no | Tangent-space normals point outward, so z is non-negative and a two-channel format such as BC5 can store x and y at high quality while the program rebuilds `z = sqrt(max(0, 1 - x*x - y*y))`. ## Where seams and inverted lighting come from A baker encodes each high-polygon normal relative to the low-polygon mesh's tangent frame. If the renderer decodes with a different frame, the normal comes out rotated. Typical causes: - **A different tangent algorithm.** Weighting, splitting at UV seams or orthogonalisation done differently from the baker gives frames that disagree most at UV seams and on curved low-polygon faces, leaving visible lines and gradient shading. - **A green-channel convention mismatch.** Tools disagree on whether +Y in the map points toward increasing or decreasing `v`; the wrong one makes bumps look lit from the opposite side along one axis only. - **Lost handedness.** Mirrored halves show inverted lighting on one axis. - **sRGB decoding** on the normal map tilts every normal, everywhere, rather than at seams. - **Filtering without renormalising.** Bilinear blends and mip averages shorten normals, which dims lighting unless the result is renormalised. The fix for the first three is a contract: one tangent-space convention shared by the baker and the runtime, and tangents exported with the mesh rather than recomputed differently on import. ## Parallax mapping, the next step A normal map changes shading but not where a texel appears: the bricks look lit but stay painted on. **Parallax mapping** also shifts the texture lookup using a height map and the view direction in tangent space. With `V` the unit vector from the surface toward the eye, and a height map whose larger values are raised toward the viewer, the simple form is ``` uv' = uv + (V.xy / V.z) * height(uv) * scale ``` Dividing by `V.z` makes the shift grow at grazing angles, which is also where the approximation breaks down; **offset limiting** drops the division. **Parallax occlusion mapping** instead ray-marches the height field in several steps to find where the view ray enters it, adding self-occlusion at a higher cost. Neither changes the silhouette.

  • What does parallax mapping add on top of normal mapping, and what can it still not do?
    It shifts the texture lookup by the height and the tangent-space view direction, so raised details appear to move against their background as the view changes. Parallax occlusion mapping ray-marches the height field for self-occlusion. Neither changes the silhouette or the depth buffer, and both break down at grazing angles and cost extra lookups per pixel.
  • Why store only x and y of a tangent-space normal and rebuild z?
    Tangent-space normals point outward, so z is non-negative and follows from x and y as sqrt(max(0, 1 - x*x - y*y)). A two-channel format such as BC5 then stores x and y as independent channels at high quality, whereas a colour format with correlated endpoints would distort the vector.
  • Why must a normal read with bilinear filtering or from a coarse mip level be renormalised?
    Averaging unit vectors that point in different directions gives a shorter vector, so lighting computed with it is dimmer and highlights are wrong. Renormalising restores unit length. The lost length is also information: it says how varied the normals were, which some renderers use to widen highlights on distant bumpy surfaces.

  • Normal mapping changes the mesh's silhouette and the shadows it casts.
  • The bitangent never needs a stored sign because cross(N, T) always gives it.
  • A normal map baked in one tool works with any renderer's tangents.
  • Normal maps should be stored sRGB like every other texture.
  • Object-space normal maps are always better because they need no tangents.