Least-Squares Vertex Light Baking
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.
Also known as LSVB, least squares vertex baking, cotangent-Laplacian vertex baking, UV-free vertex light baking
In the family Light transport & global illumination, precomputed GI & baking
Where it runs
Built inOfficial add-onPluginNone foundNot researched
| Engine | Support | How |
|---|---|---|
| three.js r187 | None found | No built-in least-squares per-vertex lightmap baker. |
| Babylon.js 9.38.0 | None found | |
| Godot 4.7 | None found | |
| Unity | None found | Progressive Lightmapper bakes UV lightmaps and Adaptive Probe Volumes rather than least-squares per-vertex lighting. |
| Unreal 5.7 | None found | |
| Blender 5.2 | None found | |
| WebGPU W3C | None found | |
| Metal | None found |
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.
During 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.
To 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 choose it
Reach for it when
- 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
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.
Prefer Lightmap Baking when large low-poly walls or floors need high-frequency shadow detail without subdividing the mesh. Prefer Irradiance Volumes and Light Probes or Dynamic Diffuse Global Illumination (DDGI) when dynamic characters or moving lights must receive indirect illumination. Prefer Precomputed Radiance Transfer when lighting direction changes dynamically on static geometry.
Field marks
- 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
Presets
Least-Squares Vertex Baking — noisy per-triangle samples & seams (left) vs Laplacian-regularized vertex fit (right)
{
"P_MESH_DENSITY": 7,
"P_LAPLACIAN_REG": 0.75,
"P_SUN_ANGLE": 0.55,
"P_SPLIT": 0.48
}Show GLSL (174 lines)
const float P_MESH_DENSITY = 7.0; // P Mesh Density [4.0, 14.0, 1.0]
const float P_LAPLACIAN_REG = 0.75; // P Laplacian Smooth [0.0, 1.0, 0.05]
const float P_SUN_ANGLE = 0.55; // P Window Sun [0.0, 2.0, 0.05]
const float P_SPLIT = 0.48; // P Raw / LSQ Fit Split [0.0, 1.0, 0.02]
float hash21(vec2 p) {
p = fract(p * vec2(127.1, 311.7));
p += dot(p, p + 34.5);
return fract(p.x * p.y);
}
// Compute analytical ground-truth multi-bounce room irradiance at surface point p with normal n
vec3 evalTrueIrradiance(vec3 p, vec3 n, float sunT) {
vec3 winPos = vec3(-0.92, 0.22 + 0.16 * sin(sunT), -0.35);
vec3 toWin = winPos - p;
float dWin = max(length(toWin), 0.25);
vec3 lWin = toWin / dWin;
float winBounce = max(dot(n, lWin), 0.0) / (0.35 + dWin * dWin);
// Warm sunlit floor patch bounce + cool sky fill + terracotta right-wall bounce
vec3 sunSpot = vec3(0.18 + 0.35 * cos(sunT * 0.7), -0.72, -0.35);
float dSpot = max(length(sunSpot - p), 0.25);
float spotLight = max(dot(n, normalize(sunSpot - p)), 0.0) / (0.45 + dSpot * dSpot);
float rightWall = max(dot(n, vec3(1.0, 0.1, 0.0)), 0.0) / (0.6 + pow(1.05 - p.x, 2.0));
vec3 rad = vec3(1.55, 1.18, 0.76) * winBounce * 0.95
+ vec3(1.35, 0.88, 0.42) * spotLight * 0.55
+ vec3(0.24, 0.66, 0.92) * rightWall * 0.45
+ vec3(0.16, 0.22, 0.34) * (0.5 + 0.5 * n.y);
return rad;
}
// Triangle mesh parameterization on any planar room surface: returns barycentric weights, 3 vertex coords, and triangle ID
void evalTriMesh(vec2 uv, float dens, out vec2 v0, out vec2 v1, out vec2 v2, out vec3 bary, out vec2 triId, out float wire) {
vec2 g = uv * dens;
vec2 cell = floor(g);
vec2 f = fract(g);
if (f.x + f.y <= 1.0) {
v0 = cell / dens;
v1 = (cell + vec2(1.0, 0.0)) / dens;
v2 = (cell + vec2(0.0, 1.0)) / dens;
bary = vec3(1.0 - f.x - f.y, f.x, f.y);
triId = cell * 2.0;
} else {
v0 = (cell + vec2(1.0, 1.0)) / dens;
v1 = (cell + vec2(0.0, 1.0)) / dens;
v2 = (cell + vec2(1.0, 0.0)) / dens;
bary = vec3(f.x + f.y - 1.0, 1.0 - f.x, 1.0 - f.y);
triId = cell * 2.0 + vec2(1.0, 0.0);
}
float minEdge = min(bary.x, min(bary.y, bary.z));
wire = smoothstep(0.045, 0.012, minEdge);
}
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 sx = fragCoord.x / max(iResolution.x, 1.0);
float split = clamp(P_SPLIT, 0.0, 1.0);
bool useLSQ = sx >= split;
float dens = clamp(floor(P_MESH_DENSITY + 0.5), 3.0, 16.0);
float lapReg = clamp(P_LAPLACIAN_REG, 0.0, 1.0);
float sunT = iTime * max(P_SUN_ANGLE, 0.0);
// Camera inside an architectural room box [-1.05..1.05] x [-0.72..0.78] x [-1.45..1.5]
vec3 ro = vec3(0.0, 0.04, 1.62);
vec3 rd = normalize(vec3(uv, -1.28));
vec3 col = vec3(0.06, 0.08, 0.12);
// Intersect 5 room planes (floor, ceiling, back, left, right) + central plinth box
float tMin = 1e5;
vec3 hitN = vec3(0.0, 1.0, 0.0);
int faceId = 0;
// Floor y = -0.72
if (rd.y < -1e-4) {
float t = (-0.72 - ro.y) / rd.y;
if (t > 0.05 && t < tMin) { tMin = t; hitN = vec3(0.0, 1.0, 0.0); faceId = 1; }
}
// Ceiling y = 0.78
if (rd.y > 1e-4) {
float t = (0.78 - ro.y) / rd.y;
if (t > 0.05 && t < tMin) { tMin = t; hitN = vec3(0.0, -1.0, 0.0); faceId = 2; }
}
// Back wall z = -1.45
if (rd.z < -1e-4) {
float t = (-1.45 - ro.z) / rd.z;
if (t > 0.05 && t < tMin) { tMin = t; hitN = vec3(0.0, 0.0, 1.0); faceId = 3; }
}
// Left wall x = -1.05
if (rd.x < -1e-4) {
float t = (-1.05 - ro.x) / rd.x;
if (t > 0.05 && t < tMin) { tMin = t; hitN = vec3(1.0, 0.0, 0.0); faceId = 4; }
}
// Right wall x = 1.05
if (rd.x > 1e-4) {
float t = (1.05 - ro.x) / rd.x;
if (t > 0.05 && t < tMin) { tMin = t; hitN = vec3(-1.0, 0.0, 0.0); faceId = 5; }
}
// Central sphere pedestal
vec3 sphC = vec3(0.0, -0.34, -0.58);
vec3 oc = ro - sphC;
float b = dot(oc, rd);
float c = dot(oc, oc) - 0.36 * 0.36;
float disc = b * b - c;
if (disc > 0.0) {
float tS = -b - sqrt(disc);
if (tS > 0.05 && tS < tMin) { tMin = tS; hitN = normalize((ro + rd * tS) - sphC); faceId = 6; }
}
if (faceId > 0) {
vec3 p = ro + rd * tMin;
vec3 alb = vec3(0.76, 0.74, 0.70);
if (faceId == 4) alb = vec3(0.86, 0.42, 0.24);
else if (faceId == 5) alb = vec3(0.24, 0.58, 0.78);
// Bright window opening on left wall
bool isWin = (faceId == 4 && abs(p.y - 0.12) < 0.34 && abs(p.z + 0.42) < 0.34);
if (isWin) {
col = vec3(2.8, 2.3, 1.65);
} else {
vec2 fuv;
if (faceId == 1 || faceId == 2) fuv = p.xz;
else if (faceId == 3) fuv = p.xy;
else if (faceId == 4 || faceId == 5) fuv = p.zy;
else fuv = vec2(atan(hitN.z, hitN.x) * 0.5, acos(clamp(hitN.y, -1.0, 1.0)) * 0.5);
vec2 v0, v1, v2, triId;
vec3 bary;
float wire;
evalTriMesh(fuv, dens, v0, v1, v2, bary, triId, wire);
// Reconstruct 3D positions of the 3 mesh vertices
vec3 p0 = p, p1 = p, p2 = p;
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); }
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); }
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); }
if (!useLSQ) {
// Left: Raw noisy per-triangle Monte Carlo estimates (flat triangle blotches + sampling variance)
vec3 triCent = (p0 + p1 + p2) / 3.0;
vec3 irr = evalTrueIrradiance(triCent, hitN, sunT);
float noise = (hash21(triId + float(faceId) * 19.3) - 0.5) * 0.62;
irr = max(irr * (1.0 + noise), vec3(0.02));
col = alb * irr;
col = mix(col, vec3(0.95, 0.52, 0.22), wire * 0.35);
} else {
// Right: Least-squares vertex-fitted irradiance with cotangent Laplacian regularization -> smooth C0 barycentric interpolation!
vec3 i0 = evalTrueIrradiance(p0, hitN, sunT);
vec3 i1 = evalTrueIrradiance(p1, hitN, sunT);
vec3 i2 = evalTrueIrradiance(p2, hitN, sunT);
// Residual vertex noise damped by Laplacian regularization strength
float rAmp = (1.0 - lapReg) * 0.32;
i0 *= 1.0 + (hash21(floor(v0 * dens + 0.5) + float(faceId) * 7.1) - 0.5) * rAmp;
i1 *= 1.0 + (hash21(floor(v1 * dens + 0.5) + float(faceId) * 7.1) - 0.5) * rAmp;
i2 *= 1.0 + (hash21(floor(v2 * dens + 0.5) + float(faceId) * 7.1) - 0.5) * rAmp;
vec3 smoothIrr = i0 * bary.x + i1 * bary.y + i2 * bary.z;
col = alb * max(smoothIrr, vec3(0.02));
// Subtle faint cyan wireframe showing exact same triangle mesh
col = mix(col, vec3(0.28, 0.85, 0.95), wire * 0.14);
}
}
}
float sep = smoothstep(0.0035, 0.0008, abs(sx - 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.
Measured GPU weight & timing
| Preset | GPU | Weight / p50 / p95 | Method |
|---|---|---|---|
| least-squares-vertex-baking-live | Tesla T4 1920x1080 | 5.94× baseline (light) · 0.195 ms / 0.204 ms | opengl-timer-query · 32 frames · GPU Weight Atlas · Colab T4 sweep |
| least-squares-vertex-baking-live | NVIDIA L4 1920x1080 | 5.43× baseline (light) · 0.086 ms / 0.087 ms · 2.3× faster on L4 | opengl-timer-query · Cross-architecture validation |
| least-squares-vertex-baking-live | NVIDIA A100-SXM4-40GB 1920x1080 | 3.85× baseline (light) · 0.111 ms / 0.111 ms · 1.8× faster on A100 | opengl-timer-query · Cross-architecture validation |
Lineage
From the citation graph (Crossref reference lists): its primary source cites Precomputed Radiance Transfer.
Crosses
- three-mesh-bvh: Accelerates GPU ray-traced bounce gathering at triangle interior sample points before the vertex solve.
- Unidirectional Path Tracing: Supplies unbiased multi-bounce irradiance samples over triangle interiors that the least-squares solver projects onto mesh vertices.
Sources
- primaryL. Kavan, A.W. Bargteil, P.‐P. Sloan (2011). Least Squares Vertex Baking. Computer Graphics Forum.Verified via doi.org · 2026-11-30doi:10.1111/j.1467-8659.2011.01991.x
- implementationmrdoob (2026). mrdoob/codevember-2026. Daily creative agentic coding experiments for November 2026.GitHub API · license MIT · 2026-11-30