{
 "id": "normal-map-baking",
 "title": "High-to-low-poly normal map baking",
 "aliases": [
  "normal baking",
  "detail transfer"
 ],
 "domain": "materials",
 "subdomain": "asset pipeline",
 "stage": "material",
 "realtime": "interactive",
 "platforms": [
  "desktop-gpu",
  "blender",
  "cpu",
  "webgl2",
  "unity"
 ],
 "year_introduced": 1998,
 "inputs": [
  "mesh",
  "uv-atlas"
 ],
 "outputs": [
  "texture",
  "normals"
 ],
 "style": "both",
 "dynamic": "static",
 "summary": "Captures the surface detail of a dense mesh into a tangent-space normal map on a simplified one by casting from low-poly surface points to the high-poly surface, so cheap geometry shades like the sculpt.",
 "how_it_works": "Both meshes share a pose and the low-poly mesh needs a unique, non-overlapping UV layout. For every texel of the low-poly UV atlas, find its 3D point and interpolated normal, then find the matching point on the high-poly surface. Ray casting along or against the normal out to a cage distance is the common method; a GPU version rasterises the high-poly mesh in the low-poly's UV space and compares attributes. The high-poly normal at the hit is transformed into the low-poly tangent frame and packed as rgb = n*0.5+0.5. The tangent frame used for baking has to be the one the runtime uses, so synchronised tangent generation (`normal-mapping-mikktspace`) is mandatory. A cage, an inflated copy of the low mesh, bounds the ray start and avoids hits on the wrong layer. The same pass can emit ambient occlusion, curvature, position and thickness maps from the same hits.",
 "when_to_use": "Choose it for any game character, prop or hard-surface asset where the visible detail is sculpted or modelled at high density. Prefer displacement or `nanite-virtualized-geometry` when silhouette detail is needed. Prefer `parallax-occlusion-mapping` for depth parallax on the baked result. Use `qem-mesh-simplification` or `instant-meshes` to produce the low-poly target, and `xatlas` for UVs. For purely procedural detail, skip baking and use `surface-gradient-bump-mapping` in the shader.",
 "cost": {
  "class": "offline",
  "notes": "Bake time depends on ray counts and mesh size; runtime cost is one texture fetch."
 },
 "failure_modes": [
  "Skewed or wavy lines when the cage or ray direction is mismatched to the low-poly normals",
  "Floating geometry gets baked onto the wrong surface when rays hit the nearest layer",
  "Seam breaks at UV islands with different tangent handedness, and mirrored UVs bake incorrectly",
  "Hard edges on the low-poly need split normals or UV islands, otherwise gradients smear across the edge",
  "Baked in a different tangent basis from the one used at runtime gives lighting that looks inverted",
  "Texel padding too small causes dark halos when mips are generated"
 ],
 "sources": [
  {
   "role": "primary",
   "key": "url:https://developer.nvidia.com/gpugems/gpugems3/part-iv-image-effects/chapter-22-baking-normal-maps-gpu",
   "type": "web",
   "title": "Chapter 22. Baking Normal Maps on the GPU",
   "authors": [
    "Diogo Teixeira"
   ],
   "year": null,
   "venue": "developer.nvidia.com",
   "url": "https://developer.nvidia.com/gpugems/gpugems3/part-iv-image-effects/chapter-22-baking-normal-maps-gpu",
   "ids": {},
   "license": null,
   "extra": {
    "http_status": 200,
    "live": true,
    "archive": {
     "url": "http://web.archive.org/web/20260728171815/https://developer.nvidia.com/gpugems/gpugems3/part-iv-image-effects/chapter-22-baking-normal-maps-gpu",
     "timestamp": "20260728171815"
    },
    "page_title": "Chapter 22. Baking Normal Maps on the GPU",
    "host": "developer.nvidia.com",
    "title_confirmed_by_page": true,
    "title_unconfirmed": false
   },
   "provenance": {
    "title": {
     "authority": "http",
     "endpoint": "GET https://developer.nvidia.com/gpugems/gpugems3/part-iv-image-effects/chapter-22-baking-normal-maps-gpu → 200",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "url": {
     "authority": "http",
     "endpoint": "GET https://developer.nvidia.com/gpugems/gpugems3/part-iv-image-effects/chapter-22-baking-normal-maps-gpu → 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://developer.nvidia.com/gpugems/gpugems3/part-iv-image-effects/chapter-22-baking-normal-maps-gpu → 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": "teixeirachapter"
  },
  {
   "role": "secondary",
   "key": "doi:10.1145/280814.280832",
   "type": "paper",
   "title": "Appearance-preserving simplification",
   "authors": [
    "Jonathan Cohen",
    "Marc Olano",
    "Dinesh Manocha"
   ],
   "year": 1998,
   "venue": "Proceedings of the 25th annual conference on Computer graphics and interactive techniques  - SIGGRAPH '98",
   "url": "https://doi.org/10.1145/280814.280832",
   "ids": {
    "doi": "10.1145/280814.280832"
   },
   "license": null,
   "extra": {
    "csl_type": "proceedings-article"
   },
   "provenance": {
    "title": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1145/280814.280832",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "authors": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1145/280814.280832",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "year": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1145/280814.280832",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "venue": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1145/280814.280832",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "url": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1145/280814.280832",
     "checked_at": "2026-11-29T15:51:27.588Z"
    }
   },
   "status": "verified",
   "checked_at": "2026-11-29T15:51:27.588Z",
   "title_sim": 1,
   "__bib": "cohen1998appearance"
  }
 ],
 "presets": [
  {
   "id": "normal-map-baking-live",
   "title": "Normal Map Baking — low-poly mesh & tangent-space normal map (left) vs high-to-low baked shading (right)",
   "runtime": "glsl-fragment",
   "params": {
    "P_SCULPT_DEPTH": 0.85,
    "P_RIVET_FREQ": 6,
    "P_SPIN_SPEED": 0.42,
    "P_SPLIT": 0.48
   },
   "basis": "original",
   "license_note": "MIT — written for this index.",
   "code": "const float P_SCULPT_DEPTH = 0.85; // P Sculpt Relief [0.2, 1.6, 0.05]\nconst float P_RIVET_FREQ = 6.0; // P Panel Density [3.0, 10.0, 1.0]\nconst float P_SPIN_SPEED = 0.42; // P Turntable Speed [0.0, 1.5, 0.05]\nconst float P_SPLIT = 0.48; // P Cage / Baked Split [0.0, 1.0, 0.02]\n\n// Low-poly beveled cube-octahedron base mesh\nfloat sdLowPoly(vec3 p) {\n  vec3 ap = abs(p);\n  float dBox = max(ap.x, max(ap.y, ap.z)) - 0.52;\n  float dOct = (ap.x + ap.y + ap.z - 0.82) * 0.57735;\n  return max(dBox, dOct);\n}\n\n// High-poly sculpted height detail projected onto each face's local tangent coordinates\nfloat evalSculptHeight(vec2 uv, float freq) {\n  vec2 c = abs(uv) - 0.36;\n  float bevelPanel = smoothstep(0.04, -0.04, max(c.x, c.y));\n  vec2 g = fract(uv * freq) - 0.5;\n  float rivet = smoothstep(0.20, 0.08, length(g)) * step(0.24, max(abs(uv.x), abs(uv.y))) * step(max(abs(uv.x), abs(uv.y)), 0.40);\n  float emblem = smoothstep(0.03, -0.01, abs(length(uv) - 0.18));\n  float groove = smoothstep(0.022, 0.005, abs(uv.x)) * step(abs(uv.y), 0.32)\n               + smoothstep(0.022, 0.005, abs(uv.y)) * step(abs(uv.x), 0.32);\n  return bevelPanel * 0.35 + rivet * 0.55 + emblem * 0.42 - clamp(groove, 0.0, 1.0) * 0.32;\n}\n\nvec3 evalBakedTangentNormal(vec2 uv, float freq, float depth) {\n  float e = 0.006;\n  float h = evalSculptHeight(uv, freq);\n  float hx = evalSculptHeight(uv + vec2(e, 0.0), freq);\n  float hy = evalSculptHeight(uv + vec2(0.0, e), freq);\n  return normalize(vec3(-(hx - h) / e * 0.045 * depth, -(hy - h) / e * 0.045 * depth, 1.0));\n}\n\nvec3 calcLowNormal(vec3 p) {\n  vec2 e = vec2(0.002, 0.0);\n  return normalize(vec3(\n    sdLowPoly(p + e.xyy) - sdLowPoly(p - e.xyy),\n    sdLowPoly(p + e.yxy) - sdLowPoly(p - e.yxy),\n    sdLowPoly(p + e.yyx) - sdLowPoly(p - e.yyx)\n  ));\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 sx = fragCoord.x / max(iResolution.x, 1.0);\n  float split = clamp(P_SPLIT, 0.0, 1.0);\n  bool showBaked = sx >= split;\n\n  float depth = clamp(P_SCULPT_DEPTH, 0.1, 2.0);\n  float freq = clamp(floor(P_RIVET_FREQ + 0.5), 2.0, 12.0);\n  float a = iTime * max(P_SPIN_SPEED, 0.0) + 0.45;\n  float bAng = 0.36;\n  mat3 ry = mat3(cos(a), 0.0, sin(a), 0.0, 1.0, 0.0, -sin(a), 0.0, cos(a));\n  mat3 rx = mat3(1.0, 0.0, 0.0, 0.0, cos(bAng), -sin(bAng), 0.0, sin(bAng), cos(bAng));\n  mat3 rot = rx * ry;\n\n  vec3 ro = vec3(0.0, 0.04, 2.15);\n  vec3 rd = normalize(vec3(uv, -1.52));\n  vec3 col = mix(vec3(0.06, 0.07, 0.10), vec3(0.16, 0.20, 0.28), uv.y + 0.5);\n\n  float t = 0.05;\n  bool hit = false;\n  for (int i = 0; i < 64; i++) {\n    vec3 op = rot * (ro + rd * t);\n    float d = sdLowPoly(op);\n    if (d < 0.0018) { hit = true; break; }\n    t += d;\n    if (t > 6.0) break;\n  }\n\n  if (hit) {\n    vec3 op = rot * (ro + rd * t);\n    vec3 nObj = calcLowNormal(op);\n    // Project local face UV and tangent basis on each faceted face\n    vec3 an = abs(nObj);\n    vec2 fuv;\n    vec3 tObj, bObj;\n    if (an.x >= an.y && an.x >= an.z) {\n      fuv = op.zy;\n      tObj = vec3(0.0, 0.0, 1.0);\n      bObj = vec3(0.0, 1.0, 0.0);\n    } else if (an.y >= an.x && an.y >= an.z) {\n      fuv = op.xz;\n      tObj = vec3(1.0, 0.0, 0.0);\n      bObj = vec3(0.0, 0.0, 1.0);\n    } else {\n      fuv = op.xy;\n      tObj = vec3(1.0, 0.0, 0.0);\n      bObj = vec3(0.0, 1.0, 0.0);\n    }\n    // Orthogonalize tangent frame for chamfered octant faces\n    tObj = normalize(tObj - nObj * dot(tObj, nObj));\n    bObj = cross(nObj, tObj);\n\n    vec3 tn = evalBakedTangentNormal(fuv, freq, depth);\n    vec3 bakedN = normalize(transpose(rot) * (tObj * tn.x + bObj * tn.y + nObj * tn.z));\n    vec3 flatN = normalize(transpose(rot) * nObj);\n\n    vec3 L = normalize(vec3(0.62, 0.74, 0.58));\n    vec3 v = -rd;\n\n    if (!showBaked) {\n      // Left: Tangent-space normal map RGB (purple/cyan/pink) baked directly onto the faceted low-poly cage\n      vec3 nmRGB = tn * 0.5 + 0.5;\n      float ndl = 0.55 + 0.45 * max(dot(flatN, L), 0.0);\n      // Facet edge wireframe highlight\n      vec3 ap = abs(op);\n      float edge = smoothstep(0.025, 0.004, abs((ap.x + ap.y + ap.z - 0.82) * 0.57735 - (max(ap.x, max(ap.y, ap.z)) - 0.52)));\n      col = nmRGB * ndl + vec3(0.95, 0.92, 0.45) * edge * 0.45;\n    } else {\n      // Right: Identical low-poly silhouette shaded with the baked tangent-space normal map\n      vec3 H = normalize(L + v);\n      float ndl = max(dot(bakedN, L), 0.0);\n      float ndh = max(dot(bakedN, H), 0.0);\n      float rim = pow(1.0 - max(dot(bakedN, v), 0.0), 3.0);\n      vec3 alb = vec3(0.66, 0.54, 0.36);\n      float spec = pow(ndh, 42.0) * 1.1;\n      vec3 sky = mix(vec3(0.14, 0.18, 0.26), vec3(0.38, 0.48, 0.66), 0.5 + 0.5 * bakedN.y);\n      col = alb * (vec3(1.25, 1.15, 0.98) * ndl + sky * 0.52) + vec3(1.0, 0.88, 0.68) * (spec + rim * 0.25);\n    }\n  }\n\n  // Lower-left corner: inset 2D tangent-space normal map texture tile preview\n  vec2 insetUv = (fragCoord / max(iResolution.y, 1.0)) - vec2(0.05, 0.06);\n  if (!showBaked && insetUv.x > 0.0 && insetUv.x < 0.26 && insetUv.y > 0.0 && insetUv.y < 0.26) {\n    vec2 tileUv = (insetUv / 0.26 - 0.5) * 0.95;\n    vec3 tn = evalBakedTangentNormal(tileUv, freq, depth);\n    col = tn * 0.5 + 0.5;\n    vec2 b = abs(insetUv / 0.26 - 0.5);\n    if (max(b.x, b.y) > 0.48) col = vec3(0.95, 0.96, 1.0);\n  }\n\n  float sep = smoothstep(0.0035, 0.0008, abs(sx - split));\n  col = mix(col, vec3(0.95, 0.97, 1.0), sep);\n  fragColor = vec4(pow(clamp(aces(col), 0.0, 1.0), vec3(1.0 / 2.2)), 1.0);\n}",
   "execution_fidelity": "conceptual-diagram",
   "proof": {
    "kind": "rendered",
    "label": "rendered 2026-11-30",
    "ok": true,
    "proof": {
     "ok": true,
     "technique": "normal-map-baking",
     "runtime": "glsl-fragment",
     "checked_at": "2026-11-30T21:07:18.000Z",
     "renderer": "Headless EGL Tesla T4/PCIe/SSE2, OpenGL 3.30 Core, 512×512, iTime=1.5",
     "stats": {
      "mean": 0.6348,
      "std": 0.2036,
      "min": 0.2648,
      "max": 0.9459
     },
     "image": "/specimens/normal-map-baking-live.webp",
     "reason": null
    }
   }
  }
 ],
 "related": [
  "normal-mapping-mikktspace",
  "xatlas",
  "qem-mesh-simplification",
  "lightmap-baking",
  "parallax-occlusion-mapping",
  "curvature-map-baking"
 ],
 "extends": [],
 "supersedes": [],
 "combines_with": [
  {
   "id": "normal-mapping-mikktspace",
   "why": "The baker writes tangent-space normals; MikkTSpace guarantees the shader decodes them with the same basis."
  },
  {
   "id": "xatlas",
   "why": "Provides the non-overlapping UV layout that the bake needs on the low-poly mesh."
  }
 ],
 "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/normal-map-baking.json"
 },
 "solves": [
  "want detail of a sculpt on a low poly mesh",
  "baked normal map looks skewed or wavy",
  "need to transfer high poly detail to game asset",
  "dark seams appear along uv edges after baking",
  "setting up a cage for bake rays"
 ],
 "authority": "Teixeira",
 "url": "https://texelatlas.vercel.app/t/normal-map-baking/",
 "execution_fidelity": "conceptual-diagram",
 "fidelity_label": "Visual Diagram",
 "benchmark_eligible": false,
 "gpu_weight": {
  "weight_x": 7.06,
  "tier": "moderate",
  "p50_ms": 0.2324,
  "p95_ms": 0.2465,
  "baseline_p50_ms": 0.0329,
  "gpu": "Tesla T4/PCIe/SSE2",
  "resolution": "1920x1080",
  "method": "opengl-timer-query",
  "frames": 32,
  "preset_id": "normal-map-baking-live",
  "execution_fidelity": "conceptual-diagram",
  "fidelity_label": "Visual Diagram",
  "benchmark_eligible": false,
  "generated_at": "2026-11-30T21:07:47Z",
  "l4": {
   "weight_x": 5.99,
   "tier": "light",
   "p50_ms": 0.0952,
   "p95_ms": 0.0985,
   "speedup_x": 2.44,
   "gpu": "NVIDIA L4/PCIe/SSE2",
   "resolution": "1920x1080",
   "baseline_p50_ms": 0.0159
  },
  "a100": {
   "weight_x": 4.96,
   "tier": "light",
   "p50_ms": 0.1428,
   "p95_ms": 0.1453,
   "speedup_x": 1.63,
   "gpu": "NVIDIA A100-SXM4-40GB/PCIe/SSE2",
   "resolution": "1920x1080",
   "baseline_p50_ms": 0.0288
  }
 }
}