{
 "id": "reoriented-normal-mapping",
 "title": "Reoriented normal map blending (detail normals)",
 "aliases": [
  "RNM",
  "reoriented normal blending"
 ],
 "domain": "materials",
 "subdomain": "normal mapping",
 "stage": "material",
 "realtime": "realtime",
 "platforms": [
  "webgl2",
  "webgpu",
  "desktop-gpu",
  "mobile-gpu",
  "unity",
  "unreal",
  "godot",
  "blender"
 ],
 "year_introduced": 2012,
 "inputs": [
  "normals",
  "texture"
 ],
 "outputs": [
  "normals"
 ],
 "style": "both",
 "dynamic": "both",
 "summary": "A correct way to layer a detail normal map onto a base normal map: it rotates the detail normal into the frame of the base so slopes combine as real orientations rather than averaged offsets.",
 "how_it_works": "Blending two tangent-space normals by adding xy and renormalising treats them as height gradients and flattens detail where the base is steep. Reoriented blending instead rotates the detail normal by the rotation that carries the +Z axis to the base normal. With t = base*(2,2,2)+(-1,-1,0) and u = detail*(-2,-2,2)+(1,1,-1), the result is r = t * dot(t,u) / t.z - u, then normalised. That is the shortest-arc rotation applied to the detail vector in closed form: no trigonometry or matrix building, just a dot product and a divide. Cheaper approximations include UDN (add the detail xy to the base) and the whiteout blend (add xy, multiply z), which keep strong detail but are not exact. RNM is the reference that others are compared to; the cost difference matters only on weak hardware.",
 "when_to_use": "Use it whenever a detail or micro normal map is layered on top of a macro normal map, or when decals and triplanar projections combine tangent-space normals. Prefer `surface-gradient-bump-mapping` for a framework that blends many bump or normal sources in one place with consistent semantics. Prefer plain UDN or whiteout when ALU is critical. Use `normal-distribution-filtering` or `toksvig-mipmapping` for how those normal maps are filtered and minified.",
 "cost": {
  "class": "cheap",
  "notes": "A dot product, a divide and a normalise per blend."
 },
 "failure_modes": [
  "Uses the +Z-up unpacked convention; passing already-biased [0,1] values or OpenGL/DirectX Y-flipped maps gives wrong slopes",
  "Division by t.z blows up when the base normal is nearly horizontal, unless clamped",
  "Blending must happen before the TBN transform; blending in world space reintroduces the error",
  "Not associative: blending in a different order across layers changes the result slightly",
  "Mip-averaged detail normals shorten in length, so the blend underestimates detail at distance without length-aware filtering"
 ],
 "sources": [
  {
   "role": "primary",
   "key": "url:https://blog.selfshadow.com/publications/blending-in-detail",
   "type": "web",
   "title": "Blending in Detail",
   "authors": [
    "Colin Barre-Brisebois",
    "Stephen Hill"
   ],
   "year": null,
   "venue": "blog.selfshadow.com",
   "url": "https://blog.selfshadow.com/publications/blending-in-detail",
   "ids": {},
   "license": null,
   "extra": {
    "http_status": 200,
    "live": true,
    "archive": {
     "url": "http://web.archive.org/web/20260922134515/https://blog.selfshadow.com/publications/blending-in-detail/",
     "timestamp": "20260922134515"
    },
    "page_title": "Blending in Detail",
    "host": "blog.selfshadow.com",
    "title_confirmed_by_page": true,
    "title_unconfirmed": false
   },
   "provenance": {
    "title": {
     "authority": "http",
     "endpoint": "GET https://blog.selfshadow.com/publications/blending-in-detail → 200",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "url": {
     "authority": "http",
     "endpoint": "GET https://blog.selfshadow.com/publications/blending-in-detail → 200",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "authors": {
     "authority": "research-draft",
     "endpoint": "title_hint/author_hint, checked against page title where available",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "venue": {
     "authority": "http",
     "endpoint": "GET https://blog.selfshadow.com/publications/blending-in-detail → 200",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "year": {
     "authority": "research-draft",
     "endpoint": "title_hint/author_hint, checked against page title where available",
     "checked_at": "2026-11-29T15:51:27.588Z"
    }
   },
   "status": "verified",
   "checked_at": "2026-11-29T15:51:27.588Z",
   "title_sim": 1,
   "__bib": "barrebriseboisblending"
  }
 ],
 "presets": [
  {
   "id": "reoriented-normal-mapping-live",
   "title": "Reoriented Normal Mapping (RNM) — linear/UDN normal blend flattening (left) vs quaternion RNM rotation (right)",
   "runtime": "glsl-fragment",
   "params": {
    "P_MACRO_STEEP": 1,
    "P_DETAIL_STR": 0.85,
    "P_LIGHT_SPIN": 0.65,
    "P_SPLIT": 0.48
   },
   "basis": "original",
   "license_note": "MIT — written for this index.",
   "code": "const float P_MACRO_STEEP = 1.0; // P Base Slope Steep [0.2, 1.5, 0.05]\nconst float P_DETAIL_STR = 0.85; // P Detail Strength [0.1, 1.5, 0.05]\nconst float P_LIGHT_SPIN = 0.65; // P Light Orbit [0.0, 2.2, 0.05]\nconst float P_SPLIT = 0.48; // P Linear / RNM Split [0.0, 1.0, 0.02]\n\n// Base macro normal map: bold embossed circular domes & deep fluted ridges (very steep base slopes!)\nvec3 evalBaseNormal(vec2 uv, float steep) {\n  vec2 p = uv * 3.2;\n  vec2 cell = fract(p) - 0.5;\n  float r = length(cell);\n  // Steep spherical bump + wave ridges\n  vec2 grad = vec2(0.0);\n  if (r < 0.38) {\n    grad += (cell / max(r, 1e-4)) * smoothstep(0.38, 0.05, r) * 2.4;\n  }\n  grad += vec2(cos(uv.x * 14.0), sin(uv.y * 14.0)) * 0.85;\n  grad *= steep;\n  return normalize(vec3(-grad.x, -grad.y, 1.0));\n}\n\n// High-frequency detail normal map: crisp micro-hexagonal scales / embossed fabric studs\nvec3 evalDetailNormal(vec2 uv, float str) {\n  vec2 q = uv * 34.0;\n  vec2 f = fract(q) - 0.5;\n  float r = length(f);\n  vec2 dg = (r < 0.38) ? (f / max(r, 1e-4)) * smoothstep(0.38, 0.08, r) * 1.65 : vec2(0.0);\n  dg += vec2(cos(q.x * 3.14159), sin(q.y * 3.14159)) * 0.45;\n  dg *= str;\n  return normalize(vec3(-dg.x, -dg.y, 1.0));\n}\n\n// Reoriented Normal Mapping (Barre-Brisebois & Hill 2012): shortest-arc quaternion rotation of n2 onto n1!\nvec3 blendRNM(vec3 n1, vec3 n2) {\n  vec3 t = n1 + vec3(0.0, 0.0, 1.0);\n  vec3 u = n2 * vec3(-1.0, -1.0, 1.0);\n  return normalize(t * (dot(t, u) / max(t.z, 1e-4)) - u);\n}\n\n// Naive linear normal blending (washes out detail when base normal tilts steeply away from +Z!)\nvec3 blendLinear(vec3 n1, vec3 n2) {\n  return normalize(n1 + n2);\n}\n\nvec3 aces(vec3 x) {\n  x = max(x, 0.0);\n  return (x * (2.51 * x + 0.03)) / (x * (2.43 * x + 0.59) + 0.14);\n}\n\nvoid mainImage(out vec4 fragColor, in vec2 fragCoord) {\n  vec2 uv = (fragCoord - 0.5 * iResolution.xy) / iResolution.y;\n  float screenX = fragCoord.x / max(iResolution.x, 1.0);\n  float split = clamp(P_SPLIT, 0.0, 1.0);\n  bool isRNM = screenX >= split;\n  float steep = clamp(P_MACRO_STEEP, 0.15, 1.6);\n  float detStr = clamp(P_DETAIL_STR, 0.05, 1.6);\n  float spin = iTime * max(P_LIGHT_SPIN, 0.0);\n\n  vec3 nBase = evalBaseNormal(uv, steep);\n  vec3 nDet = evalDetailNormal(uv, detStr);\n  vec3 n = isRNM ? blendRNM(nBase, nDet) : blendLinear(nBase, nDet);\n\n  // Orbiting grazing studio key light + cool fill light so slope-normal differences pop unmistakably!\n  vec3 l1 = normalize(vec3(cos(spin * 0.75) * 0.85, sin(spin * 0.75) * 0.85, 0.42));\n  vec3 l2 = normalize(vec3(-0.65, 0.55, 0.65));\n  vec3 v = vec3(0.0, 0.0, 1.0);\n\n  float diff1 = max(dot(n, l1), 0.0);\n  float diff2 = max(dot(n, l2), 0.0);\n  float spec1 = pow(max(dot(n, normalize(l1 + v)), 0.0), 48.0);\n  float spec2 = pow(max(dot(n, normalize(l2 + v)), 0.0), 28.0);\n\n  // Anodized copper-slate ceramic shader\n  vec3 alb = mix(vec3(0.18, 0.24, 0.34), vec3(0.84, 0.46, 0.26), smoothstep(0.4, 0.95, nBase.z));\n  vec3 col = alb * (0.16 + 0.95 * diff1 + 0.30 * diff2)\n           + vec3(1.0, 0.90, 0.78) * spec1 * 0.88\n           + vec3(0.32, 0.74, 1.0) * spec2 * 0.35;\n\n  // Subtle normal-map diagnostic strip along bottom edge\n  float screenY = fragCoord.y / max(iResolution.y, 1.0);\n  if (screenY < 0.12) {\n    col = mix(col, n * 0.5 + 0.5, smoothstep(0.12, 0.11, screenY) * 0.92);\n  }\n\n  float sep = smoothstep(0.0035, 0.0008, abs(screenX - split));\n  col = mix(col, vec3(0.95, 0.97, 1.0), sep);\n\n  fragColor = vec4(pow(clamp(aces(col), 0.0, 1.0), vec3(1.0 / 2.2)), 1.0);\n}",
   "execution_fidelity": "faithful-pass",
   "proof": {
    "kind": "rendered",
    "label": "rendered 2026-11-30",
    "ok": true,
    "proof": {
     "ok": true,
     "technique": "reoriented-normal-mapping",
     "runtime": "glsl-fragment",
     "checked_at": "2026-11-30T20:35:55.000Z",
     "renderer": "Headless EGL Tesla T4/PCIe/SSE2, OpenGL 3.30 Core, 512×512, iTime=1.5",
     "stats": {
      "mean": 0.6591,
      "std": 0.1621,
      "min": 0.1967,
      "max": 0.9324
     },
     "image": "/specimens/reoriented-normal-mapping-live.webp",
     "reason": null
    }
   }
  }
 ],
 "related": [
  "normal-mapping-mikktspace",
  "surface-gradient-bump-mapping",
  "triplanar-mapping",
  "normal-distribution-filtering",
  "toksvig-mipmapping",
  "deferred-and-projected-decals"
 ],
 "extends": [
  "normal-mapping-mikktspace"
 ],
 "supersedes": [],
 "combines_with": [
  {
   "id": "triplanar-mapping",
   "why": "The three projected tangent-space normals are combined with reoriented blending instead of a linear mix."
  },
  {
   "id": "deferred-and-projected-decals",
   "why": "Decal normals are layered over the stored surface normal using the same rotation."
  }
 ],
 "provenance": {
  "prose": "original text written for this index (research draft, editorially reviewed)",
  "sources_verified_at": "2026-11-29T15:51:27.588Z",
  "draft": "data/drafts/materials/reoriented-normal-mapping.json"
 },
 "solves": [
  "detail normal map flattens the base normal map",
  "blending two normal maps looks wrong on slopes",
  "combining triplanar or decal normals correctly",
  "micro detail normals lose strength on curved areas",
  "choose between udn whiteout and correct normal blend"
 ],
 "authority": "Barre-Brisebois & Hill",
 "url": "https://texelatlas.vercel.app/t/reoriented-normal-mapping/",
 "execution_fidelity": "faithful-pass",
 "fidelity_label": "Faithful Pass",
 "benchmark_eligible": true,
 "gpu_weight": {
  "weight_x": 4.14,
  "tier": "light",
  "p50_ms": 0.1363,
  "p95_ms": 0.1387,
  "baseline_p50_ms": 0.0329,
  "gpu": "Tesla T4/PCIe/SSE2",
  "resolution": "1920x1080",
  "method": "opengl-timer-query",
  "frames": 32,
  "preset_id": "reoriented-normal-mapping-live",
  "execution_fidelity": "faithful-pass",
  "fidelity_label": "Faithful Pass",
  "benchmark_eligible": true,
  "generated_at": "2026-11-30T21:07:47Z",
  "l4": {
   "weight_x": 3.36,
   "tier": "light",
   "p50_ms": 0.0535,
   "p95_ms": 0.054,
   "speedup_x": 2.55,
   "gpu": "NVIDIA L4/PCIe/SSE2",
   "resolution": "1920x1080",
   "baseline_p50_ms": 0.0159
  },
  "a100": {
   "weight_x": 2.5,
   "tier": "light",
   "p50_ms": 0.0721,
   "p95_ms": 0.0722,
   "speedup_x": 1.89,
   "gpu": "NVIDIA A100-SXM4-40GB/PCIe/SSE2",
   "resolution": "1920x1080",
   "baseline_p50_ms": 0.0288
  }
 }
}