Bump map explorer
Bump mapping perturbs the surface normal with a texture, so a flat quad is lit as if it were rough. The texture holds a tangent-space normal in RGB and the height in alpha; the vertex shader puts the light and view vectors into the same tangent space and the fragment shader does the lighting there. Pick an example, then change the texture, how it is filtered, the shading technique, the camera and the light.
Notes on what is approximated
- Tangent frame. Run against your own code,
bumpMap.jsstores normals whose y component is mirrored relative to its tangent frame, andbumpMap2.jsstores them rotated by 90°. The convention menu reproduces both errors so the effect on the lighting can be seen, and the derivative method (which uses the geometry) is immune to them. - Bump height and repeat. Bump height is relative to one copy of the texture, so repeating the texture shrinks the relief with it. Parallax and the derivative normals use the same units, which is why the three agree.
- Parallax treats the quad as the top of a volume. It has no self-shadowing, and the quad's silhouette stays straight; it also steps the ray at a fixed number of layers, so thin features can be missed at grazing angles with few steps.
- Derivative normals come from screen-space derivatives over 2 × 2 pixel blocks of a bilinearly filtered height, so they are blocky where the texture is magnified. Mikkelsen's formulation is used.
- Toksvig. The formula is aggressive for high shininess: averaging only 2 × 2 texels of a fine dented map can cut a shininess of 220 to about 14. The shader divides by the level-0 normal length to remove the rounding in the 8-bit normals, which would otherwise be amplified.
- Water uses a procedural sky, a tiled floor for refraction, and Beer–Lambert absorption: a convincing approximation, not a simulation. Two layers of the same map are a common trick; scrolling in different directions hides the repetition.
- Mipmapped normal maps.
generateMipmapaverages the encoded normals. The shader renormalizes, but the average of many different normals is shorter than unit length and points in a compromise direction, so fine relief fades with distance. The view "Length of the filtered normal" shows it directly. - 8-bit normals. As in the samples the normal map is RGBA8, so large bump heights on smooth fields show some banding.