Surface gradient based bump mapping framework
Mikkelsen's framework for combining bump, normal and procedural height maps in any projection by summing surface gradients rather than blending normals. Removes tangent-space dependence and makes triplanar, decals and layering consistent.
In the family Materials, BRDFs & texturing, bump and normal mapping
Where it runs
Built inOfficial add-onPluginNone foundNot researched
| Engine | Support | How |
|---|---|---|
| three.js r187 | Built in | material.bumpMap = texture docs Derivative-based bump map after Mikkelsen's surface-gradient paper. |
| Babylon.js 9.38.0 | Built in | bumpFragmentMainFunctions.fx perturbNormal screen-space surface-gradient perturbation docs |
| Godot 4.7 | None found | BaseMaterial3D uses tangent-space normal maps rather than Mikkelsen's surface-gradient bump mapping framework. |
| Unity | Built in | HDRP Lit normal and detail mapping (always on) docs HDRP shaders blend normals via the surface-gradient framework. |
| Unreal 5.7 | None found | |
| Blender 5.2 | None found | |
| WebGPU W3C | None found | |
| Metal | None found |
How it works
A surface gradient is the 2D-slope vector of a height perturbation expressed in the tangent plane of the unperturbed geometric normal. Because gradients simply add, any number of perturbations (UV normal maps, triplanar projections, procedural bumps, decals) can be accumulated as sum of gradients and resolved once into a final perturbed normal: n' = normalize(n - grad). Mikkelsen gives resolve routines for UV-mapped data (using the screen-space derivatives of position and texture coordinates, i.e. the MikkTSpace-compatible basis), for world-space and object-space normal data, and for height maps with dFdx/dFdy. It avoids the artifacts of lerp-ing normals and handles flipped or mirrored UVs deterministically.
When to choose it
Reach for it when
- blending normal maps gives wrong flattened detail
- layering decals, triplanar and detail normals looks off
- mesh has no reliable tangents
- need consistent combining of bump sources
Choose it when layering several normal sources (terrain triplanar plus detail, decals, wetness ripples) or when a mesh lacks reliable tangents. Prefer plain Normal mapping with MikkTSpace for a single UV-mapped normal map with baked tangents. Pair with Triplanar mapping and Hex-tiling for blended world-space normals.
Field marks
- Screen-space derivative bases break at helper-pixel quad boundaries and on very small triangles
- Height-map bump from derivatives yields faceted look if the height is low resolution or under-filtered
- Gradient scale must be unit-consistent across sources or contributions mix wrongly
- Differences from baked tangent-space shading mean authored normal maps may look slightly different
Presets
Surface Gradient Bump Mapping — UV tangent seam & pole pinch (left) vs tangent-free surface gradient (right)
{
"P_BUMP_FREQ": 12,
"P_GRAD_STR": 0.85,
"P_ROT_SPEED": 0.55,
"P_SPLIT": 0.48
}Show GLSL (125 lines)
const float P_BUMP_FREQ = 12.0; // P Bump Scale [5.0, 22.0, 0.5]
const float P_GRAD_STR = 0.85; // P Gradient Strength [0.1, 1.6, 0.05]
const float P_ROT_SPEED = 0.55; // P Orbit Speed [0.0, 2.2, 0.05]
const float P_SPLIT = 0.48; // P UV Seam / SurfGrad [0.0, 1.0, 0.02]
mat2 rot2(float a) { float c = cos(a), s = sin(a); return mat2(c, -s, s, c); }
// 3D volumetric procedural bump scalar field h(p) (gyroid + cellular dimples)
float bumpField3D(vec3 p, float freq) {
vec3 q = p * freq;
float g = sin(q.x) * cos(q.y) + sin(q.y) * cos(q.z) + sin(q.z) * cos(q.x);
float fine = 0.45 * sin(q.x * 2.1 + q.z * 1.9) * cos(q.y * 2.3);
return g * 0.5 + fine;
}
// Mikkelsen (2020) tangent-free Surface Gradient: project 3D gradient onto surface tangent plane!
// surfGrad = grad3D - n * dot(n, grad3D), then n_perturbed = normalize(n - str * surfGrad)
vec3 resolveSurfaceGradient(vec3 p, vec3 n, float freq, float str) {
float e = 0.004;
vec3 grad3D = vec3(
bumpField3D(p + vec3(e, 0.0, 0.0), freq) - bumpField3D(p - vec3(e, 0.0, 0.0), freq),
bumpField3D(p + vec3(0.0, e, 0.0), freq) - bumpField3D(p - vec3(0.0, e, 0.0), freq),
bumpField3D(p + vec3(0.0, 0.0, e), freq) - bumpField3D(p - vec3(0.0, 0.0, e), freq)
) / (2.0 * e);
// Also layer a second triplanar height bump using pure additive surface gradients!
vec3 surfGrad = grad3D - n * dot(n, grad3D);
return normalize(n - surfGrad * (str * 0.045));
}
// Sculpted organic knob / pinched sphere showing poles & seam clearly
float mapSculpt(vec3 p) {
float d1 = length(p) - 0.68;
float d2 = length(vec2(length(p.xz) - 0.52, p.y)) - 0.24;
float h = clamp(0.5 + 0.5 * (d2 - d1) / 0.18, 0.0, 1.0);
return (mix(d2, d1, h) - 0.18 * h * (1.0 - h)) * 0.85;
}
vec3 calcNormal(vec3 p) {
vec2 e = vec2(0.0025, 0.0);
return normalize(vec3(
mapSculpt(p + e.xyy) - mapSculpt(p - e.xyy),
mapSculpt(p + e.yxy) - mapSculpt(p - e.yxy),
mapSculpt(p + e.yyx) - mapSculpt(p - e.yyx)
));
}
vec3 aces(vec3 x) {
x = max(x, 0.0);
return (x * (2.51 * x + 0.03)) / (x * (2.43 * x + 0.59) + 0.14);
}
void mainImage(out vec4 fragColor, in vec2 fragCoord) {
vec2 uv = (fragCoord - 0.5 * iResolution.xy) / iResolution.y;
float screenX = fragCoord.x / max(iResolution.x, 1.0);
float split = clamp(P_SPLIT, 0.0, 1.0);
bool isSurfGrad = screenX >= split;
float freq = clamp(P_BUMP_FREQ, 4.0, 24.0);
float str = clamp(P_GRAD_STR, 0.05, 1.8);
float spin = iTime * max(P_ROT_SPEED, 0.0) * 0.48;
vec3 ro = vec3(0.0, 0.32, 2.28);
vec3 rd = normalize(vec3(uv - vec2(0.0, 0.06), -1.52));
ro.xz = rot2(spin) * ro.xz;
rd.xz = rot2(spin) * rd.xz;
vec3 col = mix(vec3(0.022, 0.028, 0.048), vec3(0.060, 0.076, 0.122), smoothstep(-0.55, 0.55, uv.y));
float t = 0.0;
bool hit = false;
for (int i = 0; i < 56; i++) {
float d = mapSculpt(ro + rd * t);
if (d < 0.0025) { hit = true; break; }
t += d;
if (t > 5.0) break;
}
if (hit) {
vec3 p = ro + rd * t;
vec3 nGeo = calcNormal(p);
vec3 n;
float seamAlert = 0.0;
if (isSurfGrad) {
// Right: Mikkelsen tangent-space-free Surface Gradient Bump Mapping (zero seams, zero pole pinching!)
n = resolveSurfaceGradient(p, nGeo, freq, str);
} else {
// Left: Naive spherical UV-mapped tangent-space bump (suffers atan seam flip & severe north-pole distortion!)
vec3 pn = normalize(p + vec3(1e-5));
float uS = atan(pn.z, pn.x) / 6.2831853 + 0.5;
float vS = asin(clamp(pn.y, -0.999, 0.999)) / 3.14159265 + 0.5;
vec2 suv = vec2(uS * 3.0, vS * 1.5) * freq;
float e = 0.03;
float h0 = sin(suv.x) * cos(suv.y) + 0.45 * sin(suv.x * 2.1) * cos(suv.y * 2.3);
float hx = sin(suv.x + e) * cos(suv.y) + 0.45 * sin((suv.x + e) * 2.1) * cos(suv.y * 2.3);
float hy = sin(suv.x) * cos(suv.y + e) + 0.45 * sin(suv.x * 2.1) * cos((suv.y + e) * 2.3);
vec3 tang = normalize(cross(vec3(0.0, 1.0, 0.0), nGeo) + vec3(1e-4, 0.0, 0.0));
vec3 bitang = cross(nGeo, tang);
// Tangent sign flips across UV seam & stretches near poles!
float seamSign = (pn.x > 0.0 && abs(pn.z) < 0.04) ? -1.0 : 1.0;
seamAlert = smoothstep(0.06, 0.01, abs(pn.z)) * step(0.0, pn.x) + smoothstep(0.82, 0.98, abs(pn.y));
n = normalize(nGeo - (tang * ((hx - h0) / e) * seamSign + bitang * ((hy - h0) / e)) * str * 0.25);
}
vec3 l1 = normalize(vec3(0.62, 0.78, 0.52));
vec3 l2 = normalize(vec3(-0.68, 0.15, -0.58));
float diff1 = max(dot(n, l1), 0.0);
float diff2 = max(dot(n, l2), 0.0);
float spec = pow(max(dot(n, normalize(l1 - rd)), 0.0), 42.0);
float fres = pow(1.0 - max(dot(n, -rd), 0.0), 3.0);
vec3 bronze = mix(vec3(0.24, 0.46, 0.62), vec3(0.86, 0.64, 0.34), 0.5 + 0.5 * n.y);
col = bronze * (0.24 + 0.85 * diff1 + 0.26 * diff2)
+ vec3(1.0, 0.96, 0.90) * spec * 0.62
+ vec3(0.26, 0.80, 0.96) * fres * 0.32;
if (!isSurfGrad) {
// Tint UV seam & pole pinch artifacts in warning crimson
col = mix(col, vec3(0.95, 0.24, 0.30), clamp(seamAlert * 0.42, 0.0, 0.65));
}
}
float sep = smoothstep(0.0035, 0.0008, abs(screenX - split));
col = mix(col, vec3(0.95, 0.97, 1.0), sep);
fragColor = vec4(pow(clamp(aces(col), 0.0, 1.0), vec3(1.0 / 2.2)), 1.0);
}Attribution: MIT — written for this index.
Measured GPU weight & timing
| Preset | GPU | Weight / p50 / p95 | Method |
|---|---|---|---|
| surface-gradient-bump-mapping-live | Tesla T4 1920x1080 | 10.2× baseline (moderate) · 0.334 ms / 0.345 ms | opengl-timer-query · 32 frames · GPU Weight Atlas · Colab T4 sweep |
| surface-gradient-bump-mapping-live | NVIDIA L4 1920x1080 | 7.77× baseline (moderate) · 0.124 ms / 0.124 ms · 2.7× faster on L4 | opengl-timer-query · Cross-architecture validation |
| surface-gradient-bump-mapping-live | NVIDIA A100-SXM4-40GB 1920x1080 | 6.32× baseline (moderate) · 0.182 ms / 0.182 ms · 1.8× faster on A100 | opengl-timer-query · Cross-architecture validation |
Lineage
Crosses
- Triplanar mapping: Accumulates the three projected normals as gradients, giving correct lighting at blends.
Sources
- primaryMorten S. Mikkelsen. Surface Gradient–Based Bump Mapping Framework. JCGT 2020.Verified via live page · 2026-11-29