---
id: "surface-gradient-bump-mapping"
title: "Surface gradient based bump mapping framework"
domain: "materials"
stage: "material"
realtime: "realtime"
platforms: [webgl2, webgpu, desktop-gpu, mobile-gpu, unity, unreal, godot, blender]
year_introduced: 2020
inputs: [normals, texture, mesh]
outputs: [normals]
style: "photoreal"
dynamic: "both"
cost: "cheap"
authority: "Mikkelsen"
url: "https://texelatlas.vercel.app/t/surface-gradient-bump-mapping/"
sources_verified_at: "2026-11-29"
---
# Surface gradient based bump mapping framework (Mikkelsen)

> 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.

## 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

## 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 use it

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](https://texelatlas.vercel.app/t/normal-mapping-mikktspace.md) for a single UV-mapped normal map with baked tangents. Pair with [Triplanar mapping](https://texelatlas.vercel.app/t/triplanar-mapping.md) and [Hex-tiling](https://texelatlas.vercel.app/t/hex-tiling.md) for blended world-space normals.

## Cost

cheap — Derivative-based basis plus a few vector ops; slightly more ALU than a tangent-frame fetch.
Measured GPU Weight: 10.16× baseline (moderate) — 0.3341 ms median / 0.3452 ms p95 on Tesla T4/PCIe/SSE2 @ 1920x1080 (opengl-timer-query).
Ada L4 scaling: 7.77× baseline (moderate) — 0.1236 ms median (2.7× faster on L4).
Ampere A100 scaling: 6.32× baseline (moderate) — 0.1819 ms median (1.84× faster on A100).

## Failure modes

- 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

## Engine support

- babylonjs: builtin — `bumpFragmentMainFunctions.fx perturbNormal screen-space surface-gradient perturbation` (evidence: https://github.com/BabylonJS/Babylon.js/blob/9.38.0/packages/dev/core/src/Shaders/ShadersInclude/bumpFragmentMainFunctions.fx, checked 2026-12-01)
- threejs: builtin — `material.bumpMap = texture` (evidence: https://github.com/mrdoob/three.js/blob/r187/src/nodes/display/BumpMapNode.js, checked 2026-12-01) — Derivative-based bump map after Mikkelsen's surface-gradient paper.
- unity: builtin — `HDRP Lit normal and detail mapping (always on)` (evidence: https://github.com/Unity-Technologies/Graphics/blob/557f6ac22b948284f57ffae6a789751fd1f63620/Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariablesFunctions.hlsl, checked 2026-12-01) — HDRP shaders blend normals via the surface-gradient framework.

## Dataflow

- Inputs: normals, texture, mesh
- Outputs: normals
- Platforms: webgl2, webgpu, desktop-gpu, mobile-gpu, unity, unreal, godot, blender

## Presets

### Surface Gradient Bump Mapping — UV tangent seam & pole pinch (left) vs tangent-free surface gradient (right) (glsl-fragment; rendered 2026-11-30)

```json
{
  "P_BUMP_FREQ": 12,
  "P_GRAD_STR": 0.85,
  "P_ROT_SPEED": 0.55,
  "P_SPLIT": 0.48
}
```

```glsl
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.

## Lineage

- extends [Reoriented normal map blending (detail normals)](https://texelatlas.vercel.app/t/reoriented-normal-mapping.md)

## Combines with

- [Triplanar mapping](https://texelatlas.vercel.app/t/triplanar-mapping.md): Accumulates the three projected normals as gradients, giving correct lighting at blends.

## Sources

1. [primary] Morten S. Mikkelsen Surface Gradient–Based Bump Mapping Framework. JCGT 2020. https://jcgt.org/published/0009/03/04 (verified via http on 2026-11-29)

## Cite this entry

Texel. "Surface gradient based bump mapping framework." https://texelatlas.vercel.app/t/surface-gradient-bump-mapping/ (accessed 2026-12-01).
