Algorithm Search⌘K

Techniqueintro

Normal mapping

Also called normal maps.

Store surface normals in a texture, usually in tangent space, and use them in place of the interpolated normal when shading.

Normal mapping stores a unit normal per texel in an RGB texture and uses it as the shading normal of the pixel. Most normal maps store the normal in tangent space, relative to the frame of the surface, so the same map works on any part of any mesh and can tile. Bump mapping computes the tilted normal from the slopes of a height texture at run time. Normal mapping stores the result, which costs one texture read and no differences, and can store normals that come from no single height field, such as those baked from a detailed mesh. Like bump mapping, it changes only the lighting. Parallax mapping also shifts the texture by the view, and displacement mapping moves the geometry.

In plain words

A normal is the direction a surface faces, and light uses it to decide how bright a point is. A normal map is an image where each pixel holds such a direction, written as a color: red for left and right, green for up and down, blue for straight out of the surface.

At render time the shader reads the color, turns it back into a direction, and turns that direction from the frame of the surface into the frame of the world. Then it lights the pixel with it. A low-detail model with a good normal map looks almost as detailed as the high-detail model it came from, as long as you do not look at its outline.

When it applies

  • The surface detail is smaller than the triangles, and the outline does not need to show it.
  • There is a detailed version of the model, or a height or sculpt, from which to bake the normals.
  • The renderer has a tangent frame per vertex, or can build one, that matches the frame of the baking tool.
  • The memory for a second texture is acceptable. Compressed two-channel formats reduce it to 8 bits per texel or less.
  • It does not apply when the relief must hide parts of itself or change the outline. Use the parallax methods or displacement mapping then.

The template

The inputs are a normal map with texels c∈[0,1]3c \in [0, 1]^3, and at each vertex a normal NN, a tangent TT along the uu axis of the texture, and a sign σ=±1\sigma = \pm 1 for the handedness.

  1. Bake or author the map. For each texel, find the normal n=(nT,nB,nN)n = (n_T, n_B, n_N) of the detailed surface in the tangent frame of the low-detail surface, and store c=(n+1)/2c = (n + 1)/2, quantized to 8 or more bits per channel.
  2. Per vertex, make TT orthogonal to NN by one step of the Gram-Schmidt process, T←normalize(T−(N⋅T)N)T \leftarrow \mathrm{normalize}(T - (N \cdot T) N), and set the bitangent B=σ(N×T)B = \sigma (N \times T).
  3. Interpolate NN, TT and BB over the triangle, and normalize them again per pixel.
  4. Read the texel and decode it: n=2c−1n = 2c - 1, then normalize nn. For a two-channel map, rebuild nN=max⁡(0,1−nT2−nB2)n_N = \sqrt{\max(0, 1 - n_T^2 - n_B^2)}.
  5. Transform to the world: nw=nTT+nBB+nNNn_w = n_T T + n_B B + n_N N.
  6. Use nwn_w in the lighting in place of the interpolated normal.

Step 5 is exact only if TT, BB and NN are the same frame that step 1 used. Two tools that build tangents in different ways give visible seams and wrong shading, so the baker and the renderer must agree on the convention. This is the main practical rule of the method, and it is a convention, not a law.

Classic examples

A trace. A floor has N=(0,1,0)N = (0, 1, 0), T=(1,0,0)T = (1, 0, 0) and B=(0,0,−1)B = (0, 0, -1), and the light comes from the unit direction l=(0.6,0.8,0)l = (0.6, 0.8, 0). The flat floor gives N⋅l=0.8N \cdot l = 0.8. A texel stores c=(204,128,230)/255c = (204, 128, 230)/255, which decodes in step 4 to (0.600,0.004,0.804)(0.600, 0.004, 0.804), of length 1.0031.003, and normalizes to (0.598,0.004,0.801)(0.598, 0.004, 0.801). Step 5 gives nw=(0.598,0.801,−0.004)n_w = (0.598, 0.801, -0.004), tilted by about 37 degrees toward the light, and nw⋅l=1.000n_w \cdot l = 1.000. The pixel is lit as if it faced the light. The value 128 does not decode to exactly 0, because 2⋅128/255−1=1/2552 \cdot 128/255 - 1 = 1/255.

Detail from a high-poly model. Cohen, Olano and Manocha (1998) stored the normals of a detailed mesh in a texture over a simplified mesh, so that the simplified model kept its appearance. Game art is made the same way today: a sculpt with millions of triangles, a game mesh with thousands, and a baked normal map.

Tiled materials. Bricks, wood, cloth and stone use tiling tangent-space maps, often made from a height map as in bump mapping, and stored with block compression in two channels.

Detail maps. A second, small normal map that repeats many times adds fine detail, such as pores on skin, over a large base map.

Variations

  • Object-space normal maps. Store the normal in the frame of the object. This needs no tangents and has no tangent seams, but the map cannot tile or be shared between parts, and it breaks with skinning unless the normal is transformed with the bones.
  • Two-channel storage. Store only nTn_T and nBn_B, and rebuild nNn_N in step 4. Block formats for two channels keep more precision than three-channel color formats.
  • Mipmapping with Toksvig's factor. The average of different unit normals is shorter than 1. Toksvig (2005) uses its length ∣nˉ∣|\bar n| to lower the specular exponent pp to p′=p∣nˉ∣/(∣nˉ∣+p(1−∣nˉ∣))p' = p |\bar n| / (|\bar n| + p (1 - |\bar n|)), so that distant bumpy surfaces get a wider highlight in place of sparkles. This is a heuristic. For the two normals (±0.6,0,0.8)(\pm 0.6, 0, 0.8) the average is (0,0,0.8)(0, 0, 0.8), and p=32p = 32 becomes about 3.63.6.
  • Blending two maps. Adding the tangent components of two maps and normalizing again is a common heuristic. Methods that rotate the detail normal into the frame of the base normal keep more of the detail.
  • Parallax and relief. The normal map gives the lighting, and parallax mapping or parallax occlusion mapping shifts the texture coordinate where the normal is read.

Pitfalls

  • Tangent frame mismatch. If the renderer builds TT and BB in another way than the baker, the lighting is wrong near seams and on curved parts. Use one shared convention.
  • The green channel. Some tools store +B+B and others −B-B in green. A map in the other convention lights bumps from the wrong side.
  • Mirrored UVs. Mirrored parts of a mesh need σ=−1\sigma = -1. Without it, the mirrored side has inverted bumps.
  • Forgetting to decode or normalize. Using cc in place of 2c−12c - 1, or skipping the normalization after filtering and interpolation, gives a dim and wrong result.
  • Wrong color space. A normal map holds vectors, not colors. Loading it as sRGB applies a gamma curve and bends all normals. Mark it as linear data.
  • Specular aliasing. At a distance, a mipmapped normal map gives an average normal, but the true surface has many normals, so the highlight should widen. Without a correction such as Toksvig's, highlights sparkle or vanish.
  • Flat outlines and no self-shadowing. As with bump mapping, the silhouette stays smooth and the bumps cast no shadows.

Exercises

  1. Show that n=2c−1n = 2c - 1 inverts c=(n+1)/2c = (n + 1)/2, and find the largest angle error that 8-bit quantization of each channel can cause for a unit normal near (0,0,1)(0, 0, 1).
  2. Show that TT, BB and NN from step 2 form an orthonormal frame when NN is a unit vector and TT is not parallel to NN.
  3. Explain why the interpolated TT and NN of step 3 are in general not orthogonal, and what error this gives in step 5.
  4. Compute Toksvig's exponent for p=64p = 64 when the average of the normals in a texel has length 0.95.
  5. A height map hh is converted to a normal map by the formula of step 6 of bump mapping. What happens to the result when the texture is tiled twice as often, and how must the conversion change?

References

  1. Jonathan Cohen, Marc Olano and Dinesh Manocha, Appearance-preserving simplification, SIGGRAPH 1998, storing the normals of the detailed surface in a texture over the simplified mesh (general locator)
  2. Mark Peercy, John Airey and Brian Cabral, Efficient bump mapping hardware, SIGGRAPH 1997, the tangent frame per vertex and the perturbed normal in that frame (general locator)
  3. Michael Toksvig, Mipmapping normal maps, Journal of Graphics Tools, 2005, the length of the averaged normal as a measure of the spread of normals, and the reduced specular exponent (general locator)
  4. Tomas Akenine-Möller, Eric Haines, Naty Hoffman, Angelo Pesce, Michał Iwanicki and Sébastien Hillaire, Real-Time Rendering, fourth edition, CRC Press, 2018, Section 6.7, Bump Mapping, from page 208 (the tangent frame and normal maps)

Where this leads

About this page

The build computes these levels from the evidence in the repository. Each row says what the next level needs. Read what the levels mean.

LadderLevelWhat the next level needs
Human proofH0 no proof
  • add a proof in proofs/ (06.5)
LeanL0 no Lean part
  • name a Lean module in the lean field (07)
VisualV0 none
  • add viz/scene.ts or a figure (10)
WritingW2 basic
  • three classic examples