{
 "id": "bidirectional-path-tracing",
 "title": "Bidirectional Path Tracing",
 "aliases": [
  "BDPT",
  "BPT"
 ],
 "domain": "gi",
 "subdomain": "Monte Carlo light transport",
 "stage": "lighting",
 "realtime": "offline",
 "platforms": [
  "cpu",
  "cuda"
 ],
 "year_introduced": 1993,
 "inputs": [
  "mesh",
  "material-params"
 ],
 "outputs": [
  "radiance"
 ],
 "style": "photoreal",
 "dynamic": "both",
 "summary": "Traces one random walk from the camera and one from a light, then connects every pair of vertices with a shadow ray. Each connection is a different path-sampling strategy, merged with multiple importance sampling.",
 "how_it_works": "A path from a light to the eye can be built many ways: by extending from the eye, from the light, or from both and joining in the middle. BDPT does all of them in one pass. It generates an **eye subpath** and a **light subpath**, each a short random walk, and for every pair of vertices `(i, j)` it tests visibility and evaluates the connecting segment's throughput. A path of length `k` is therefore sampled by `k+1` different strategies.\n\nStrategies differ wildly in quality per path type, so contributions are combined with [multiple-importance-sampling](multiple-importance-sampling). The weights need the pdf each other strategy would have used, which is where most implementation bugs live: reversed-direction pdfs, non-symmetric BSDFs and the area measure for vertices.\n\nLight subpaths that reach the camera lens (the `t = 1` case) deposit into the image as a **light tracing** splat, so the framebuffer needs atomic or per-thread accumulation.",
 "when_to_use": "Choose it for scenes lit mostly indirectly through small gaps, lamps enclosed in diffusers, or interiors with a lot of diffuse interreflection and hard-to-reach emitters, where the camera walk rarely finds a light.\n\nPrefer [path-tracing](path-tracing) for open scenes, outdoor lighting or when the extra complexity is not worth it; BDPT is slower per sample and does not help much there. Prefer [vertex-connection-and-merging](vertex-connection-and-merging) or [progressive-photon-mapping](progressive-photon-mapping) when specular-diffuse-specular caustics dominate, because plain connections cannot sample a specular vertex. Prefer [metropolis-light-transport](metropolis-light-transport) for very constrained light paths.",
 "cost": {
  "class": "offline",
  "notes": "Roughly several times the cost per sample of unidirectional path tracing because of the connection rays and MIS weight computation; image splatting makes GPU implementations awkward."
 },
 "failure_modes": [
  "Specular vertices cannot be connected, so caustics through glass still fall back to unlikely random hits",
  "Subtle MIS pdf bugs create slightly wrong brightness that is hard to spot without a reference",
  "Light-tracing splats outside the pixel footprint create sparse speckle and need a separate buffer or atomics",
  "Memory and bandwidth for storing subpaths make wavefront GPU versions heavy"
 ],
 "sources": [
  {
   "role": "primary",
   "key": "doi:10.1007/978-3-642-87825-1_11",
   "type": "chapter",
   "title": "Bidirectional Estimators for Light Transport",
   "authors": [
    "Eric Veach",
    "Leonidas Guibas"
   ],
   "year": 1995,
   "venue": "Photorealistic Rendering Techniques",
   "url": "https://doi.org/10.1007/978-3-642-87825-1_11",
   "ids": {
    "doi": "10.1007/978-3-642-87825-1_11"
   },
   "license": null,
   "extra": {
    "csl_type": "book-chapter"
   },
   "provenance": {
    "title": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1007/978-3-642-87825-1_11",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "authors": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1007/978-3-642-87825-1_11",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "year": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1007/978-3-642-87825-1_11",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "venue": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1007/978-3-642-87825-1_11",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "url": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1007/978-3-642-87825-1_11",
     "checked_at": "2026-11-29T15:51:27.588Z"
    }
   },
   "status": "verified",
   "checked_at": "2026-11-29T15:51:27.588Z",
   "title_sim": 1,
   "__bib": "veach1995bidirectional"
  },
  {
   "role": "tutorial",
   "key": "url:https://pbr-book.org/3ed-2018/Light_Transport_III_Bidirectional_Methods/Bidirectional_Path_Tracing",
   "type": "tutorial",
   "title": "Bidirectional Path Tracing (Physically Based Rendering, 3rd edition)",
   "authors": [
    "Matt Pharr",
    "Wenzel Jakob",
    "Greg Humphreys"
   ],
   "year": null,
   "venue": "pbr-book.org",
   "url": "https://pbr-book.org/3ed-2018/Light_Transport_III_Bidirectional_Methods/Bidirectional_Path_Tracing",
   "ids": {},
   "license": null,
   "extra": {
    "http_status": 200,
    "live": true,
    "archive": {
     "url": "http://web.archive.org/web/20260914082514/https://www.pbr-book.org/3ed-2018/Light_Transport_III_Bidirectional_Methods/Bidirectional_Path_Tracing",
     "timestamp": "20260914082514"
    },
    "page_title": "Bidirectional Path Tracing",
    "host": "pbr-book.org",
    "title_confirmed_by_page": true,
    "title_unconfirmed": false
   },
   "provenance": {
    "title": {
     "authority": "http",
     "endpoint": "GET https://pbr-book.org/3ed-2018/Light_Transport_III_Bidirectional_Methods/Bidirectional_Path_Tracing → 200",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "url": {
     "authority": "http",
     "endpoint": "GET https://pbr-book.org/3ed-2018/Light_Transport_III_Bidirectional_Methods/Bidirectional_Path_Tracing → 200",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "authors": {
     "authority": "research-draft",
     "endpoint": "title_hint/author_hint, checked against page title where available",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "venue": {
     "authority": "http",
     "endpoint": "GET https://pbr-book.org/3ed-2018/Light_Transport_III_Bidirectional_Methods/Bidirectional_Path_Tracing → 200",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "year": {
     "authority": "research-draft",
     "endpoint": "title_hint/author_hint, checked against page title where available",
     "checked_at": "2026-11-29T15:51:27.588Z"
    }
   },
   "status": "verified",
   "checked_at": "2026-11-29T15:51:27.588Z",
   "title_sim": 0.95,
   "__bib": "pharrbidirectional"
  },
  {
   "role": "implementation",
   "key": "gh:mmp/pbrt-v3",
   "type": "code",
   "title": "mmp/pbrt-v3",
   "description": "Source code for pbrt, the renderer described in the third edition of \"Physically Based Rendering: From Theory To Implementation\", by Matt Pharr, Wenzel Jakob, and Greg Humphreys.",
   "authors": [
    "mmp"
   ],
   "year": 2015,
   "venue": "GitHub",
   "url": "https://github.com/mmp/pbrt-v3",
   "ids": {
    "repo": "mmp/pbrt-v3"
   },
   "license": "BSD-2-Clause",
   "extra": {
    "stars": 5094,
    "stars_checked": "2026-11-29",
    "archived": false,
    "fork": false,
    "pushed_at": "2023-09-03T11:38:00Z",
    "language": "C++",
    "homepage": "http://pbrt.org",
    "license_name": "BSD 2-Clause \"Simplified\" License"
   },
   "provenance": {
    "title": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/mmp/pbrt-v3",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "authors": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/mmp/pbrt-v3",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "year": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/mmp/pbrt-v3",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "venue": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/mmp/pbrt-v3",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "url": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/mmp/pbrt-v3",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "license": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/mmp/pbrt-v3",
     "checked_at": "2026-11-29T15:51:27.588Z"
    }
   },
   "status": "verified",
   "checked_at": "2026-11-29T15:51:27.588Z",
   "title_sim": null,
   "__bib": "mmp2015pbrt"
  }
 ],
 "presets": [
  {
   "id": "bidirectional-path-tracing-live",
   "title": "Bidirectional Path Tracing (BDPT) — unidirectional path noise (left) vs MIS eye+light subpath connections (right)",
   "runtime": "glsl-fragment",
   "params": {
    "P_MIS_WEIGHT": 1,
    "P_INDIRECT": 1.15,
    "P_LIGHT_SWAY": 0.65,
    "P_SPLIT": 0.48
   },
   "basis": "original",
   "license_note": "MIT — written for this index.",
   "code": "const float P_MIS_WEIGHT = 1.0; // P BDPT MIS Gain [0.2, 1.5, 0.05]\nconst float P_INDIRECT = 1.15; // P Indirect Bounce [0.2, 2.0, 0.05]\nconst float P_LIGHT_SWAY = 0.65; // P Lamp Swing [0.0, 2.0, 0.05]\nconst float P_SPLIT = 0.48; // P PT / BDPT 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// Classic shielded-lamp Cornell Box (hard for unidirectional PT because direct light is blocked by ceiling baffle!)\nvec2 mapBox(vec3 p) {\n  // Room interior walls: x in [-1, 1], y in [-1, 1], z in [-1.2, 1.4]\n  float dFloor = p.y + 0.95;\n  float dCeil = 0.95 - p.y;\n  float dLeft = p.x + 1.05;\n  float dRight = 1.05 - p.x;\n  float dBack = p.z + 1.15;\n\n  vec2 res = vec2(dFloor, 1.0); // white floor\n  if (dCeil < res.x) res = vec2(dCeil, 1.0);\n  if (dBack < res.x) res = vec2(dBack, 1.0);\n  if (dLeft < res.x) res = vec2(dLeft, 2.0); // red left wall\n  if (dRight < res.x) res = vec2(dRight, 3.0); // cyan-green right wall\n\n  // Opaque shade baffle beneath the upward-pointing ceiling lamp (forces indirect bounce!)\n  vec3 pb = abs(p - vec3(0.0, 0.56, -0.15)) - vec3(0.36, 0.035, 0.36);\n  float dBaffle = length(max(pb, 0.0)) + min(max(pb.x, max(pb.y, pb.z)), 0.0);\n  if (dBaffle < res.x) res = vec2(dBaffle, 4.0);\n\n  // Diffuse matte sphere + glossy tall block inside room\n  float dSph = length(p - vec3(-0.36, -0.58, -0.20)) - 0.37;\n  if (dSph < res.x) res = vec2(dSph, 5.0);\n\n  vec3 pt = abs(p - vec3(0.42, -0.38, -0.35)) - vec3(0.24, 0.57, 0.24);\n  float dTall = length(max(pt, 0.0)) + min(max(pt.x, max(pt.y, pt.z)), 0.0);\n  if (dTall < res.x) res = vec2(dTall, 6.0);\n\n  return res;\n}\n\nvec3 calcNormal(vec3 p) {\n  vec2 e = vec2(0.0025, 0.0);\n  return normalize(vec3(\n    mapBox(p + e.xyy).x - mapBox(p - e.xyy).x,\n    mapBox(p + e.yxy).x - mapBox(p - e.yxy).x,\n    mapBox(p + e.yyx).x - mapBox(p - e.yyx).x\n  ));\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 isBDPT = screenX >= split;\n  float misGain = clamp(P_MIS_WEIGHT, 0.15, 1.6);\n  float indGain = clamp(P_INDIRECT, 0.15, 2.2);\n  float sway = sin(iTime * 0.75 * max(P_LIGHT_SWAY, 0.0)) * 0.22;\n\n  vec3 ro = vec3(0.0, 0.02, 2.15);\n  vec3 rd = normalize(vec3(uv, -1.38));\n\n  float t = 0.05;\n  vec2 hit = vec2(10.0, 0.0);\n  for (int i = 0; i < 64; i++) {\n    vec2 h = mapBox(ro + rd * t);\n    if (h.x < 0.0025) { hit = vec2(t, h.y); break; }\n    t += h.x;\n    if (t > 6.5) break;\n  }\n\n  vec3 col = vec3(0.02, 0.025, 0.04);\n  if (hit.y > 0.5) {\n    vec3 p = ro + rd * hit.x;\n    vec3 n = calcNormal(p);\n\n    vec3 alb = vec3(0.76, 0.75, 0.72);\n    if (hit.y > 1.5 && hit.y < 2.5) alb = vec3(0.84, 0.16, 0.14);\n    else if (hit.y > 2.5 && hit.y < 3.5) alb = vec3(0.14, 0.74, 0.56);\n    else if (hit.y > 3.5 && hit.y < 4.5) alb = vec3(0.14, 0.16, 0.20);\n    else if (hit.y > 4.5 && hit.y < 5.5) alb = vec3(0.88, 0.84, 0.78);\n    else if (hit.y > 5.5) alb = vec3(0.78, 0.74, 0.68);\n\n    // Upward-pointing ceiling lamp at (sway, 0.68, -0.15) bounces cleanly off ceiling into room!\n    vec3 lampPos = vec3(sway, 0.68, -0.15);\n    vec3 vplCeil1 = vec3(sway - 0.35, 0.92, -0.15);\n    vec3 vplCeil2 = vec3(sway + 0.35, 0.92, -0.15);\n    vec3 vplLeft = vec3(-1.02, 0.12, -0.20);\n    vec3 vplRight = vec3(1.02, 0.12, -0.20);\n\n    // Clean multi-bounce indirect irradiance via BDPT light subpath vertices connected to camera vertex\n    vec3 toC1 = vplCeil1 - p;\n    vec3 toC2 = vplCeil2 - p;\n    float wC1 = max(dot(n, normalize(toC1)), 0.0) / (0.45 + dot(toC1, toC1));\n    float wC2 = max(dot(n, normalize(toC2)), 0.0) / (0.45 + dot(toC2, toC2));\n\n    // Soft occlusion by the lamp baffle & objects\n    float occ = smoothstep(-0.2, 0.3, length(p.xz - vec2(0.0, -0.15)) - 0.15 * step(p.y, 0.56));\n    vec3 ceilBounce = vec3(1.0, 0.92, 0.78) * (wC1 + wC2) * 0.95 * (0.45 + 0.55 * occ);\n\n    // Secondary wall color bleeding from red left & teal right walls\n    vec3 toL = vplLeft - p;\n    vec3 toR = vplRight - p;\n    vec3 bleedL = vec3(0.86, 0.16, 0.12) * max(dot(n, normalize(toL)), 0.0) / (0.65 + dot(toL, toL)) * 0.55;\n    vec3 bleedR = vec3(0.12, 0.78, 0.58) * max(dot(n, normalize(toR)), 0.0) / (0.65 + dot(toR, toR)) * 0.55;\n\n    // Bright emissive ceiling pool right above the shielded lamp\n    float ceilGlow = smoothstep(0.55, 0.05, length(p.xz - lampPos.xz)) * smoothstep(0.86, 0.94, p.y);\n    vec3 cleanGI = alb * (ceilBounce + (bleedL + bleedR) * indGain + vec3(0.04)) + vec3(2.8, 2.4, 1.9) * ceilGlow;\n\n    if (isBDPT) {\n      // Right: BDPT with MIS balances (s, t) light+eye subpaths -> smooth, firefly-free indirect lighting!\n      col = cleanGI * misGain;\n      // Subtle glowing MIS connection arcs near the lamp ceiling bounce\n      float arc = exp(-abs(length(uv - vec2(sway * 0.35, 0.34)) - 0.14) * 48.0) * 0.25;\n      col += vec3(0.24, 0.90, 0.98) * arc;\n    } else {\n      // Left: Unidirectional path tracing struggles to hit shielded light -> heavy Monte Carlo speckle & fireflies!\n      vec2 pix = floor(fragCoord * 0.75);\n      float frame = floor(iTime * 10.0) * 0.13;\n      float r1 = hash21(pix + vec2(frame * 17.3, 3.1));\n      float r2 = hash21(pix * 1.41 + vec2(7.7, frame * 23.1));\n      float noiseMult = mix(0.25, 1.65, r1);\n      float firefly = smoothstep(0.965, 0.999, r2) * 5.2;\n      col = cleanGI * noiseMult + alb * vec3(1.0, 0.92, 0.76) * firefly * (1.0 - ceilGlow);\n    }\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": "bidirectional-path-tracing",
     "runtime": "glsl-fragment",
     "checked_at": "2026-11-30T20:35:44.000Z",
     "renderer": "Headless EGL Tesla T4/PCIe/SSE2, OpenGL 3.30 Core, 512×512, iTime=1.5",
     "stats": {
      "mean": 0.5331,
      "std": 0.2815,
      "min": 0.0277,
      "max": 0.9927
     },
     "image": "/specimens/bidirectional-path-tracing-live.webp",
     "reason": null
    }
   }
  }
 ],
 "related": [
  "path-tracing",
  "vertex-connection-and-merging",
  "metropolis-light-transport",
  "multiple-importance-sampling"
 ],
 "extends": [],
 "supersedes": [],
 "combines_with": [
  {
   "id": "multiple-importance-sampling",
   "why": "Weights the k+1 strategies that can build each path."
  }
 ],
 "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/bidirectional-path-tracing.json"
 },
 "solves": [
  "interior lit by a lamp inside a diffuser is full of noise",
  "light only reaches the room through a small gap",
  "camera paths rarely find the light source",
  "fireflies in scenes with enclosed emitters",
  "indirect-lit interiors converge too slowly"
 ],
 "authority": "Veach & Guibas, 1995",
 "url": "https://texelatlas.vercel.app/t/bidirectional-path-tracing/",
 "execution_fidelity": "conceptual-diagram",
 "fidelity_label": "Visual Diagram",
 "benchmark_eligible": false,
 "gpu_weight": {
  "weight_x": 19.98,
  "tier": "moderate",
  "p50_ms": 0.6575,
  "p95_ms": 0.7245,
  "baseline_p50_ms": 0.0329,
  "gpu": "Tesla T4/PCIe/SSE2",
  "resolution": "1920x1080",
  "method": "opengl-timer-query",
  "frames": 32,
  "preset_id": "bidirectional-path-tracing-live",
  "execution_fidelity": "conceptual-diagram",
  "fidelity_label": "Visual Diagram",
  "benchmark_eligible": false,
  "generated_at": "2026-11-30T21:07:47Z",
  "l4": {
   "weight_x": 20.29,
   "tier": "heavy",
   "p50_ms": 0.3226,
   "p95_ms": 0.3239,
   "speedup_x": 2.04,
   "gpu": "NVIDIA L4/PCIe/SSE2",
   "resolution": "1920x1080",
   "baseline_p50_ms": 0.0159
  },
  "a100": {
   "weight_x": 12.68,
   "tier": "moderate",
   "p50_ms": 0.3651,
   "p95_ms": 0.3667,
   "speedup_x": 1.8,
   "gpu": "NVIDIA A100-SXM4-40GB/PCIe/SSE2",
   "resolution": "1920x1080",
   "baseline_p50_ms": 0.0288
  }
 }
}