{
 "id": "path-guiding",
 "title": "Practical Path Guiding",
 "aliases": [
  "guided path tracing",
  "SD-tree guiding"
 ],
 "domain": "gi",
 "subdomain": "adaptive sampling",
 "stage": "lighting",
 "realtime": "offline",
 "platforms": [
  "cpu",
  "cuda"
 ],
 "year_introduced": 2017,
 "inputs": [
  "mesh",
  "material-params"
 ],
 "outputs": [
  "radiance"
 ],
 "style": "photoreal",
 "dynamic": "static",
 "summary": "Learns a spatially varying directional distribution of incident radiance during rendering, then uses it to sample bounce directions, cutting noise in scenes with hard indirect light.",
 "how_it_works": "Standard BSDF sampling ignores where the light actually comes from. Path guiding builds an approximation of the incident radiance field `L(x, w)` and samples new directions from a distribution proportional to it times the BSDF cosine, ideally minimizing variance.\n\nThe practical version stores that field in a **spatial binary tree** whose leaves each hold a **directional quadtree** on an equal-area sphere mapping. Every path vertex contributes (via its estimated radiance, weighted by throughput) to the leaf containing it. Trees refine: spatial nodes split when they accumulate enough samples, directional nodes split when they hold too much energy.\n\nRendering proceeds in **iterations** of doubling sample counts. Iteration `k` samples from the distribution learned in iteration `k-1`, and its own samples train the next one, with earlier iterations' results combined by inverse variance for the final image. The learned distribution is combined with BSDF sampling by one-sample MIS, which protects against bad guides and keeps the estimator unbiased.",
 "when_to_use": "Choose it for offline scenes where indirect light arrives through narrow openings, lamp shades or complex layered materials and standard path tracing remains noisy.\n\nPrefer [path-tracing](path-tracing) with [multiple-importance-sampling](multiple-importance-sampling) for simple scenes, since learning costs memory and time. Prefer [metropolis-light-transport](metropolis-light-transport) for the most constrained paths where adaptive proposals still fail. Prefer [neural-radiance-caching](neural-radiance-caching) for real-time budgets, since guiding still needs many samples per pixel.",
 "cost": {
  "class": "offline",
  "notes": "Tree training adds modest per-sample overhead; the benefit is lower variance per sample and faster convergence on hard scenes."
 },
 "failure_modes": [
  "Poor training early on: the first iterations can be worse than unguided sampling",
  "Spatial subdivision cannot represent thin or high-frequency geometry, so guiding is blurry in complex areas",
  "Pure diffuse scenes see little or no gain while paying the learning overhead",
  "Fireflies from a sharply peaked learned distribution if the BSDF fallback fraction is too small"
 ],
 "sources": [
  {
   "role": "primary",
   "key": "doi:10.1111/cgf.13227",
   "type": "paper",
   "title": "Practical Path Guiding for Efficient Light‐Transport Simulation",
   "authors": [
    "Thomas Müller",
    "Markus Gross",
    "Jan Novák"
   ],
   "year": 2017,
   "venue": "Computer Graphics Forum",
   "url": "https://doi.org/10.1111/cgf.13227",
   "ids": {
    "doi": "10.1111/cgf.13227"
   },
   "license": null,
   "extra": {
    "csl_type": "journal-article"
   },
   "provenance": {
    "title": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1111/cgf.13227",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "authors": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1111/cgf.13227",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "year": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1111/cgf.13227",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "venue": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1111/cgf.13227",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "url": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1111/cgf.13227",
     "checked_at": "2026-11-29T15:51:27.588Z"
    }
   },
   "status": "verified",
   "checked_at": "2026-11-29T15:51:27.588Z",
   "title_sim": 1,
   "__bib": "mller2017practical"
  }
 ],
 "presets": [
  {
   "id": "path-guiding-live",
   "title": "Practical Path Guiding — cosine hemisphere noise (left) vs SD-tree directional guiding lobes (right)",
   "runtime": "glsl-fragment",
   "params": {
    "P_GUIDE_SHARP": 0.85,
    "P_LOBE_VIS": 0.85,
    "P_LIGHT_ORBIT": 0.65,
    "P_SPLIT": 0.48
   },
   "basis": "original",
   "license_note": "MIT — written for this index.",
   "code": "const float P_GUIDE_SHARP = 0.85; // P Guiding Focus [0.1, 1.0, 0.02]\nconst float P_LOBE_VIS = 0.85; // P SD-Tree Lobes [0.0, 1.5, 0.05]\nconst float P_LIGHT_ORBIT = 0.65; // P Caustic Sweep [0.0, 2.2, 0.05]\nconst float P_SPLIT = 0.48; // P Unguided / Guided [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\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 screenX = fragCoord.x / max(iResolution.x, 1.0);\n  float split = clamp(P_SPLIT, 0.0, 1.0);\n  bool isGuided = screenX >= split;\n  float sharp = clamp(P_GUIDE_SHARP, 0.05, 1.0);\n  float lobeVis = clamp(P_LOBE_VIS, 0.0, 1.6);\n  float spin = iTime * max(P_LIGHT_ORBIT, 0.0);\n\n  // Perspective glossy-diffuse floor & central reflective torus illuminated by a tiny bright ceiling skylight!\n  vec3 ro = vec3(0.0, 0.65, 2.25);\n  vec3 rd = normalize(vec3(uv - vec2(0.0, 0.14), -1.42));\n\n  vec3 bg = mix(vec3(0.018, 0.024, 0.042), vec3(0.055, 0.072, 0.118), smoothstep(-0.5, 0.5, uv.y));\n  vec3 col = bg;\n\n  // Moving small high-radiance skylight / indirect mirror patch (primary target of directional guiding!)\n  vec3 lightPos = vec3(0.75 * cos(spin * 0.55), 1.35, 0.45 * sin(spin * 0.55) - 0.25);\n\n  // Intersect hero sphere (R=0.46 at y=0.04) and floor plane (y=-0.42)\n  vec3 sc = vec3(0.0, 0.04, 0.0);\n  vec3 oc = ro - sc;\n  float b = dot(oc, rd);\n  float c = dot(oc, oc) - 0.46 * 0.46;\n  float disc = b * b - c;\n  float tSph = (disc > 0.0 && (-b - sqrt(disc)) > 0.05) ? (-b - sqrt(disc)) : 1e5;\n  float tFl = (rd.y < -0.01) ? ((-0.42 - ro.y) / rd.y) : 1e5;\n  if (tFl < 0.05 || tFl > 12.0) tFl = 1e5;\n\n  float tHit = min(tSph, tFl);\n  if (tHit < 1e4) {\n    vec3 p = ro + rd * tHit;\n    vec3 n = (tSph < tFl) ? normalize(p - sc) : vec3(0.0, 1.0, 0.0);\n    vec3 toL = lightPos - p;\n    float distL = length(toL);\n    vec3 lDir = toL / max(distL, 1e-4);\n\n    // Soft sphere shadow on floor\n    vec3 toSc = sc - p;\n    float proj = dot(toSc, lDir);\n    float perp = length(toSc - lDir * max(proj, 0.0));\n    float shadow = (tFl < tSph && proj > 0.0) ? smoothstep(0.38, 0.52, perp) : 1.0;\n\n    float diff = max(dot(n, lDir), 0.0) * shadow;\n    float spec = pow(max(dot(n, normalize(lDir - rd)), 0.0), 42.0) * shadow;\n    // Focused indirect caustic ring around base of sphere\n    float caustic = (tFl < tSph) ? exp(-abs(length(p.xz) - 0.64) * 14.0) * (0.4 + 0.6 * max(dot(normalize(p.xz + 1e-4), lDir.xz), 0.0)) : 0.0;\n\n    vec3 alb = (tSph < tFl) ? vec3(0.84, 0.68, 0.46) : vec3(0.38, 0.42, 0.48);\n    vec3 cleanCol = alb * (0.14 + 1.35 * diff / (0.65 + 0.35 * distL))\n                  + vec3(1.0, 0.94, 0.82) * (spec * 0.95 + caustic * 0.72);\n\n    if (isGuided) {\n      // Right: Learned SD-Tree directional guiding concentrates rays into the skylight lobe -> low variance!\n      float residNoise = (hash21(floor(fragCoord) + floor(iTime * 12.0) * 0.13) - 0.5) * 0.16 * (1.0 - sharp);\n      col = cleanCol * (1.0 + residNoise);\n\n      // Overlay subtle spatial SD-Tree quad cells & directional guiding arrows pointing toward lightPos on floor!\n      if (tFl < tSph && lobeVis > 0.02) {\n        vec2 cellUV = p.xz * 2.2;\n        vec2 cellF = fract(cellUV) - 0.5;\n        vec2 cellD = 0.5 - abs(cellF);\n        float sdGrid = smoothstep(0.028, 0.008, min(cellD.x, cellD.y));\n        // Directional Von Mises-Fisher / quadtree lobe petal aligned toward lDir.xz\n        vec2 dir2 = normalize(lDir.xz + vec2(1e-4));\n        float rC = length(cellF);\n        float align = max(dot(normalize(cellF + vec2(1e-5)), dir2), 0.0);\n        float lobeR = 0.08 + 0.24 * pow(align, mix(1.5, 6.0, sharp));\n        float lobeRing = exp(-abs(rC - lobeR) * 58.0) * smoothstep(0.45, 0.05, rC);\n        col += vec3(0.16, 0.82, 0.98) * (sdGrid * 0.18 + lobeRing * 0.55) * lobeVis;\n      }\n    } else {\n      // Left: Unguided cosine-weighted sampling misses small light & caustic -> heavy variance & fireflies!\n      vec2 pix = floor(fragCoord * 0.75);\n      float fr = floor(iTime * 10.0) * 0.17;\n      float r1 = hash21(pix + vec2(fr * 13.7, 2.9));\n      float r2 = hash21(pix * 1.27 + vec2(9.1, fr * 23.3));\n      float variance = mix(0.22, 1.85, r1);\n      float firefly = smoothstep(0.95, 0.998, r2) * 5.8 * (0.25 + spec + caustic);\n      col = cleanCol * variance + vec3(1.0, 0.90, 0.72) * firefly;\n    }\n\n    if (tFl < tSph) col = mix(col, bg, 1.0 - exp(-tFl * 0.12));\n  }\n\n  float sep = smoothstep(0.0035, 0.0008, abs(screenX - split));\n  col = mix(col, vec3(0.95, 0.97, 1.0), sep);\n\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": "path-guiding",
     "runtime": "glsl-fragment",
     "checked_at": "2026-11-30T20:35:54.000Z",
     "renderer": "Headless EGL Tesla T4/PCIe/SSE2, OpenGL 3.30 Core, 512×512, iTime=1.5",
     "stats": {
      "mean": 0.4001,
      "std": 0.1825,
      "min": 0.1129,
      "max": 0.9767
     },
     "image": "/specimens/path-guiding-live.webp",
     "reason": null
    }
   }
  }
 ],
 "related": [
  "path-tracing",
  "neural-radiance-caching",
  "metropolis-light-transport",
  "restir-pt"
 ],
 "extends": [],
 "supersedes": [],
 "combines_with": [
  {
   "id": "multiple-importance-sampling",
   "why": "One-sample MIS between the learned guide and BSDF sampling keeps the combined estimator robust and unbiased."
  }
 ],
 "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/path-guiding.json"
 },
 "solves": [
  "indirect light through narrow openings stays noisy",
  "path tracer wastes samples in the wrong directions",
  "lamp shades and layered materials render grainy",
  "need smarter bounce directions learned while rendering",
  "caustic-like paths converge too slowly"
 ],
 "authority": "Müller et al., 2017",
 "url": "https://texelatlas.vercel.app/t/path-guiding/",
 "execution_fidelity": "conceptual-diagram",
 "fidelity_label": "Visual Diagram",
 "benchmark_eligible": false,
 "gpu_weight": {
  "weight_x": 3.3,
  "tier": "light",
  "p50_ms": 0.1086,
  "p95_ms": 0.1108,
  "baseline_p50_ms": 0.0329,
  "gpu": "Tesla T4/PCIe/SSE2",
  "resolution": "1920x1080",
  "method": "opengl-timer-query",
  "frames": 32,
  "preset_id": "path-guiding-live",
  "execution_fidelity": "conceptual-diagram",
  "fidelity_label": "Visual Diagram",
  "benchmark_eligible": false,
  "generated_at": "2026-11-30T21:07:47Z",
  "l4": {
   "weight_x": 2.56,
   "tier": "light",
   "p50_ms": 0.0407,
   "p95_ms": 0.0432,
   "speedup_x": 2.67,
   "gpu": "NVIDIA L4/PCIe/SSE2",
   "resolution": "1920x1080",
   "baseline_p50_ms": 0.0159
  },
  "a100": {
   "weight_x": 1.99,
   "tier": "feather",
   "p50_ms": 0.0572,
   "p95_ms": 0.0573,
   "speedup_x": 1.9,
   "gpu": "NVIDIA A100-SXM4-40GB/PCIe/SSE2",
   "resolution": "1920x1080",
   "baseline_p50_ms": 0.0288
  }
 }
}