Techniquecore
Parallax mapping
Also called offset mapping.
Shift the texture coordinates along the view direction by the height read from a height map, to fake the parallax of surface relief.
Parallax mapping moves the texture coordinate of each pixel by an offset that depends on the view direction and on the depth stored in a height map. Points of the relief that lie deep then shift away from the viewer, as they would on a real rough surface, and the texture seems to have depth when the camera moves. Bump mapping and normal mapping change only the normal, so the texture stays fixed on the polygon. Parallax mapping applies one offset, computed from the depth at the starting point. That is cheap, but it is right only where the relief is smooth. Parallax occlusion mapping marches the view ray through the height field to find the true intersection, and displacement mapping moves the geometry itself.
In plain words
Look at a brick wall from the side. The mortar between the bricks lies deeper, so you see it a little behind and to the side of where it would be on a flat picture of the wall.
Parallax mapping fakes this. For each pixel, read how deep the surface is at that spot. Then slide the texture lookup a little along the direction you look in, by an amount that grows with the depth. Deep spots slide more and high spots slide less, so the picture shifts as the camera moves, like a real surface with depth.
It uses one read of the depth per pixel, so it is fast. It is only a guess, and it fails on steep or tall relief.
When it applies
- The relief is shallow and smooth compared with the size of the texture: bricks with soft edges, cobblestones, bark, worn stone.
- The surface is seen from angles near the normal, not grazing.
- There is a normal map for the lighting, and a height or depth map in the same texture space. Often the depth is in the alpha channel of the normal map.
- The budget allows one more texture read per pixel, but not a loop.
- It does not apply when the relief is steep or tall, when it must hide itself, or at grazing angles. Use parallax occlusion mapping then.
The template
The work happens in tangent space, as in normal mapping. The inputs are the texture coordinate of the pixel, the unit vector from the surface toward the viewer in the tangent frame, with , a depth map with values in (0 at the top, at the polygon), and a scale , the depth of the relief in texture units.
- Transform the view vector into the tangent frame with the matrix of normal mapping, .
- Read the depth at the start, .
- Compute the offset. Kaneko and others use , the point where a ray at depth would be.
- Or, with Welsh's offset limiting, use , which drops the division by .
- Read every texture of the material, including the normal map, at , and shade the pixel as usual.
Step 3 is exact when the depth is the same, , at every point between and , because the view ray then reaches depth exactly at . This is a proved property. Where the depth changes along the ray, the error grows with the slope of the relief and with . Step 4 keeps the offset at most , because . This is also proved, and it hides the worst errors at grazing angles, at the cost of less parallax there. The scale , and an optional bias added to , are tuning.
Classic examples
A trace. Take , and a view with and , so . Let the depth along the ray be at depth of the ray, the example of parallax occlusion mapping. The true intersection is at , so the true point has .
| method | depth used | |
|---|---|---|
| step 3, one offset | ||
| step 4, offset limiting | ||
| iterative, 8 steps | ||
| march of POM |
The single offset gets about two thirds of the way to the true point. Offset limiting gets less, which is its purpose at grazing angles.
Brick and stone walls. The classic use is a wall with a normal map and a depth map in its alpha channel. The mortar lines shift as the camera moves, which a normal map alone cannot do.
Floors in games. Cobblestone and tile floors use parallax mapping for distant surfaces, and switch to parallax occlusion mapping near the camera, where the errors would show.
Decals. Footprints, bullet holes and cracks get depth from a small depth map at the cost of one read.
Variations
- Offset limiting. Step 4, from Welsh (2004). The parallax is weaker at grazing angles, but the texture no longer swims away.
- Iterative parallax mapping. Repeat steps 2 and 3 with the depth at the last offset: with . This is a fixed-point iteration for the intersection depth . It converges when the map has a slope of absolute value below 1 near , by the contraction argument. In the trace the slope is , and the iteration goes , , , and so on to .
- Slope-based offset. Some versions also use the normal from the normal map to tilt the offset, which follows the local slope of the relief.
- Parallax occlusion mapping. Replace the single read by a march along the ray. See parallax occlusion mapping.
Pitfalls
- Swimming at grazing angles. As the offset of step 3 grows without a bound, and the texture slides across the surface. Use offset limiting, clamp , or fade the effect out.
- Steep edges. At the edge of a brick the depth jumps, so the offset jumps too, and the texture tears or doubles along the edge.
- No occlusion. A high point never hides a deep point behind it. Tall relief looks warped instead of solid.
- Depth and height mixed up. If the map stores height (1 at the top), use as the depth. The wrong sign moves the deep parts toward the viewer.
- Wrong tangent frame. The view vector must be in the same frame as the texture axes, as for normal maps. A wrong sign of the bitangent moves the relief the wrong way.
- Mip level of the shifted read. The shift happens in the pixel shader, so the derivatives of include the derivatives of the offset. Use the derivatives of for the reads at to avoid seams.
Exercises
- Show that step 3 gives the exact intersection when is constant along the ray.
- For a depth map that is a plane, along the ray with , find the true intersection and the error of step 3 as a function of .
- Show that the offset of step 4 is at most , and compare it with the offset of step 3 for .
- Run the iterative version on and count the steps until the error is below . Compare with the bound from the contraction factor .
- Explain why parallax mapping needs the normal map to be read at and not at .
References
- Kaneko and others, Detailed shape representation with parallax mapping, ICAT 2001, the whole paper (the shift of the texture coordinate by the height and the view direction)
- Terry Welsh, Parallax mapping with offset limiting, Infiscape, 2004, the offset without the division by the normal component of the view vector (general locator)
- 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.8, Parallax Mapping, from page 214
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.
| Ladder | Level | What the next level needs |
|---|---|---|
| Human proof | H0 no proof |
|
| Lean | L0 no Lean part |
|
| Visual | V0 none |
|
| Writing | W2 basic |
|
Tag NCNT13 Edit this page History Report an error Markdown