Texel A field guide to 3D techniques

Neural Radiance Fields (NeRF) × Lightmap Baking

Baking trained NeRF radiance fields into directional mesh lightmaps. Treating a trained NeRF volume as a directional incident-radiance oracle during UV lightmap baking distills expensive neural ray-marching into static L1/L2 spherical-harmonic lightmaps that run at 120 FPS on any WebGL2 or mobile mesh renderer.

Open in StudioReproduced104× · 3.23 ms

Neural Radiance Fields (NeRF)Capture · Offlinein: photos, camera-posesout: radiance-fieldcompositeLightmap BakingLighting · Real-timein: mesh, uv-atlas, material-paramsout: texture

Verified proof

reproduced · 2026-12-01texel-lablicense MIT
Specimen render of NeRF oracle + directional lightmap baking (left: noisy volumetric NeRF, right: baked L1 SH directional lightmap)
Cross-proof specimen. NeRF oracle + directional lightmap baking (left: noisy volumetric NeRF, right: baked L1 SH directional lightmap). Verified WebGL2 proof · 2026-12-01

Split-screen WebGL2 proof comparing noisy low-budget volumetric NeRF ray-marching with floater artifacts and milky edges (left) against a UV-unwrapped proxy mesh shaded by directional L1 spherical-harmonic lightmaps baked from the NeRF radiance oracle with crisp micro-normal response (right).

Chromium Headless ANGLE/SwiftShader WebGL2 · 512x512 · distills noisy volumetric NeRF radiance into crisp directional L1 SH mesh lightmaps free of neural floater haze

Show GLSL proof (189 lines)
const float P_SH_DIRECT = 1.15; // P L1 SH Directionality [0.3, 2.0, 0.05]
const float P_MICRO_BUMP = 0.85; // P Proxy Normal Detail [0.0, 1.5, 0.05]
const float P_UV_CHART = 0.24; // P Lightmap UV Grid [0.0, 1.0, 0.05]
const float P_FLOATER_AMT = 0.78; // P NeRF Floater Noise [0.1, 1.5, 0.05]

float hash31(vec3 p) {
  p = fract(p * 0.1031);
  p += dot(p, p.yzx + 33.33);
  return fract((p.x + p.y) * p.z);
}

float vnoise3(vec3 p) {
  vec3 i = floor(p);
  vec3 f = fract(p);
  f = f * f * (3.0 - 2.0 * f);
  return mix(
    mix(mix(hash31(i), hash31(i + vec3(1.0, 0.0, 0.0)), f.x),
        mix(hash31(i + vec3(0.0, 1.0, 0.0)), hash31(i + vec3(1.0, 1.0, 0.0)), f.x), f.y),
    mix(mix(hash31(i + vec3(0.0, 0.0, 1.0)), hash31(i + vec3(1.0, 0.0, 1.0)), f.x),
        mix(hash31(i + vec3(0.0, 1.0, 1.0)), hash31(i + vec3(1.0, 1.0, 1.0)), f.x), f.y),
    f.z
  );
}

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);
}

// Extracted coarse proxy mesh SDF: sculpted urn on a stepped plinth inside a gallery alcove
vec2 mapProxy(vec3 p) {
  // Pedestal base
  float ped = sdBox(p - vec3(0.0, -0.58, 0.0), vec3(0.46, 0.34, 0.46)) - 0.03;
  // Sculpted vessel on pedestal
  vec3 q = p - vec3(0.0, 0.16, 0.0);
  float r = 0.36 + 0.12 * sin(q.y * 5.2 + 0.4) - 0.14 * q.y * q.y;
  float urn = max(length(q.xz) - r, abs(q.y) - 0.44);
  // Alcove back wall & floor
  float floorD = p.y + 0.94;
  float wallD = p.z + 1.15;
  vec2 res = vec2(ped, 1.0);
  if (urn < res.x) res = vec2(urn, 2.0);
  if (floorD < res.x) res = vec2(floorD, 3.0);
  if (wallD < res.x) res = vec2(wallD, 3.0);
  return res;
}

vec3 calcNormal(vec3 p) {
  vec2 e = vec2(0.003, -0.003);
  return normalize(
    e.xyy * mapProxy(p + e.xyy).x +
    e.yyx * mapProxy(p + e.yyx).x +
    e.yxy * mapProxy(p + e.yxy).x +
    e.xxx * mapProxy(p + e.xxx).x
  );
}

// Trained NeRF incident radiance oracle L_i(dir, pos) emitted by warm portal (left) & cool skylight (right)
vec3 nerfOracleRadiance(vec3 pos, vec3 dir, float t) {
  vec3 portalDir = normalize(vec3(-0.78, 0.36 + 0.12 * sin(t * 0.7), 0.50));
  vec3 skyDir = normalize(vec3(0.72, 0.65, 0.25));
  vec3 rimDir = normalize(vec3(0.0, 0.25, -0.95));
  float p1 = pow(max(dot(dir, portalDir), 0.0), 3.0);
  float p2 = pow(max(dot(dir, skyDir), 0.0), 2.5);
  float p3 = pow(max(dot(dir, rimDir), 0.0), 4.0);
  float bounceWarm = clamp(0.5 - 0.5 * pos.x, 0.0, 1.0);
  vec3 c1 = vec3(2.4, 0.92, 0.48) * p1 * (0.7 + 0.5 * bounceWarm);
  vec3 c2 = vec3(0.42, 0.95, 1.75) * p2 * (1.2 - 0.4 * bounceWarm);
  vec3 c3 = vec3(0.95, 0.45, 0.85) * p3 * 0.65;
  return c1 + c2 + c3 + vec3(0.14, 0.16, 0.21);
}

// Evaluate baked directional L1 spherical-harmonic irradiance gathered from the NeRF oracle
vec3 evalBakedSHLightmap(vec3 wp, vec3 macroN, vec3 detailN, float t) {
  // Project 6 hemisphere NeRF oracle rays onto L0 + L1 directional irradiance basis
  vec3 upRef = abs(macroN.y) < 0.9 ? vec3(0.0, 1.0, 0.0) : vec3(1.0, 0.0, 0.0);
  vec3 T = normalize(cross(upRef, macroN));
  vec3 B = cross(macroN, T);
  vec3 sh0 = vec3(0.0);
  vec3 shX = vec3(0.0);
  vec3 shY = vec3(0.0);
  vec3 shZ = vec3(0.0);
  for (int i = 0; i < 6; i++) {
    float ang = float(i) * 1.0472 + 0.2;
    vec3 d = normalize(macroN * 0.65 + (T * cos(ang) + B * sin(ang)) * 0.76);
    // Self-occlusion factor against proxy mesh
    float occ = clamp(mapProxy(wp + d * 0.28).x * 4.5, 0.18, 1.0);
    vec3 rad = nerfOracleRadiance(wp, d, t) * occ;
    sh0 += rad;
    shX += rad * d.x;
    shY += rad * d.y;
    shZ += rad * d.z;
  }
  sh0 /= 6.0; shX /= 6.0; shY /= 6.0; shZ /= 6.0;
  // Reconstruct directional irradiance at fine normal-mapped detailN
  vec3 dirTerm = shX * detailN.x + shY * detailN.y + shZ * detailN.z;
  return max(vec3(0.04), sh0 * 0.62 + dirTerm * (0.95 * P_SH_DIRECT));
}

vec3 acesTone(vec3 x) {
  return clamp((x * (2.51 * x + 0.03)) / (x * (2.43 * x + 0.59) + 0.14), 0.0, 1.0);
}

void mainImage(out vec4 fragColor, in vec2 fragCoord) {
  vec2 res = max(iResolution.xy, vec2(1.0));
  vec2 uvN = fragCoord / res;
  float splitX = iMouse.z > 0.0 ? clamp(iMouse.x / res.x, 0.05, 0.95) : 0.5;
  bool useLightmap = uvN.x > splitX;

  vec2 p = (fragCoord - 0.5 * res) / res.y;
  float t = iTime;
  float camA = sin(t * 0.35) * 0.32;
  vec3 ro = vec3(sin(camA) * 2.55, 0.36, cos(camA) * 2.55);
  vec3 ta = vec3(0.0, -0.10, 0.0);
  vec3 fw = normalize(ta - ro);
  vec3 ri = normalize(cross(vec3(0.0, 1.0, 0.0), fw));
  vec3 up = cross(fw, ri);
  vec3 rd = normalize(fw * 1.65 + ri * p.x + up * p.y);

  vec3 col = vec3(0.06, 0.08, 0.12);

  if (!useLightmap) {
    // Left baseline: noisy low-budget volumetric NeRF integration with density floaters and soft edges
    float trans = 1.0;
    vec3 accum = vec3(0.0);
    float jitter = hash31(vec3(fragCoord, floor(t * 8.0))) * 0.08;
    for (int i = 0; i < 42; i++) {
      float dist = 0.85 + float(i) * 0.095 + jitter;
      vec3 q = ro + rd * dist;
      vec2 h = mapProxy(q);
      // Soft volumetric NeRF density ramp + spurious floating haze clouds
      float surfSigma = exp(-max(h.x, 0.0) * 18.0) * (h.x < 0.08 ? 4.2 : 0.0);
      float floater = smoothstep(0.70, 0.92, vnoise3(q * 3.8 + vec3(0.0, 0.4, 1.2))) * 0.42 * P_FLOATER_AMT;
      float sigma = surfSigma + floater;
      if (sigma > 0.01) {
        vec3 alb = h.y < 1.5 ? vec3(0.55, 0.52, 0.48) : (h.y < 2.5 ? vec3(0.68, 0.60, 0.52) : vec3(0.36, 0.38, 0.42));
        vec3 nEst = calcNormal(q);
        vec3 rad = nerfOracleRadiance(q, nEst, t) * 0.58 + vec3(0.18, 0.16, 0.22) * floater;
        float a = 1.0 - exp(-sigma * 0.095);
        accum += trans * a * alb * rad;
        trans *= (1.0 - a);
        if (trans < 0.03) break;
      }
    }
    col = accum + col * trans;
  } else {
    // Right: clean UV-unwrapped proxy mesh rendered at 120 FPS with baked L1 SH directional lightmap
    float d = 0.0;
    float mat = -1.0;
    for (int i = 0; i < 64; i++) {
      vec2 h = mapProxy(ro + rd * d);
      if (h.x < 0.002) { mat = h.y; break; }
      d += h.x;
      if (d > 9.0) break;
    }
    if (mat > 0.0) {
      vec3 wp = ro + rd * d;
      vec3 macroN = calcNormal(wp);
      // High-frequency carved flutes & stone micro-relief normal map driven by L1 SH lightmap
      float ang = atan(wp.z, wp.x);
      float fluteG = cos(ang * 18.0) * 0.26 * (mat > 1.5 && mat < 2.5 ? 1.0 : 0.0);
      float stoneG = (vnoise3(wp * 24.0) - 0.5) * 0.35;
      vec3 upRef = abs(macroN.y) < 0.9 ? vec3(0.0, 1.0, 0.0) : vec3(1.0, 0.0, 0.0);
      vec3 T = normalize(cross(upRef, macroN));
      vec3 B = cross(macroN, T);
      vec3 detailN = normalize(macroN + (T * (fluteG + stoneG) + B * stoneG * 0.7) * P_MICRO_BUMP);

      vec3 alb = mat < 1.5 ? vec3(0.56, 0.53, 0.49) : (mat < 2.5 ? vec3(0.72, 0.63, 0.53) : vec3(0.38, 0.40, 0.44));
      vec3 irr = evalBakedSHLightmap(wp, macroN, detailN, t);
      // Crisp specular highlight derived from dominant L1 SH direction
      vec3 V = -rd;
      vec3 domL = normalize(vec3(-0.35, 0.75, 0.55));
      float spec = pow(max(dot(detailN, normalize(domL + V)), 0.0), 48.0) * 0.38;
      col = alb * irr + vec3(1.0, 0.94, 0.88) * spec;

      // Optional UV lightmap chart texel overlay
      if (P_UV_CHART > 0.01) {
        vec2 uvChart = mat > 1.5 && mat < 2.5 ? vec2(ang * 1.9, wp.y * 6.0) : wp.xz * 4.5 + wp.xy * 2.5;
        vec2 gf = abs(fract(uvChart) - 0.5);
        float grid = smoothstep(0.44, 0.49, max(gf.x, gf.y));
        col = mix(col, vec3(0.32, 0.90, 0.82), grid * P_UV_CHART * 0.55);
      }
    }
  }

  col = acesTone(col * 1.08);
  if (abs(fragCoord.x - splitX * res.x) < 1.0) col = vec3(0.95, 0.93, 0.89);
  fragColor = vec4(pow(clamp(col, 0.0, 1.0), vec3(1.0 / 2.2)), 1.0);
}

Why they connect

Neural Radiance Fields (NeRF) represents a captured 3D environment as a continuous volumetric radiance-field mapping (position, view-direction) to color and density. The hop to Lightmap Baking is composite: extract a coarse UV-unwrapped proxy mesh from the NeRF's 0.5-transmittance iso-surface, rasterize every UV texel to world-space position and surface normal, and evaluate hemisphere rays directly through the NeRF radiance field (instead of a traditional mesh path tracer). Lightmap Baking projects the gathered neural radiance into directional irradiance textures (e.g., HL2 radiosity normal mapping or L1 spherical harmonics) with gutter dilation for artifact-free mipmapping.

How to build it

From a trained NeRF (or analytical neural radiance field in a standalone browser specimen), extract and UV-pack a low-poly proxy mesh. For each occupied lightmap texel (p, n), cast 32-64 cosine-weighted hemisphere rays r(t) = p + (eps + t) * d through the NeRF volume, integrating volumetric emission + transmittance to obtain incoming radiance L_i(d). Project L_i(d) onto L1 spherical-harmonic basis coefficients (or 3 Half-Life 2 directional basis vectors), dilate occupied texels by 4-8 pixels across chart boundaries to prevent UV seam bleeding, and apply a joint bilateral normal-aware denoiser. At runtime, render the lightweight textured proxy mesh with zero neural inference cost.

Field marks

  1. NeRF radiance fields encode view-dependent specular highlights tightly coupled to original camera angles, which average into milky sheen when projected onto low-order diffuse SH lightmaps.
  2. Small geometric offsets between the coarse proxy mesh and the true NeRF high-density surface cause self-occlusion darkening unless ray origins step outward by a normal bias eps.
  3. Floater density clouds inside the trained NeRF cast phantom dark blotches onto baked lightmap texels.
  4. UV chart seams show color discontinuities across high-curvature areas unless seam dilation and conservative rasterization are applied during texel baking.

Prior art

No prior art found on 2026-12-01.

Searches run (2)
  • arXiv: all:"NeRF" AND all:"lightmap"
  • GitHub repos: "nerf" "lightmap baking"