{
 "id": "lightmap-baking",
 "title": "Lightmap Baking",
 "aliases": [
  "baked GI",
  "precomputed lighting",
  "lightmapping"
 ],
 "domain": "gi",
 "subdomain": "precomputed GI",
 "stage": "lighting",
 "realtime": "realtime",
 "platforms": [
  "webgl2",
  "webgpu",
  "desktop-gpu",
  "mobile-gpu",
  "unity",
  "unreal",
  "godot",
  "blender"
 ],
 "year_introduced": 1996,
 "inputs": [
  "mesh",
  "uv-atlas",
  "material-params"
 ],
 "outputs": [
  "texture"
 ],
 "style": "photoreal",
 "dynamic": "static",
 "summary": "Precomputes the lighting of static surfaces offline into textures addressed by a second, non-overlapping UV set, then samples them at runtime for essentially free GI.",
 "how_it_works": "Every static mesh gets a **lightmap UV atlas**: a unique, non-overlapping unwrap with padding between charts so bilinear filtering does not bleed. Texels of the atlas are mapped back to world positions and normals. A baker then computes the irradiance (or directional radiance) at each texel with an offline integrator, typically [path-tracing](path-tracing) with many samples, and writes the results into a texture. Storage formats include RGB irradiance, plus a dominant light direction or low-order spherical-harmonic or spherical-Gaussian coefficients so normal maps still respond to the light.\n\nAfter baking, a **denoiser** cleans the noisy output and a **dilation** pass fills texels outside the charts to avoid seams. At runtime the shader multiplies albedo by the sampled lightmap value, optionally combined with real-time direct light and [irradiance-volumes](irradiance-volumes) probes for dynamic objects.\n\nThe baker is the offline system; the runtime cost is one texture fetch per pixel.",
 "when_to_use": "Choose it for static scenes, mobile and web targets, and anything with a tight frame budget where high-quality interreflection and soft shadows must be paid for once.\n\nPrefer [irradiance-volumes](irradiance-volumes) for dynamic objects and for volumes without UVs. Prefer [ddgi](ddgi), [lumen-gi](lumen-gi) or [surfel-gi](surfel-gi) when lights or geometry move at runtime. Prefer [precomputed-radiance-transfer](precomputed-radiance-transfer) when the light changes but the geometry is rigid.",
 "cost": {
  "class": "cheap",
  "notes": "Runtime cost is a texture fetch; bake time ranges from minutes to hours depending on resolution and sample count. Memory grows with atlas resolution."
 },
 "failure_modes": [
  "Seams along chart borders from missing padding or inconsistent texel density between adjacent charts",
  "Light and shadow bleeding where thin walls share texels from both sides",
  "Static only: moving lights or doors leave baked shadows behind, requiring a hybrid with dynamic direct light",
  "Atlas packing waste and long iteration times: any geometry or light edit requires a rebake"
 ],
 "sources": [
  {
   "role": "primary",
   "key": "doi:10.1145/2504459.2504484",
   "type": "paper",
   "title": "Lighting technology of the last of us",
   "authors": [
    "Michal Iwanicki"
   ],
   "year": 2013,
   "venue": "ACM SIGGRAPH 2013 Talks",
   "url": "https://doi.org/10.1145/2504459.2504484",
   "ids": {
    "doi": "10.1145/2504459.2504484"
   },
   "license": null,
   "extra": {
    "csl_type": "proceedings-article"
   },
   "provenance": {
    "title": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1145/2504459.2504484",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "authors": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1145/2504459.2504484",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "year": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1145/2504459.2504484",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "venue": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1145/2504459.2504484",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "url": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1145/2504459.2504484",
     "checked_at": "2026-11-29T15:51:27.588Z"
    }
   },
   "status": "verified",
   "checked_at": "2026-11-29T15:51:27.588Z",
   "title_sim": 1,
   "__bib": "iwanicki2013lighting"
  },
  {
   "role": "implementation",
   "key": "gh:ands/lightmapper",
   "type": "code",
   "title": "ands/lightmapper",
   "description": "A C/C++ single-file library for drop-in lightmap baking. Just use your existing OpenGL renderer to bounce light!",
   "authors": [
    "ands"
   ],
   "year": 2016,
   "venue": "GitHub",
   "url": "https://github.com/ands/lightmapper",
   "ids": {
    "repo": "ands/lightmapper"
   },
   "license": null,
   "extra": {
    "stars": 1548,
    "stars_checked": "2026-11-29",
    "archived": false,
    "fork": false,
    "pushed_at": "2023-03-24T08:48:21Z",
    "language": "C",
    "homepage": null,
    "license_name": null
   },
   "provenance": {
    "title": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/ands/lightmapper",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "authors": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/ands/lightmapper",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "year": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/ands/lightmapper",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "venue": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/ands/lightmapper",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "url": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/ands/lightmapper",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "license": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/ands/lightmapper",
     "checked_at": "2026-11-29T15:51:27.588Z"
    }
   },
   "status": "verified",
   "checked_at": "2026-11-29T15:51:27.588Z",
   "title_sim": null,
   "__bib": "ands2016ands"
  }
 ],
 "presets": [
  {
   "id": "lightmap-baking-live",
   "title": "Lightmap Baking — coarse UV-chart texels & seams (left) vs high-res directional baked lightmap (right)",
   "runtime": "glsl-fragment",
   "params": {
    "P_TEXEL_RES": 10,
    "P_BOUNCE_INT": 1.25,
    "P_CHART_VIS": 0.75,
    "P_SPLIT": 0.48
   },
   "basis": "original",
   "license_note": "MIT — written for this index.",
   "code": "const float P_TEXEL_RES = 10.0; // P Low-Res Texels [4.0, 20.0, 1.0]\nconst float P_BOUNCE_INT = 1.25; // P Baked GI Gain [0.3, 2.2, 0.05]\nconst float P_CHART_VIS = 0.75; // P UV Chart Grid [0.0, 1.5, 0.05]\nconst float P_SPLIT = 0.48; // P Coarse / Fine Split [0.0, 1.0, 0.02]\n\nfloat sdBox(vec3 p, vec3 b) {\n  vec3 q = abs(p) - b;\n  return length(max(q, 0.0)) + min(max(q.x, max(q.y, q.z)), 0.0);\n}\n\n// Sunlit architectural gallery with skylight aperture and sculpted bench + archway\nvec2 mapScene(vec3 p) {\n  vec2 res = vec2(p.y + 0.85, 1.0);\n  float dC = 1.05 - p.y; if (dC < res.x) res = vec2(dC, 1.0);\n  float dB = p.z + 1.45; if (dB < res.x) res = vec2(dB, 2.0);\n  float dL = p.x + 1.35; if (dL < res.x) res = vec2(dL, 3.0);\n  float dR = 1.35 - p.x; if (dR < res.x) res = vec2(dR, 4.0);\n\n  float dBench = sdBox(p - vec3(-0.35, -0.58, -0.35), vec3(0.42, 0.27, 0.24)) - 0.02;\n  if (dBench < res.x) res = vec2(dBench, 5.0);\n  float dPed = sdBox(p - vec3(0.55, -0.45, -0.55), vec3(0.24, 0.40, 0.24)) - 0.02;\n  if (dPed < res.x) res = vec2(dPed, 5.0);\n  float dSph = length(p - vec3(0.55, 0.14, -0.55)) - 0.22;\n  if (dSph < res.x) res = vec2(dSph, 6.0);\n  return res;\n}\n\nvec3 calcNormal(vec3 p) {\n  vec2 e = vec2(0.0022, 0.0);\n  return normalize(vec3(\n    mapScene(p + e.xyy).x - mapScene(p - e.xyy).x,\n    mapScene(p + e.yxy).x - mapScene(p - e.yxy).x,\n    mapScene(p + e.yyx).x - mapScene(p - e.yyx).x\n  ));\n}\n\n// Evaluate precomputed static lightmap irradiance at UV-mapped surface point p\nvec3 bakeLightmap(vec3 p, vec3 n, float giGain) {\n  // Warm angled skylight beam hitting floor & bench + soft indirect bounce\n  vec3 sunDir = normalize(vec3(0.45, 0.82, 0.35));\n  float tPlane = (1.05 - p.y) / sunDir.y;\n  vec2 skyHit = p.xz + sunDir.xz * tPlane;\n  float inBeam = smoothstep(0.52, 0.34, abs(skyHit.x + 0.15)) * smoothstep(0.42, 0.26, abs(skyHit.y + 0.35));\n  float ndl = max(dot(n, sunDir), 0.0);\n\n  // Soft shadow occlusion inside baked pass\n  float sh = 1.0;\n  float ts = 0.04;\n  for (int i = 0; i < 16; i++) {\n    float d = mapScene(p + sunDir * ts).x;\n    sh = min(sh, 5.5 * d / max(ts, 0.04));\n    ts += clamp(d, 0.03, 0.20);\n    if (sh < 0.05 || ts > 2.2) break;\n  }\n  vec3 sunDirect = vec3(2.4, 2.05, 1.55) * ndl * inBeam * clamp(sh, 0.0, 1.0);\n\n  // Multi-bounce color bleed from sunlit warm terracotta floor patch & cool sky fill\n  float floorBounce = exp(-length(p - vec3(-0.35, -0.85, -0.45)) * 0.95);\n  vec3 indirect = vec3(0.92, 0.56, 0.26) * floorBounce * 0.72;\n  indirect += vec3(0.28, 0.46, 0.74) * (0.45 + 0.55 * max(n.y, 0.0)) * 0.48;\n  float ao = clamp(0.35 + 0.65 * mapScene(p + n * 0.26).x / 0.26, 0.16, 1.0);\n  return sunDirect + indirect * giGain * ao;\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 isHiRes = screenX >= split;\n  float texRes = clamp(floor(P_TEXEL_RES + 0.5), 4.0, 22.0);\n  float giGain = clamp(P_BOUNCE_INT, 0.2, 2.4);\n  float chartVis = clamp(P_CHART_VIS, 0.0, 1.5);\n\n  float camAng = 0.14 * sin(iTime * 0.42);\n  vec3 ro = vec3(0.32 * sin(camAng), 0.06, 2.38);\n  vec3 rd = normalize(vec3(uv, -1.52));\n\n  vec3 col = vec3(0.03);\n  float t = 0.0;\n  float matId = 0.0;\n  bool hit = false;\n  for (int i = 0; i < 64; i++) {\n    vec2 h = mapScene(ro + rd * t);\n    if (h.x < 0.002) { hit = true; matId = h.y; break; }\n    t += h.x;\n    if (t > 9.0) break;\n  }\n\n  if (hit) {\n    vec3 p = ro + rd * t;\n    vec3 n = calcNormal(p);\n\n    // Triplanar non-overlapping UV2 chart coordinates per surface orientation\n    vec3 an = abs(n);\n    vec2 lmUV = (an.x > an.y && an.x > an.z) ? p.yz : ((an.y > an.z) ? p.xz : p.xy);\n\n    vec3 alb = vec3(0.76, 0.74, 0.70);\n    if (matId > 2.5 && matId < 3.5) alb = vec3(0.84, 0.44, 0.26);\n    if (matId > 3.5 && matId < 4.5) alb = vec3(0.32, 0.56, 0.70);\n    if (matId > 5.5) alb = vec3(0.88, 0.82, 0.68);\n\n    if (!isHiRes) {\n      // Left: low-texel-density quantized lightmap showing blocky texels & chart-edge bleeding\n      float stepUV = 1.0 / max(texRes * 0.5, 2.0);\n      vec3 pQ = (floor(p / stepUV) + 0.5) * stepUV;\n      vec3 lmCoarse = bakeLightmap(pQ, n, giGain);\n      col = alb * lmCoarse;\n\n      // Texel cell borders and UV chart seam highlight\n      vec2 tf = abs(fract(lmUV / stepUV - 0.5) - 0.5);\n      float tGrid = smoothstep(0.065, 0.015, min(tf.x, tf.y));\n      col = mix(col, vec3(0.08, 0.14, 0.22), tGrid * 0.48 * min(chartVis, 1.2));\n    } else {\n      // Right: high-resolution directional baked lightmap + micro-bump normal shading\n      vec3 lmFine = bakeLightmap(p, n, giGain);\n      // Directional lightmap dominant vector adds crisp normal-map relief to static bounce\n      vec3 domDir = normalize(vec3(0.35, 0.80, 0.30));\n      float micro = sin(lmUV.x * 46.0) * sin(lmUV.y * 46.0) * 0.06;\n      vec3 bumpedN = normalize(n + vec3(micro, 0.0, -micro));\n      float dirScale = 0.78 + 0.36 * max(dot(bumpedN, domDir), 0.0);\n      col = alb * lmFine * dirScale;\n    }\n\n    // Bright skylight window opening on ceiling\n    if (p.y > 1.03 && abs(p.x + 0.15) < 0.44 && abs(p.z + 0.35) < 0.34) {\n      col = vec3(2.8, 3.2, 3.8);\n    }\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": "conceptual-diagram",
   "proof": {
    "kind": "rendered",
    "label": "rendered 2026-11-30",
    "ok": true,
    "proof": {
     "ok": true,
     "technique": "lightmap-baking",
     "runtime": "glsl-fragment",
     "checked_at": "2026-11-30T19:53:29.000Z",
     "renderer": "Headless EGL Tesla T4/PCIe/SSE2, OpenGL 3.30 Core, 512×512, iTime=1.5",
     "stats": {
      "mean": 0.5182,
      "std": 0.125,
      "min": 0.1647,
      "max": 0.9801
     },
     "image": "/specimens/lightmap-baking-live.webp",
     "reason": null
    }
   }
  }
 ],
 "related": [
  "irradiance-volumes",
  "radiosity",
  "spherical-harmonics-lighting",
  "path-tracing"
 ],
 "extends": [],
 "supersedes": [],
 "combines_with": [
  {
   "id": "irradiance-volumes",
   "why": "Volume probes baked in the same pass light dynamic objects consistently with the static lightmap."
  }
 ],
 "provenance": {
  "prose": "original text written for this index (research draft, editorially reviewed)",
  "sources_verified_at": "2026-11-29T15:51:27.588Z",
  "draft": "data/drafts/gi/lightmap-baking.json"
 },
 "solves": [
  "static scenes need free high quality gi at runtime",
  "mobile game needs precomputed lighting",
  "lighting looks flat with only direct lights",
  "bake shadows and bounce light into textures"
 ],
 "authority": "Iwanicki, 2013",
 "url": "https://texelatlas.vercel.app/t/lightmap-baking/",
 "execution_fidelity": "conceptual-diagram",
 "fidelity_label": "Visual Diagram",
 "benchmark_eligible": false,
 "gpu_weight": {
  "weight_x": 26.9,
  "tier": "heavy",
  "p50_ms": 0.8339,
  "p95_ms": 0.947,
  "baseline_p50_ms": 0.0329,
  "gpu": "Tesla T4/PCIe/SSE2",
  "resolution": "1920x1080",
  "method": "opengl-timer-query",
  "frames": 36,
  "preset_id": "lightmap-baking-live",
  "execution_fidelity": "conceptual-diagram",
  "fidelity_label": "Visual Diagram",
  "benchmark_eligible": false,
  "generated_at": "2026-11-30T21:07:47Z",
  "l4": {
   "weight_x": 27.75,
   "tier": "heavy",
   "p50_ms": 0.4413,
   "p95_ms": 0.4462,
   "speedup_x": 1.89,
   "gpu": "NVIDIA L4/PCIe/SSE2",
   "resolution": "1920x1080",
   "baseline_p50_ms": 0.0159
  },
  "a100": {
   "weight_x": 17.17,
   "tier": "moderate",
   "p50_ms": 0.4946,
   "p95_ms": 0.5023,
   "speedup_x": 1.69,
   "gpu": "NVIDIA A100-SXM4-40GB/PCIe/SSE2",
   "resolution": "1920x1080",
   "baseline_p50_ms": 0.0288
  }
 }
}