---
id: "lightmap-baking"
title: "Lightmap Baking"
aliases: [baked GI, precomputed lighting, lightmapping]
domain: "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"
cost: "cheap"
authority: "Iwanicki, 2013"
url: "https://texelatlas.vercel.app/t/lightmap-baking/"
sources_verified_at: "2026-11-29"
---
# Lightmap Baking (Iwanicki, 2013)

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

## Reach for it when

- 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

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

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

The baker is the offline system; the runtime cost is one texture fetch per pixel.

## When to use it

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.

Prefer [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

cheap — Runtime cost is a texture fetch; bake time ranges from minutes to hours depending on resolution and sample count. Memory grows with atlas resolution.
Measured GPU Weight: 26.9× baseline (heavy) — 0.8339 ms median / 0.947 ms p95 on Tesla T4/PCIe/SSE2 @ 1920x1080 (opengl-timer-query).
Ada L4 scaling: 27.75× baseline (heavy) — 0.4413 ms median (1.89× faster on L4).
Ampere A100 scaling: 17.17× baseline (moderate) — 0.4946 ms median (1.69× faster on A100).

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

## Engine support

- blender: builtin — `Properties > Render > Bake (Cycles), Bake button` (evidence: https://docs.blender.org/manual/en/5.2/render/cycles/baking.html, checked 2026-12-01)
- godot: builtin — `Add a LightmapGI node and bake (LightmapGI.bake())` (evidence: https://github.com/godotengine/godot/blob/4.7.2-stable/doc/classes/LightmapGI.xml, checked 2026-12-01) — GPU lightmapper (LightmapperRD) bakes lightmaps with denoising.
- threejs: official — `import { LightMapper } from 'three/addons/lighting/LightMapper.js'` (evidence: https://github.com/mrdoob/three.js/blob/r187/examples/jsm/lighting/LightMapper.js, checked 2026-12-01) — WebGPURenderer only.
- unity: builtin — `Window > Rendering > Lighting > Lightmapping Settings > Progressive GPU/CPU` (evidence: https://docs.unity3d.com/6000.0/Documentation/Manual/progressive-lightmapper.html, checked 2026-12-01) — Progressive Lightmapper (CPU/GPU) in URP and HDRP.
- unreal: official — `Enable the GPU Lightmass plugin; World Settings > Lightmass; build lighting with GPU Lightmass (or built-in CPU Lightmass)` (evidence: https://dev.epicgames.com/documentation/en-us/unreal-engine/gpu-lightmass-global-illumination-in-unreal-engine, checked 2026-12-01)

## Dataflow

- Inputs: mesh, uv-atlas, material-params
- Outputs: texture
- Platforms: webgl2, webgpu, desktop-gpu, mobile-gpu, unity, unreal, godot, blender

## Presets

### Lightmap Baking — coarse UV-chart texels & seams (left) vs high-res directional baked lightmap (right) (glsl-fragment; rendered 2026-11-30)

```json
{
  "P_TEXEL_RES": 10,
  "P_BOUNCE_INT": 1.25,
  "P_CHART_VIS": 0.75,
  "P_SPLIT": 0.48
}
```

```glsl
const float P_TEXEL_RES = 10.0; // P Low-Res Texels [4.0, 20.0, 1.0]
const float P_BOUNCE_INT = 1.25; // P Baked GI Gain [0.3, 2.2, 0.05]
const float P_CHART_VIS = 0.75; // P UV Chart Grid [0.0, 1.5, 0.05]
const float P_SPLIT = 0.48; // P Coarse / Fine Split [0.0, 1.0, 0.02]

float sdBox(vec3 p, vec3 b) {
  vec3 q = abs(p) - b;
  return length(max(q, 0.0)) + min(max(q.x, max(q.y, q.z)), 0.0);
}

// Sunlit architectural gallery with skylight aperture and sculpted bench + archway
vec2 mapScene(vec3 p) {
  vec2 res = vec2(p.y + 0.85, 1.0);
  float dC = 1.05 - p.y; if (dC < res.x) res = vec2(dC, 1.0);
  float dB = p.z + 1.45; if (dB < res.x) res = vec2(dB, 2.0);
  float dL = p.x + 1.35; if (dL < res.x) res = vec2(dL, 3.0);
  float dR = 1.35 - p.x; if (dR < res.x) res = vec2(dR, 4.0);

  float dBench = sdBox(p - vec3(-0.35, -0.58, -0.35), vec3(0.42, 0.27, 0.24)) - 0.02;
  if (dBench < res.x) res = vec2(dBench, 5.0);
  float dPed = sdBox(p - vec3(0.55, -0.45, -0.55), vec3(0.24, 0.40, 0.24)) - 0.02;
  if (dPed < res.x) res = vec2(dPed, 5.0);
  float dSph = length(p - vec3(0.55, 0.14, -0.55)) - 0.22;
  if (dSph < res.x) res = vec2(dSph, 6.0);
  return res;
}

vec3 calcNormal(vec3 p) {
  vec2 e = vec2(0.0022, 0.0);
  return normalize(vec3(
    mapScene(p + e.xyy).x - mapScene(p - e.xyy).x,
    mapScene(p + e.yxy).x - mapScene(p - e.yxy).x,
    mapScene(p + e.yyx).x - mapScene(p - e.yyx).x
  ));
}

// Evaluate precomputed static lightmap irradiance at UV-mapped surface point p
vec3 bakeLightmap(vec3 p, vec3 n, float giGain) {
  // Warm angled skylight beam hitting floor & bench + soft indirect bounce
  vec3 sunDir = normalize(vec3(0.45, 0.82, 0.35));
  float tPlane = (1.05 - p.y) / sunDir.y;
  vec2 skyHit = p.xz + sunDir.xz * tPlane;
  float inBeam = smoothstep(0.52, 0.34, abs(skyHit.x + 0.15)) * smoothstep(0.42, 0.26, abs(skyHit.y + 0.35));
  float ndl = max(dot(n, sunDir), 0.0);

  // Soft shadow occlusion inside baked pass
  float sh = 1.0;
  float ts = 0.04;
  for (int i = 0; i < 16; i++) {
    float d = mapScene(p + sunDir * ts).x;
    sh = min(sh, 5.5 * d / max(ts, 0.04));
    ts += clamp(d, 0.03, 0.20);
    if (sh < 0.05 || ts > 2.2) break;
  }
  vec3 sunDirect = vec3(2.4, 2.05, 1.55) * ndl * inBeam * clamp(sh, 0.0, 1.0);

  // Multi-bounce color bleed from sunlit warm terracotta floor patch & cool sky fill
  float floorBounce = exp(-length(p - vec3(-0.35, -0.85, -0.45)) * 0.95);
  vec3 indirect = vec3(0.92, 0.56, 0.26) * floorBounce * 0.72;
  indirect += vec3(0.28, 0.46, 0.74) * (0.45 + 0.55 * max(n.y, 0.0)) * 0.48;
  float ao = clamp(0.35 + 0.65 * mapScene(p + n * 0.26).x / 0.26, 0.16, 1.0);
  return sunDirect + indirect * giGain * ao;
}

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 isHiRes = screenX >= split;
  float texRes = clamp(floor(P_TEXEL_RES + 0.5), 4.0, 22.0);
  float giGain = clamp(P_BOUNCE_INT, 0.2, 2.4);
  float chartVis = clamp(P_CHART_VIS, 0.0, 1.5);

  float camAng = 0.14 * sin(iTime * 0.42);
  vec3 ro = vec3(0.32 * sin(camAng), 0.06, 2.38);
  vec3 rd = normalize(vec3(uv, -1.52));

  vec3 col = vec3(0.03);
  float t = 0.0;
  float matId = 0.0;
  bool hit = false;
  for (int i = 0; i < 64; i++) {
    vec2 h = mapScene(ro + rd * t);
    if (h.x < 0.002) { hit = true; matId = h.y; break; }
    t += h.x;
    if (t > 9.0) break;
  }

  if (hit) {
    vec3 p = ro + rd * t;
    vec3 n = calcNormal(p);

    // Triplanar non-overlapping UV2 chart coordinates per surface orientation
    vec3 an = abs(n);
    vec2 lmUV = (an.x > an.y && an.x > an.z) ? p.yz : ((an.y > an.z) ? p.xz : p.xy);

    vec3 alb = vec3(0.76, 0.74, 0.70);
    if (matId > 2.5 && matId < 3.5) alb = vec3(0.84, 0.44, 0.26);
    if (matId > 3.5 && matId < 4.5) alb = vec3(0.32, 0.56, 0.70);
    if (matId > 5.5) alb = vec3(0.88, 0.82, 0.68);

    if (!isHiRes) {
      // Left: low-texel-density quantized lightmap showing blocky texels & chart-edge bleeding
      float stepUV = 1.0 / max(texRes * 0.5, 2.0);
      vec3 pQ = (floor(p / stepUV) + 0.5) * stepUV;
      vec3 lmCoarse = bakeLightmap(pQ, n, giGain);
      col = alb * lmCoarse;

      // Texel cell borders and UV chart seam highlight
      vec2 tf = abs(fract(lmUV / stepUV - 0.5) - 0.5);
      float tGrid = smoothstep(0.065, 0.015, min(tf.x, tf.y));
      col = mix(col, vec3(0.08, 0.14, 0.22), tGrid * 0.48 * min(chartVis, 1.2));
    } else {
      // Right: high-resolution directional baked lightmap + micro-bump normal shading
      vec3 lmFine = bakeLightmap(p, n, giGain);
      // Directional lightmap dominant vector adds crisp normal-map relief to static bounce
      vec3 domDir = normalize(vec3(0.35, 0.80, 0.30));
      float micro = sin(lmUV.x * 46.0) * sin(lmUV.y * 46.0) * 0.06;
      vec3 bumpedN = normalize(n + vec3(micro, 0.0, -micro));
      float dirScale = 0.78 + 0.36 * max(dot(bumpedN, domDir), 0.0);
      col = alb * lmFine * dirScale;
    }

    // Bright skylight window opening on ceiling
    if (p.y > 1.03 && abs(p.x + 0.15) < 0.44 && abs(p.z + 0.35) < 0.34) {
      col = vec3(2.8, 3.2, 3.8);
    }
  }

  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.

## Combines with

- [Irradiance Volumes and Light Probes](https://texelatlas.vercel.app/t/irradiance-volumes.md): Volume probes baked in the same pass light dynamic objects consistently with the static lightmap.

## Combination ideas

- [Baking trained NeRF radiance fields into directional mesh lightmaps](https://texelatlas.vercel.app/ideas/nerf-oracle-lightmap-baking/)
- [Neural-compressed directional lightmaps](https://texelatlas.vercel.app/ideas/neural-compressed-lightmaps/)

## Sources

1. [primary] Michal Iwanicki (2013) Lighting technology of the last of us. ACM SIGGRAPH 2013 Talks. https://doi.org/10.1145/2504459.2504484 (verified via crossref on 2026-11-29)
2. [implementation] ands (2016) ands/lightmapper. https://github.com/ands/lightmapper (verified via github on 2026-11-29)

## Cite this entry

Texel. "Lightmap Baking." https://texelatlas.vercel.app/t/lightmap-baking/ (accessed 2026-12-01).
