Height map to normal map
Open a grayscale height map, set how tall white is, and download a tangent-space normal map in OpenGL or DirectX style. A 16-bit PNG is read at 16 bits, so smooth terrain and sculpt bakes don't come out stepped. Runs in your browser.
What the converter computes
For every pixel it measures how fast height changes to the right (dx) and toward the top of the image (dy), using the pixels around it. The normal is the direction perpendicular to that slope:
n = normalize(−dx · d, −dy · d, 1)
where d is the relief in pixels: strength × image width. The vector is stored as color with R = (x + 1) / 2, G = (y + 1) / 2, B = (z + 1) / 2, which is why a flat area is the familiar (128, 128, 255) lavender. DirectX output stores G as 1 − G.
| Filter | Weights across the slope | Character |
|---|---|---|
| Sobel | 1 · 2 · 1 | Common default, mild smoothing |
| Scharr | 3 · 10 · 3 | Most even response to diagonal slopes |
| Prewitt | 1 · 1 · 1 | Strongest averaging, softest result |
Each kernel is scaled so that a straight ramp gives its exact slope. Our test script runs ramps, a hemisphere and a sine ridge through all three: ramps come out within 0.0001° of the true normal, the hemisphere within 0.03°.
Setting strength from real sizes
Strength is the height of the full black-to-white range as a percentage of the texture's width. If you know the real sizes, you can set it instead of guessing:
- A texture covering a 2 m wide wall, where black-to-white is 1 cm of depth: 1 / 200 = 0.5 %.
- A 30 cm tile whose grout is 3 mm deep: 0.3 / 30 = 1 %.
- In Blender, displacing the same height map on a plane of width W with a Displacement node, Scale = strength × W (midlevel 0) gives geometry that matches this normal map.
Why 16-bit input matters
An 8-bit height map has 256 levels. On a gentle slope the height climbs one level every few pixels, so the measured slope flickers between zero and one step, and the normal map shows terraces. Browsers decode every PNG to 8 bits for display; this page reads PNG files with its own decoder so a 16-bit height map keeps all 65,536 levels.
Converting a color photo instead? Use the normal map generator, which estimates height from brightness and also makes AO and roughness.