Ready to execute
Hardware Heritage
Bump mapping simulates rough surfaces by calculating light reflection based on a "height map" rather than geometry. In 2D, this effect is often called "Emboss" or "Phong Shading".
The Trick
Calculate the slope (normal) of the surface at every pixel by comparing neighbors. Then calculate the dot product between this normal and the light vector.
Performance
This requires per-pixel processing. In the 90s, this was pre-calculated or done in Assembly. Today, it's trivial for a shader.
Use Cases
Used for metallic logos, stone textures, and creating pseudo-3D UI elements in games like StarCraft.
Bump Mapping
2D Phong lighting simulation.
The Math
dx = texture[x-1] - texture[x+1]; dy = texture[y-1] - texture[y+1]; nx = dx; ny = dy; nz = 1; // Normal Vector lx = lightX - x; ly = lightY - y; lz = 100; // Light Vector // Dot Product intensity = (nx*lx + ny*ly + nz*lz) / dist;