{
 "id": "light-bvh-many-lights",
 "title": "Light BVH and Adaptive Tree Splitting",
 "aliases": [
  "light tree",
  "many-light importance sampling"
 ],
 "domain": "gi",
 "subdomain": "many-light sampling",
 "stage": "lighting",
 "realtime": "offline",
 "platforms": [
  "cpu",
  "cuda"
 ],
 "year_introduced": 2018,
 "inputs": [
  "mesh",
  "material-params"
 ],
 "outputs": [
  "radiance"
 ],
 "style": "photoreal",
 "dynamic": "both",
 "summary": "Organizes emitters into a bounding-volume hierarchy with per-node energy and orientation bounds, then samples a light by descending the tree with probabilities proportional to estimated contribution at the shading point.",
 "how_it_works": "Choosing a light uniformly is hopeless with tens of thousands of emitters, and power-based choice ignores distance. A **light BVH** is built over the emitters. Each node stores total power, a spatial bound and an orientation cone bound for one-sided emitters.\n\nTo sample a light for a shading point `x`, you walk from the root. At each node you compute an **importance** for each child using conservative bounds: power times the geometric term from the minimum distance to the bound and the cone angle factors relative to the surface normal. You choose a child with probability proportional to its importance and continue down to a leaf, accumulating the pdf along the way. The pdf for MIS is computed from the same walk.\n\n**Adaptive tree splitting** (Conty and Kulla) takes several samples per shading point and, when a node has similar importance in all children and the samples-per-node budget allows, splits the samples among both children instead of picking one. Near the tree top this stratifies samples and noticeably lowers variance.",
 "when_to_use": "Choose it for offline or interactive path tracers with many emissive triangles, light-emitting meshes, or large sets of point lights, as the sampling backbone with next-event estimation.\n\nPrefer [lightcuts](lightcuts) when you want error-bounded deterministic clustering instead of stochastic sampling. Prefer [restir-di](restir-di) for real-time budgets with dynamic lights. Prefer plain power sampling with [multiple-importance-sampling](multiple-importance-sampling) when you have a few lights.",
 "cost": {
  "class": "offline",
  "notes": "Tree traversal costs a few dozen node evaluations per light sample; build cost is small and rebuilds are fast for animation."
 },
 "failure_modes": [
  "Bounds are conservative, so importance for nearby shading points inside a cluster is poor and noise remains",
  "Needs special handling for lights on both sides of the surface plane or very large emitters",
  "Importance ignores visibility, so heavily occluded lights are over-sampled",
  "Orientation cones are weak for omnidirectional and spherical lights"
 ],
 "sources": [
  {
   "role": "primary",
   "key": "doi:10.1145/3233305",
   "type": "paper",
   "title": "Importance Sampling of Many Lights with Adaptive Tree Splitting",
   "authors": [
    "Alejandro Conty Estevez",
    "Christopher Kulla"
   ],
   "year": 2018,
   "venue": "Proceedings of the ACM on Computer Graphics and Interactive Techniques",
   "url": "https://doi.org/10.1145/3233305",
   "ids": {
    "doi": "10.1145/3233305"
   },
   "license": null,
   "extra": {
    "csl_type": "journal-article"
   },
   "provenance": {
    "title": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1145/3233305",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "authors": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1145/3233305",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "year": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1145/3233305",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "venue": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1145/3233305",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "url": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1145/3233305",
     "checked_at": "2026-11-29T15:51:27.588Z"
    }
   },
   "status": "verified",
   "checked_at": "2026-11-29T15:51:27.588Z",
   "title_sim": 1,
   "__bib": "estevez2018importance"
  },
  {
   "role": "implementation",
   "key": "gh:mmp/pbrt-v4",
   "type": "code",
   "title": "mmp/pbrt-v4",
   "description": "Source code to pbrt, the ray tracer described in the forthcoming 4th edition of the \"Physically Based Rendering: From Theory to Implementation\" book.",
   "authors": [
    "mmp"
   ],
   "year": 2017,
   "venue": "GitHub",
   "url": "https://github.com/mmp/pbrt-v4",
   "ids": {
    "repo": "mmp/pbrt-v4"
   },
   "license": "Apache-2.0",
   "extra": {
    "stars": 3761,
    "stars_checked": "2026-11-29",
    "archived": false,
    "fork": false,
    "pushed_at": "2026-11-15T22:47:49Z",
    "language": "C++",
    "homepage": "https://pbrt.org",
    "license_name": "Apache License 2.0"
   },
   "provenance": {
    "title": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/mmp/pbrt-v4",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "authors": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/mmp/pbrt-v4",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "year": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/mmp/pbrt-v4",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "venue": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/mmp/pbrt-v4",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "url": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/mmp/pbrt-v4",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "license": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/mmp/pbrt-v4",
     "checked_at": "2026-11-29T15:51:27.588Z"
    }
   },
   "status": "verified",
   "checked_at": "2026-11-29T15:51:27.588Z",
   "title_sim": null,
   "__bib": "mmp2017pbrt"
  }
 ],
 "presets": [
  {
   "id": "light-bvh-many-lights-live",
   "title": "Light BVH Many-Light Sampling — noisy uniform light picking (left) vs energy-cone BVH importance sampling (right)",
   "runtime": "glsl-fragment",
   "params": {
    "P_LIGHT_COUNT": 24,
    "P_CONE_SHARP": 1.1,
    "P_ANIM_SPEED": 0.45,
    "P_SPLIT": 0.48
   },
   "basis": "original",
   "license_note": "MIT — written for this index.",
   "code": "const float P_LIGHT_COUNT = 24.0; // P Emitter Count [8.0, 32.0, 4.0]\nconst float P_CONE_SHARP = 1.10; // P Orientation Bound [0.2, 2.0, 0.1]\nconst float P_ANIM_SPEED = 0.45; // P Cluster Drift [0.0, 1.5, 0.05]\nconst float P_SPLIT = 0.48; // P Uniform / BVH 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// 32 procedural point emitters organized in 4 spatial BVH clusters (amber, cyan, magenta, emerald)\nvoid getLight(int idx, float t, out vec3 pos, out vec3 col) {\n  int cl = idx / 8;\n  float fi = float(idx - cl * 8);\n  float ang = fi * 0.785398 + t * (0.4 + 0.15 * float(cl));\n  vec3 cPos;\n  if (cl == 0) { cPos = vec3(-1.15, 0.25, -0.35); col = vec3(2.4, 1.15, 0.35); }\n  else if (cl == 1) { cPos = vec3(-0.32, 0.42, -0.95); col = vec3(0.28, 1.85, 2.35); }\n  else if (cl == 2) { cPos = vec3(0.58, 0.22, -0.25); col = vec3(2.25, 0.38, 1.45); }\n  else { cPos = vec3(1.18, 0.48, -0.95); col = vec3(0.45, 2.15, 0.85); }\n  pos = cPos + vec3(cos(ang) * 0.36, 0.16 * sin(ang * 2.0), sin(ang) * 0.36);\n}\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\nvec2 mapHall(vec3 p) {\n  float dFloor = p.y + 0.58;\n  float dBack = p.z + 1.85;\n  vec2 res = vec2(dFloor, 1.0);\n  if (dBack < res.x) res = vec2(dBack, 2.0);\n  float dB1 = sdBox(p - vec3(-0.68, -0.22, -0.62), vec3(0.22, 0.36, 0.22));\n  if (dB1 < res.x) res = vec2(dB1, 3.0);\n  float dB2 = length(p - vec3(0.16, -0.28, -0.45)) - 0.30;\n  if (dB2 < res.x) res = vec2(dB2, 3.0);\n  float dB3 = sdBox(p - vec3(0.88, -0.18, -0.78), vec3(0.20, 0.40, 0.20));\n  if (dB3 < res.x) res = vec2(dB3, 3.0);\n  return res;\n}\n\nvec3 calcNormal(vec3 p) {\n  vec2 e = vec2(0.0025, 0.0);\n  return normalize(vec3(\n    mapHall(p + e.xyy).x - mapHall(p - e.xyy).x,\n    mapHall(p + e.yxy).x - mapHall(p - e.yxy).x,\n    mapHall(p + e.yyx).x - mapHall(p - e.yyx).x\n  ));\n}\n\nfloat evalShadow(vec3 p, vec3 lPos) {\n  vec3 d = lPos - p;\n  float dist = length(d);\n  vec3 dir = d / max(dist, 1e-4);\n  float t = 0.04;\n  for (int i = 0; i < 14; i++) {\n    float h = mapHall(p + dir * t).x;\n    if (h < 0.004) return 0.0;\n    t += max(h, 0.04);\n    if (t >= dist - 0.05) break;\n  }\n  return 1.0;\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 useBVH = sx >= split;\n\n  int nLights = int(clamp(floor(P_LIGHT_COUNT + 0.5), 8.0, 32.0));\n  float coneK = clamp(P_CONE_SHARP, 0.2, 2.5);\n  float anim = iTime * max(P_ANIM_SPEED, 0.0);\n\n  vec3 ro = vec3(0.0, 0.42, 2.08);\n  vec3 rd = normalize(vec3(uv.x, uv.y - 0.16, -1.35));\n  vec3 col = vec3(0.025, 0.03, 0.045);\n\n  float t = 0.05;\n  float hitId = 0.0;\n  for (int i = 0; i < 64; i++) {\n    vec2 h = mapHall(ro + rd * t);\n    if (h.x < 0.002) { hitId = h.y; break; }\n    t += h.x;\n    if (t > 9.0) break;\n  }\n\n  if (hitId > 0.5) {\n    vec3 p = ro + rd * t;\n    vec3 n = calcNormal(p);\n    vec3 alb = (hitId < 1.5) ? vec3(0.56, 0.57, 0.60) : ((hitId < 2.5) ? vec3(0.45, 0.48, 0.52) : vec3(0.76, 0.76, 0.78));\n\n    // Cluster bounding centers for 2-level Light BVH importance traversal\n    vec3 clCent[4];\n    clCent[0] = vec3(-1.15, 0.25, -0.35);\n    clCent[1] = vec3(-0.32, 0.42, -0.95);\n    clCent[2] = vec3(0.58, 0.22, -0.25);\n    clCent[3] = vec3(1.18, 0.48, -0.95);\n\n    int activeClusters = max(nLights / 8, 1);\n    float cw[4];\n    float sumW = 0.0;\n    for (int c = 0; c < 4; c++) {\n      if (c >= activeClusters) { cw[c] = 0.0; continue; }\n      vec3 toC = clCent[c] - p;\n      float d2 = max(dot(toC, toC), 0.18);\n      float cosBound = pow(max(dot(n, normalize(toC)) + 0.35, 0.05), coneK);\n      cw[c] = cosBound / d2;\n      sumW += cw[c];\n    }\n\n    vec3 acc = vec3(0.0);\n    float frameJit = floor(iTime * 10.0) * 0.13;\n    const int SAMPLES = 4;\n\n    for (int s = 0; s < SAMPLES; s++) {\n      float u1 = hash21(fragCoord + vec2(float(s) * 19.3, frameJit * 13.7));\n      float u2 = hash21(fragCoord * 1.19 + vec2(frameJit * 7.1, float(s) * 31.1));\n      int chosenIdx = 0;\n      float pdf = 1.0 / float(nLights);\n\n      if (!useBVH) {\n        // Left: Uniform random selection across all N lights -> massive variance & missed nearby emitters\n        chosenIdx = int(min(floor(u1 * float(nLights)), float(nLights - 1)));\n      } else {\n        // Right: Light BVH descent: pick cluster with probability cw[c]/sumW, then pick child in cluster\n        float target = u1 * max(sumW, 1e-5);\n        int pickedCl = 0;\n        float run = 0.0;\n        for (int c = 0; c < 4; c++) {\n          run += cw[c];\n          if (target <= run) { pickedCl = c; break; }\n        }\n        int subIdx = int(min(floor(u2 * 8.0), 7.0));\n        chosenIdx = min(pickedCl * 8 + subIdx, nLights - 1);\n        pdf = (cw[pickedCl] / max(sumW, 1e-5)) * (1.0 / 8.0);\n      }\n\n      vec3 lPos, lCol;\n      getLight(chosenIdx, anim, lPos, lCol);\n      vec3 toL = lPos - p;\n      float d2 = max(dot(toL, toL), 0.08);\n      vec3 L = toL / sqrt(d2);\n      float ndl = max(dot(n, L), 0.0);\n      if (ndl > 0.002) {\n        float vis = evalShadow(p + n * 0.015, lPos);\n        vec3 contrib = alb * lCol * (ndl * vis / d2) * 0.055;\n        acc += contrib / max(pdf, 1e-4);\n      }\n    }\n    col = acc / float(SAMPLES) + alb * vec3(0.03, 0.035, 0.048);\n  }\n\n  // Render glowing emitter bulbs in 3D space so clusters are immediately legible\n  for (int i = 0; i < 32; i++) {\n    if (i >= nLights) break;\n    vec3 lPos, lCol;\n    getLight(i, anim, lPos, lCol);\n    vec3 toL = lPos - ro;\n    float proj = dot(toL, rd);\n    if (proj > 0.1 && proj < t) {\n      float perp = length(toL - rd * proj);\n      col += lCol * exp(-perp * perp * 850.0) * 0.72;\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": "light-bvh-many-lights",
     "runtime": "glsl-fragment",
     "checked_at": "2026-11-30T21:07:14.000Z",
     "renderer": "Headless EGL Tesla T4/PCIe/SSE2, OpenGL 3.30 Core, 512×512, iTime=1.5",
     "stats": {
      "mean": 0.5732,
      "std": 0.1904,
      "min": 0.1101,
      "max": 0.9936
     },
     "image": "/specimens/light-bvh-many-lights-live.webp",
     "reason": null
    }
   }
  }
 ],
 "related": [
  "lightcuts",
  "restir-di",
  "multiple-importance-sampling",
  "instant-radiosity"
 ],
 "extends": [],
 "supersedes": [],
 "combines_with": [
  {
   "id": "restir-di",
   "why": "The tree supplies better initial candidates that reservoirs then resample and reuse."
  }
 ],
 "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/light-bvh-many-lights.json"
 },
 "solves": [
  "path tracer is slow with thousands of emissive triangles",
  "scene with many lights is noisy",
  "which light to sample when there are too many",
  "emissive meshes make rendering cost explode",
  "choose lights by their likely contribution"
 ],
 "authority": "Estevez & Kulla, 2018",
 "url": "https://texelatlas.vercel.app/t/light-bvh-many-lights/",
 "execution_fidelity": "conceptual-diagram",
 "fidelity_label": "Visual Diagram",
 "benchmark_eligible": false,
 "gpu_weight": {
  "weight_x": 87.27,
  "tier": "extreme",
  "p50_ms": 2.8712,
  "p95_ms": 3.0247,
  "baseline_p50_ms": 0.0329,
  "gpu": "Tesla T4/PCIe/SSE2",
  "resolution": "1920x1080",
  "method": "opengl-timer-query",
  "frames": 32,
  "preset_id": "light-bvh-many-lights-live",
  "execution_fidelity": "conceptual-diagram",
  "fidelity_label": "Visual Diagram",
  "benchmark_eligible": false,
  "generated_at": "2026-11-30T21:07:47Z",
  "l4": {
   "weight_x": 93.33,
   "tier": "extreme",
   "p50_ms": 1.484,
   "p95_ms": 1.5191,
   "speedup_x": 1.93,
   "gpu": "NVIDIA L4/PCIe/SSE2",
   "resolution": "1920x1080",
   "baseline_p50_ms": 0.0159
  },
  "a100": {
   "weight_x": 59.73,
   "tier": "heavy",
   "p50_ms": 1.7203,
   "p95_ms": 1.7267,
   "speedup_x": 1.67,
   "gpu": "NVIDIA A100-SXM4-40GB/PCIe/SSE2",
   "resolution": "1920x1080",
   "baseline_p50_ms": 0.0288
  }
 }
}