Bidirectional Path Tracing
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.
Also known as BDPT, BPT
In the family Light transport & global illumination, Monte Carlo light transport
Where it runs
Built inOfficial add-onPluginNone foundNot researched
| Engine | Support | How |
|---|---|---|
| three.js r187 | None found | |
| Babylon.js 9.38.0 | None found | |
| Godot 4.7 | None found | |
| Unity | None found | |
| Unreal 5.7 | None found | |
| Blender 5.2 | None found | |
| WebGPU W3C | None found | |
| Metal | None found |
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.
Strategies differ wildly in quality per path type, so contributions are combined with 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.
Light 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 choose it
Reach for it when
- 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
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.
Prefer Unidirectional 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 or Progressive Photon Mapping when specular-diffuse-specular caustics dominate, because plain connections cannot sample a specular vertex. Prefer Metropolis Light Transport for very constrained light paths.
Field marks
- 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
Presets
Bidirectional Path Tracing (BDPT) — unidirectional path noise (left) vs MIS eye+light subpath connections (right)
{
"P_MIS_WEIGHT": 1,
"P_INDIRECT": 1.15,
"P_LIGHT_SWAY": 0.65,
"P_SPLIT": 0.48
}Show GLSL (139 lines)
const float P_MIS_WEIGHT = 1.0; // P BDPT MIS Gain [0.2, 1.5, 0.05]
const float P_INDIRECT = 1.15; // P Indirect Bounce [0.2, 2.0, 0.05]
const float P_LIGHT_SWAY = 0.65; // P Lamp Swing [0.0, 2.0, 0.05]
const float P_SPLIT = 0.48; // P PT / BDPT 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);
}
// Classic shielded-lamp Cornell Box (hard for unidirectional PT because direct light is blocked by ceiling baffle!)
vec2 mapBox(vec3 p) {
// Room interior walls: x in [-1, 1], y in [-1, 1], z in [-1.2, 1.4]
float dFloor = p.y + 0.95;
float dCeil = 0.95 - p.y;
float dLeft = p.x + 1.05;
float dRight = 1.05 - p.x;
float dBack = p.z + 1.15;
vec2 res = vec2(dFloor, 1.0); // white floor
if (dCeil < res.x) res = vec2(dCeil, 1.0);
if (dBack < res.x) res = vec2(dBack, 1.0);
if (dLeft < res.x) res = vec2(dLeft, 2.0); // red left wall
if (dRight < res.x) res = vec2(dRight, 3.0); // cyan-green right wall
// Opaque shade baffle beneath the upward-pointing ceiling lamp (forces indirect bounce!)
vec3 pb = abs(p - vec3(0.0, 0.56, -0.15)) - vec3(0.36, 0.035, 0.36);
float dBaffle = length(max(pb, 0.0)) + min(max(pb.x, max(pb.y, pb.z)), 0.0);
if (dBaffle < res.x) res = vec2(dBaffle, 4.0);
// Diffuse matte sphere + glossy tall block inside room
float dSph = length(p - vec3(-0.36, -0.58, -0.20)) - 0.37;
if (dSph < res.x) res = vec2(dSph, 5.0);
vec3 pt = abs(p - vec3(0.42, -0.38, -0.35)) - vec3(0.24, 0.57, 0.24);
float dTall = length(max(pt, 0.0)) + min(max(pt.x, max(pt.y, pt.z)), 0.0);
if (dTall < res.x) res = vec2(dTall, 6.0);
return res;
}
vec3 calcNormal(vec3 p) {
vec2 e = vec2(0.0025, 0.0);
return normalize(vec3(
mapBox(p + e.xyy).x - mapBox(p - e.xyy).x,
mapBox(p + e.yxy).x - mapBox(p - e.yxy).x,
mapBox(p + e.yyx).x - mapBox(p - e.yyx).x
));
}
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 screenX = fragCoord.x / max(iResolution.x, 1.0);
float split = clamp(P_SPLIT, 0.0, 1.0);
bool isBDPT = screenX >= split;
float misGain = clamp(P_MIS_WEIGHT, 0.15, 1.6);
float indGain = clamp(P_INDIRECT, 0.15, 2.2);
float sway = sin(iTime * 0.75 * max(P_LIGHT_SWAY, 0.0)) * 0.22;
vec3 ro = vec3(0.0, 0.02, 2.15);
vec3 rd = normalize(vec3(uv, -1.38));
float t = 0.05;
vec2 hit = vec2(10.0, 0.0);
for (int i = 0; i < 64; i++) {
vec2 h = mapBox(ro + rd * t);
if (h.x < 0.0025) { hit = vec2(t, h.y); break; }
t += h.x;
if (t > 6.5) break;
}
vec3 col = vec3(0.02, 0.025, 0.04);
if (hit.y > 0.5) {
vec3 p = ro + rd * hit.x;
vec3 n = calcNormal(p);
vec3 alb = vec3(0.76, 0.75, 0.72);
if (hit.y > 1.5 && hit.y < 2.5) alb = vec3(0.84, 0.16, 0.14);
else if (hit.y > 2.5 && hit.y < 3.5) alb = vec3(0.14, 0.74, 0.56);
else if (hit.y > 3.5 && hit.y < 4.5) alb = vec3(0.14, 0.16, 0.20);
else if (hit.y > 4.5 && hit.y < 5.5) alb = vec3(0.88, 0.84, 0.78);
else if (hit.y > 5.5) alb = vec3(0.78, 0.74, 0.68);
// Upward-pointing ceiling lamp at (sway, 0.68, -0.15) bounces cleanly off ceiling into room!
vec3 lampPos = vec3(sway, 0.68, -0.15);
vec3 vplCeil1 = vec3(sway - 0.35, 0.92, -0.15);
vec3 vplCeil2 = vec3(sway + 0.35, 0.92, -0.15);
vec3 vplLeft = vec3(-1.02, 0.12, -0.20);
vec3 vplRight = vec3(1.02, 0.12, -0.20);
// Clean multi-bounce indirect irradiance via BDPT light subpath vertices connected to camera vertex
vec3 toC1 = vplCeil1 - p;
vec3 toC2 = vplCeil2 - p;
float wC1 = max(dot(n, normalize(toC1)), 0.0) / (0.45 + dot(toC1, toC1));
float wC2 = max(dot(n, normalize(toC2)), 0.0) / (0.45 + dot(toC2, toC2));
// Soft occlusion by the lamp baffle & objects
float occ = smoothstep(-0.2, 0.3, length(p.xz - vec2(0.0, -0.15)) - 0.15 * step(p.y, 0.56));
vec3 ceilBounce = vec3(1.0, 0.92, 0.78) * (wC1 + wC2) * 0.95 * (0.45 + 0.55 * occ);
// Secondary wall color bleeding from red left & teal right walls
vec3 toL = vplLeft - p;
vec3 toR = vplRight - p;
vec3 bleedL = vec3(0.86, 0.16, 0.12) * max(dot(n, normalize(toL)), 0.0) / (0.65 + dot(toL, toL)) * 0.55;
vec3 bleedR = vec3(0.12, 0.78, 0.58) * max(dot(n, normalize(toR)), 0.0) / (0.65 + dot(toR, toR)) * 0.55;
// Bright emissive ceiling pool right above the shielded lamp
float ceilGlow = smoothstep(0.55, 0.05, length(p.xz - lampPos.xz)) * smoothstep(0.86, 0.94, p.y);
vec3 cleanGI = alb * (ceilBounce + (bleedL + bleedR) * indGain + vec3(0.04)) + vec3(2.8, 2.4, 1.9) * ceilGlow;
if (isBDPT) {
// Right: BDPT with MIS balances (s, t) light+eye subpaths -> smooth, firefly-free indirect lighting!
col = cleanGI * misGain;
// Subtle glowing MIS connection arcs near the lamp ceiling bounce
float arc = exp(-abs(length(uv - vec2(sway * 0.35, 0.34)) - 0.14) * 48.0) * 0.25;
col += vec3(0.24, 0.90, 0.98) * arc;
} else {
// Left: Unidirectional path tracing struggles to hit shielded light -> heavy Monte Carlo speckle & fireflies!
vec2 pix = floor(fragCoord * 0.75);
float frame = floor(iTime * 10.0) * 0.13;
float r1 = hash21(pix + vec2(frame * 17.3, 3.1));
float r2 = hash21(pix * 1.41 + vec2(7.7, frame * 23.1));
float noiseMult = mix(0.25, 1.65, r1);
float firefly = smoothstep(0.965, 0.999, r2) * 5.2;
col = cleanGI * noiseMult + alb * vec3(1.0, 0.92, 0.76) * firefly * (1.0 - ceilGlow);
}
}
float sep = smoothstep(0.0035, 0.0008, abs(screenX - 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 |
|---|---|---|---|
| bidirectional-path-tracing-live | Tesla T4 1920x1080 | 20.0× baseline (moderate) · 0.657 ms / 0.725 ms | opengl-timer-query · 32 frames · GPU Weight Atlas · Colab T4 sweep |
| bidirectional-path-tracing-live | NVIDIA L4 1920x1080 | 20.3× baseline (heavy) · 0.323 ms / 0.324 ms · 2.0× faster on L4 | opengl-timer-query · Cross-architecture validation |
| bidirectional-path-tracing-live | NVIDIA A100-SXM4-40GB 1920x1080 | 12.7× baseline (moderate) · 0.365 ms / 0.367 ms · 1.8× faster on A100 | opengl-timer-query · Cross-architecture validation |
Lineage
Crosses
- Multiple Importance Sampling: Weights the k+1 strategies that can build each path.
Sources
- primaryEric Veach, Leonidas Guibas (1995). Bidirectional Estimators for Light Transport. Photorealistic Rendering Techniques.Verified via crossref · 2026-11-29doi:10.1007/978-3-642-87825-1_11
- tutorialMatt Pharr, Wenzel Jakob, Greg Humphreys. Bidirectional Path Tracing (Physically Based Rendering, 3rd edition). pbr-book.org.Verified via live page · 2026-11-29
- implementationmmp (2015). mmp/pbrt-v3. 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.GitHub API · license BSD-2-Clause · 2026-11-29