In this post, we are going to explain a technique called displacement mapping (or height mapping).

A normal map is a texture, but instead of storing RGB data at each texel, we store a compressed x-coordinate, y-coordinate and z-coordinate in the red component, green component, and blue component, respectively. These coordinates define a normal vector, thus a normal map stores a normal vector at each pixel.

The strategy of normal mapping is to texture our polygons with normal maps. We then have per-pixel normals which capture the fine details of a surface like bumps, scratches, and crevices. We then use these per-pixel normals from the normal map in our lighting calculations, instead of the interpolated vertex normal.

Normal mapping just improves the lighting detail, but it does not improve the detail of the actual geometry. So in a sense, normal mapping is just a lighting trick.

The idea of displacement mapping is to utilize an additional map, called a heightmap, which describes the bumps and crevices of the surface. In other words, whereas a normal map has three color channels to yield a normal vector (x, y, z) for each pixel, the heightmap has a single color channel to yield a height value h at each pixel. Visually, a heightmap is just a grayscale image (grays because there is only one color channel), where each pixel is interpreted as a height value, it is basically a discrete representation of a 2D scalar field h = f(x, z). When we tessellate the mesh, we sample the heightmap in the domain shader to offset the vertices in the normal vector direction to add geometric detail to the mesh.

While tessellating geometry adds triangles, it does not add detail on its own. That is, if you subdivide a triangle several times, you just get more triangles that lie on the original triangle plane. To add detail, then you need to offset the tessellated vertices in some way. A heightmap is one input source that can be used to displace the tessellated vertices.

To generate heightmaps you could use NVIDIA Photoshop’s plugin or CrazyBump for example