{
 "id": "least-squares-vertex-baking",
 "title": "Least-Squares Vertex Light Baking",
 "aliases": [
  "LSVB",
  "least squares vertex baking",
  "cotangent-Laplacian vertex baking",
  "UV-free vertex light baking"
 ],
 "domain": "gi",
 "subdomain": "precomputed GI & baking",
 "stage": "lighting",
 "realtime": "realtime",
 "platforms": [
  "webgl2",
  "webgpu",
  "desktop-gpu",
  "mobile-gpu",
  "cpu"
 ],
 "year_introduced": 2011,
 "inputs": [
  "mesh",
  "radiance"
 ],
 "outputs": [
  "radiance"
 ],
 "style": "both",
 "dynamic": "static",
 "summary": "Solves a sparse linear least-squares system over mesh vertices to fit area-sampled indirect lighting across every triangle, eliminating lightmap UV unwrapping and seams while regularizing undersampled regions with a cotangent Laplacian.",
 "how_it_works": "Naive per-vertex light baking evaluates irradiance only at mesh vertices, which misses narrow shadows or bright patches falling inside triangles and creates severe aliasing on irregular tessellations. **Least-Squares Vertex Baking** treats the vertex colors `x` as the degrees of freedom of a piecewise-linear finite-element function defined across the mesh by barycentric interpolation.\n\nDuring the bake, radiance or irradiance is Monte Carlo gathered at many sample points distributed over triangle interiors (combining area-weighted and per-vertex-weighted sampling so small geometric features are not starved). Each sample contributes a row to an overdetermined system `A x ≈ b`, where the three nonzero entries in the row are the sample's barycentric weights. Forming the normal equations `A^T A x = A^T b` produces a symmetric positive-definite sparse matrix whose sparsity matches the mesh edge graph.\n\nTo suppress Monte Carlo noise and stabilize sparsely sampled or sliver triangles, a small **cotangent-Laplacian** smoothness energy `λ L` is added to the normal matrix before solving via conjugate gradients or Cholesky factorization. Coplanar vertices sharing position and normal are welded, while sharp creases stay split, and oversized triangles are subdivided prior to baking so linear interpolation can capture spatial light variation.",
 "when_to_use": "Choose it for static architectural or stylized meshes when you want clean baked bounce lighting with zero UV unwrapping, zero atlas padding or seam bleeding, and minimal runtime shader cost.\n\nPrefer [lightmap-baking](lightmap-baking) when large low-poly walls or floors need high-frequency shadow detail without subdividing the mesh. Prefer [irradiance-volumes](irradiance-volumes) or [ddgi](ddgi) when dynamic characters or moving lights must receive indirect illumination. Prefer [precomputed-radiance-transfer](precomputed-radiance-transfer) when lighting direction changes dynamically on static geometry.",
 "cost": {
  "class": "cheap",
  "notes": "Runtime evaluation is a single interpolated vertex attribute with no texture fetch; offline or progressive GPU baking solves a sparse linear system over the mesh vertex count."
 },
 "failure_modes": [
  "Coarse triangles cannot represent high-frequency light or shadow gradients unless the mesh is pre-subdivided along long edges",
  "Excessive cotangent-Laplacian regularization blurs crisp contact shadows and bleeds light across thin walls if sharp creases are accidentally welded",
  "Non-manifold or obtuse sliver triangles can yield negative cotangent weights unless clamped or replaced with intrinsic/tufted Laplacians",
  "Static only: moving light sources or occluders require re-gathering samples and re-solving the linear system"
 ],
 "sources": [
  {
   "role": "primary",
   "key": "doi:10.1111/j.1467-8659.2011.01991.x",
   "type": "paper",
   "title": "Least Squares Vertex Baking",
   "authors": [
    "L. Kavan",
    "A.W. Bargteil",
    "P.‐P. Sloan"
   ],
   "year": 2011,
   "venue": "Computer Graphics Forum",
   "url": "https://doi.org/10.1111/j.1467-8659.2011.01991.x",
   "ids": {
    "doi": "10.1111/j.1467-8659.2011.01991.x"
   },
   "license": null,
   "extra": {
    "csl_type": "journal-article"
   },
   "provenance": {
    "title": {
     "authority": "doi.org",
     "endpoint": "https://doi.org/10.1111/j.1467-8659.2011.01991.x (CSL-JSON)",
     "checked_at": "2026-11-30T17:59:51.239Z"
    },
    "authors": {
     "authority": "doi.org",
     "endpoint": "https://doi.org/10.1111/j.1467-8659.2011.01991.x (CSL-JSON)",
     "checked_at": "2026-11-30T17:59:51.239Z"
    },
    "year": {
     "authority": "doi.org",
     "endpoint": "https://doi.org/10.1111/j.1467-8659.2011.01991.x (CSL-JSON)",
     "checked_at": "2026-11-30T17:59:51.239Z"
    },
    "venue": {
     "authority": "doi.org",
     "endpoint": "https://doi.org/10.1111/j.1467-8659.2011.01991.x (CSL-JSON)",
     "checked_at": "2026-11-30T17:59:51.239Z"
    },
    "url": {
     "authority": "doi.org",
     "endpoint": "https://doi.org/10.1111/j.1467-8659.2011.01991.x (CSL-JSON)",
     "checked_at": "2026-11-30T17:59:51.239Z"
    }
   },
   "status": "verified",
   "checked_at": "2026-11-30T17:59:51.239Z",
   "title_sim": 1,
   "__bib": "kavan2011least"
  },
  {
   "role": "implementation",
   "key": "gh:mrdoob/codevember-2026",
   "type": "code",
   "title": "mrdoob/codevember-2026",
   "description": "Daily creative agentic coding experiments for November 2026.",
   "authors": [
    "mrdoob"
   ],
   "year": 2026,
   "venue": "GitHub",
   "url": "https://github.com/mrdoob/codevember-2026",
   "ids": {
    "repo": "mrdoob/codevember-2026"
   },
   "license": "MIT",
   "extra": {
    "stars": 102,
    "stars_checked": "2026-11-30",
    "archived": false,
    "fork": false,
    "pushed_at": "2026-11-27T06:32:02Z",
    "language": "JavaScript",
    "homepage": "https://mrdoob.github.io/codevember-2026/",
    "license_name": "MIT License"
   },
   "provenance": {
    "title": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/mrdoob/codevember-2026",
     "checked_at": "2026-11-30T17:59:51.239Z"
    },
    "authors": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/mrdoob/codevember-2026",
     "checked_at": "2026-11-30T17:59:51.239Z"
    },
    "year": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/mrdoob/codevember-2026",
     "checked_at": "2026-11-30T17:59:51.239Z"
    },
    "venue": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/mrdoob/codevember-2026",
     "checked_at": "2026-11-30T17:59:51.239Z"
    },
    "url": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/mrdoob/codevember-2026",
     "checked_at": "2026-11-30T17:59:51.239Z"
    },
    "license": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/mrdoob/codevember-2026",
     "checked_at": "2026-11-30T17:59:51.239Z"
    }
   },
   "status": "verified",
   "checked_at": "2026-11-30T17:59:51.239Z",
   "title_sim": null,
   "__bib": "mrdoob2026mrdoob"
  }
 ],
 "presets": [
  {
   "id": "least-squares-vertex-baking-live",
   "title": "Least-Squares Vertex Baking — noisy per-triangle samples & seams (left) vs Laplacian-regularized vertex fit (right)",
   "runtime": "glsl-fragment",
   "params": {
    "P_MESH_DENSITY": 7,
    "P_LAPLACIAN_REG": 0.75,
    "P_SUN_ANGLE": 0.55,
    "P_SPLIT": 0.48
   },
   "basis": "original",
   "license_note": "MIT — written for this index.",
   "code": "const float P_MESH_DENSITY = 7.0; // P Mesh Density [4.0, 14.0, 1.0]\nconst float P_LAPLACIAN_REG = 0.75; // P Laplacian Smooth [0.0, 1.0, 0.05]\nconst float P_SUN_ANGLE = 0.55; // P Window Sun [0.0, 2.0, 0.05]\nconst float P_SPLIT = 0.48; // P Raw / LSQ Fit Split [0.0, 1.0, 0.02]\n\nfloat hash21(vec2 p) {\n  p = fract(p * vec2(127.1, 311.7));\n  p += dot(p, p + 34.5);\n  return fract(p.x * p.y);\n}\n\n// Compute analytical ground-truth multi-bounce room irradiance at surface point p with normal n\nvec3 evalTrueIrradiance(vec3 p, vec3 n, float sunT) {\n  vec3 winPos = vec3(-0.92, 0.22 + 0.16 * sin(sunT), -0.35);\n  vec3 toWin = winPos - p;\n  float dWin = max(length(toWin), 0.25);\n  vec3 lWin = toWin / dWin;\n  float winBounce = max(dot(n, lWin), 0.0) / (0.35 + dWin * dWin);\n\n  // Warm sunlit floor patch bounce + cool sky fill + terracotta right-wall bounce\n  vec3 sunSpot = vec3(0.18 + 0.35 * cos(sunT * 0.7), -0.72, -0.35);\n  float dSpot = max(length(sunSpot - p), 0.25);\n  float spotLight = max(dot(n, normalize(sunSpot - p)), 0.0) / (0.45 + dSpot * dSpot);\n  float rightWall = max(dot(n, vec3(1.0, 0.1, 0.0)), 0.0) / (0.6 + pow(1.05 - p.x, 2.0));\n\n  vec3 rad = vec3(1.55, 1.18, 0.76) * winBounce * 0.95\n           + vec3(1.35, 0.88, 0.42) * spotLight * 0.55\n           + vec3(0.24, 0.66, 0.92) * rightWall * 0.45\n           + vec3(0.16, 0.22, 0.34) * (0.5 + 0.5 * n.y);\n  return rad;\n}\n\n// Triangle mesh parameterization on any planar room surface: returns barycentric weights, 3 vertex coords, and triangle ID\nvoid evalTriMesh(vec2 uv, float dens, out vec2 v0, out vec2 v1, out vec2 v2, out vec3 bary, out vec2 triId, out float wire) {\n  vec2 g = uv * dens;\n  vec2 cell = floor(g);\n  vec2 f = fract(g);\n  if (f.x + f.y <= 1.0) {\n    v0 = cell / dens;\n    v1 = (cell + vec2(1.0, 0.0)) / dens;\n    v2 = (cell + vec2(0.0, 1.0)) / dens;\n    bary = vec3(1.0 - f.x - f.y, f.x, f.y);\n    triId = cell * 2.0;\n  } else {\n    v0 = (cell + vec2(1.0, 1.0)) / dens;\n    v1 = (cell + vec2(0.0, 1.0)) / dens;\n    v2 = (cell + vec2(1.0, 0.0)) / dens;\n    bary = vec3(f.x + f.y - 1.0, 1.0 - f.x, 1.0 - f.y);\n    triId = cell * 2.0 + vec2(1.0, 0.0);\n  }\n  float minEdge = min(bary.x, min(bary.y, bary.z));\n  wire = smoothstep(0.045, 0.012, minEdge);\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 useLSQ = sx >= split;\n\n  float dens = clamp(floor(P_MESH_DENSITY + 0.5), 3.0, 16.0);\n  float lapReg = clamp(P_LAPLACIAN_REG, 0.0, 1.0);\n  float sunT = iTime * max(P_SUN_ANGLE, 0.0);\n\n  // Camera inside an architectural room box [-1.05..1.05] x [-0.72..0.78] x [-1.45..1.5]\n  vec3 ro = vec3(0.0, 0.04, 1.62);\n  vec3 rd = normalize(vec3(uv, -1.28));\n  vec3 col = vec3(0.06, 0.08, 0.12);\n\n  // Intersect 5 room planes (floor, ceiling, back, left, right) + central plinth box\n  float tMin = 1e5;\n  vec3 hitN = vec3(0.0, 1.0, 0.0);\n  int faceId = 0;\n\n  // Floor y = -0.72\n  if (rd.y < -1e-4) {\n    float t = (-0.72 - ro.y) / rd.y;\n    if (t > 0.05 && t < tMin) { tMin = t; hitN = vec3(0.0, 1.0, 0.0); faceId = 1; }\n  }\n  // Ceiling y = 0.78\n  if (rd.y > 1e-4) {\n    float t = (0.78 - ro.y) / rd.y;\n    if (t > 0.05 && t < tMin) { tMin = t; hitN = vec3(0.0, -1.0, 0.0); faceId = 2; }\n  }\n  // Back wall z = -1.45\n  if (rd.z < -1e-4) {\n    float t = (-1.45 - ro.z) / rd.z;\n    if (t > 0.05 && t < tMin) { tMin = t; hitN = vec3(0.0, 0.0, 1.0); faceId = 3; }\n  }\n  // Left wall x = -1.05\n  if (rd.x < -1e-4) {\n    float t = (-1.05 - ro.x) / rd.x;\n    if (t > 0.05 && t < tMin) { tMin = t; hitN = vec3(1.0, 0.0, 0.0); faceId = 4; }\n  }\n  // Right wall x = 1.05\n  if (rd.x > 1e-4) {\n    float t = (1.05 - ro.x) / rd.x;\n    if (t > 0.05 && t < tMin) { tMin = t; hitN = vec3(-1.0, 0.0, 0.0); faceId = 5; }\n  }\n\n  // Central sphere pedestal\n  vec3 sphC = vec3(0.0, -0.34, -0.58);\n  vec3 oc = ro - sphC;\n  float b = dot(oc, rd);\n  float c = dot(oc, oc) - 0.36 * 0.36;\n  float disc = b * b - c;\n  if (disc > 0.0) {\n    float tS = -b - sqrt(disc);\n    if (tS > 0.05 && tS < tMin) { tMin = tS; hitN = normalize((ro + rd * tS) - sphC); faceId = 6; }\n  }\n\n  if (faceId > 0) {\n    vec3 p = ro + rd * tMin;\n    vec3 alb = vec3(0.76, 0.74, 0.70);\n    if (faceId == 4) alb = vec3(0.86, 0.42, 0.24);\n    else if (faceId == 5) alb = vec3(0.24, 0.58, 0.78);\n\n    // Bright window opening on left wall\n    bool isWin = (faceId == 4 && abs(p.y - 0.12) < 0.34 && abs(p.z + 0.42) < 0.34);\n    if (isWin) {\n      col = vec3(2.8, 2.3, 1.65);\n    } else {\n      vec2 fuv;\n      if (faceId == 1 || faceId == 2) fuv = p.xz;\n      else if (faceId == 3) fuv = p.xy;\n      else if (faceId == 4 || faceId == 5) fuv = p.zy;\n      else fuv = vec2(atan(hitN.z, hitN.x) * 0.5, acos(clamp(hitN.y, -1.0, 1.0)) * 0.5);\n\n      vec2 v0, v1, v2, triId;\n      vec3 bary;\n      float wire;\n      evalTriMesh(fuv, dens, v0, v1, v2, bary, triId, wire);\n\n      // Reconstruct 3D positions of the 3 mesh vertices\n      vec3 p0 = p, p1 = p, p2 = p;\n      if (faceId == 1 || faceId == 2) { p0 = vec3(v0.x, p.y, v0.y); p1 = vec3(v1.x, p.y, v1.y); p2 = vec3(v2.x, p.y, v2.y); }\n      else if (faceId == 3) { p0 = vec3(v0.x, v0.y, p.z); p1 = vec3(v1.x, v1.y, p.z); p2 = vec3(v2.x, v2.y, p.z); }\n      else if (faceId == 4 || faceId == 5) { p0 = vec3(p.x, v0.y, v0.x); p1 = vec3(p.x, v1.y, v1.x); p2 = vec3(p.x, v2.y, v2.x); }\n\n      if (!useLSQ) {\n        // Left: Raw noisy per-triangle Monte Carlo estimates (flat triangle blotches + sampling variance)\n        vec3 triCent = (p0 + p1 + p2) / 3.0;\n        vec3 irr = evalTrueIrradiance(triCent, hitN, sunT);\n        float noise = (hash21(triId + float(faceId) * 19.3) - 0.5) * 0.62;\n        irr = max(irr * (1.0 + noise), vec3(0.02));\n        col = alb * irr;\n        col = mix(col, vec3(0.95, 0.52, 0.22), wire * 0.35);\n      } else {\n        // Right: Least-squares vertex-fitted irradiance with cotangent Laplacian regularization -> smooth C0 barycentric interpolation!\n        vec3 i0 = evalTrueIrradiance(p0, hitN, sunT);\n        vec3 i1 = evalTrueIrradiance(p1, hitN, sunT);\n        vec3 i2 = evalTrueIrradiance(p2, hitN, sunT);\n        // Residual vertex noise damped by Laplacian regularization strength\n        float rAmp = (1.0 - lapReg) * 0.32;\n        i0 *= 1.0 + (hash21(floor(v0 * dens + 0.5) + float(faceId) * 7.1) - 0.5) * rAmp;\n        i1 *= 1.0 + (hash21(floor(v1 * dens + 0.5) + float(faceId) * 7.1) - 0.5) * rAmp;\n        i2 *= 1.0 + (hash21(floor(v2 * dens + 0.5) + float(faceId) * 7.1) - 0.5) * rAmp;\n        vec3 smoothIrr = i0 * bary.x + i1 * bary.y + i2 * bary.z;\n        col = alb * max(smoothIrr, vec3(0.02));\n        // Subtle faint cyan wireframe showing exact same triangle mesh\n        col = mix(col, vec3(0.28, 0.85, 0.95), wire * 0.14);\n      }\n    }\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": "least-squares-vertex-baking",
     "runtime": "glsl-fragment",
     "checked_at": "2026-11-30T21:07:13.000Z",
     "renderer": "Headless EGL Tesla T4/PCIe/SSE2, OpenGL 3.30 Core, 512×512, iTime=1.5",
     "stats": {
      "mean": 0.7155,
      "std": 0.1244,
      "min": 0.1025,
      "max": 0.9501
     },
     "image": "/specimens/least-squares-vertex-baking-live.webp",
     "reason": null
    }
   }
  }
 ],
 "related": [
  "lightmap-baking",
  "radiosity",
  "precomputed-radiance-transfer",
  "irradiance-volumes",
  "tufted-laplacian"
 ],
 "extends": [],
 "supersedes": [],
 "combines_with": [
  {
   "id": "three-mesh-bvh",
   "why": "Accelerates GPU ray-traced bounce gathering at triangle interior sample points before the vertex solve."
  },
  {
   "id": "path-tracing",
   "why": "Supplies unbiased multi-bounce irradiance samples over triangle interiors that the least-squares solver projects onto mesh vertices."
  }
 ],
 "provenance": {
  "prose": "original text written for this index (research draft, editorially reviewed)",
  "sources_verified_at": "2026-11-30T17:59:51.239Z",
  "draft": "data/drafts/gi/least-squares-vertex-baking.json"
 },
 "solves": [
  "want baked lighting or ao on meshes without uv unwrapping",
  "vertex colors look blotchy when point sampled at corners",
  "fit noisy path traced samples cleanly across mesh triangles",
  "bake smooth radiosity onto low poly assets without lightmap seams",
  "reduce lightmap texture memory by storing lighting per vertex"
 ],
 "authority": "Kavan et al., 2011",
 "url": "https://texelatlas.vercel.app/t/least-squares-vertex-baking/",
 "execution_fidelity": "conceptual-diagram",
 "fidelity_label": "Visual Diagram",
 "benchmark_eligible": false,
 "gpu_weight": {
  "weight_x": 5.94,
  "tier": "light",
  "p50_ms": 0.1954,
  "p95_ms": 0.2042,
  "baseline_p50_ms": 0.0329,
  "gpu": "Tesla T4/PCIe/SSE2",
  "resolution": "1920x1080",
  "method": "opengl-timer-query",
  "frames": 32,
  "preset_id": "least-squares-vertex-baking-live",
  "execution_fidelity": "conceptual-diagram",
  "fidelity_label": "Visual Diagram",
  "benchmark_eligible": false,
  "generated_at": "2026-11-30T21:07:47Z",
  "l4": {
   "weight_x": 5.43,
   "tier": "light",
   "p50_ms": 0.0864,
   "p95_ms": 0.0872,
   "speedup_x": 2.26,
   "gpu": "NVIDIA L4/PCIe/SSE2",
   "resolution": "1920x1080",
   "baseline_p50_ms": 0.0159
  },
  "a100": {
   "weight_x": 3.85,
   "tier": "light",
   "p50_ms": 0.1108,
   "p95_ms": 0.1109,
   "speedup_x": 1.76,
   "gpu": "NVIDIA A100-SXM4-40GB/PCIe/SSE2",
   "resolution": "1920x1080",
   "baseline_p50_ms": 0.0288
  }
 }
}