Next-event estimation (direct light sampling)
At every path vertex, trace a shadow ray toward a sampled point on a light instead of hoping a random bounce hits it. Direct illumination becomes low-variance and small lights stop producing fireflies.
Also known as NEE, direct lighting sampling, explicit light sampling, shadow rays
In the family Light transport & global illumination, Monte Carlo sampling
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 | LightmapGI separates direct lighting and bounce passes via cached lightmap texels rather than per-vertex NEE shadow rays. |
| Unity | Built in | HDRP Volume > Add Override > Ray Tracing > Path Tracing (PathTracingSurface.hlsl runs SampleLights direct-light shadow queries with MIS) docs HDRP-only path tracer. |
| Unreal 5.7 | Built in | Path Tracer direct light sampling / multiple importance sampling docs |
| Blender 5.2 | Built in | Cycles samples lights directly by default; Light > Multiple Importance Sample docs Always on in Cycles; MIS is a toggle. |
| WebGPU W3C | None found | |
| Metal | None found |
How it works
A naive path tracer finds light only when a random bounce happens to hit an emitter, so small bright lights give extremely noisy images. Next-event estimation splits the rendering equation at each vertex: the direct term is estimated by choosing a point on a light, evaluating the BSDF and geometry for that direction, and casting a shadow ray to check visibility.
The indirect term continues with the usual BSDF-sampled bounce. To avoid counting emission twice, the continued path must not add emitted light from a surface it hits directly after an NEE-sampled vertex, or the two strategies must be combined with Multiple Importance Sampling weights. The light is chosen by area, power or, with many lights, by a hierarchy (Light BVH and Adaptive Tree Splitting); the sample pdf converts from area to solid angle with the usual distance^2 / cos factor.
Specular chains are the exception: a delta BSDF cannot be sampled by NEE, so those vertices still rely on BSDF sampling and emission hits.
When to choose it
Reach for it when
- path tracer is extremely noisy with small lights
- fireflies from tiny bright emitters
- direct lighting converges too slowly
- light only found when random bounces hit it
Choose it in any path tracer that renders small or bright lights, area lights or HDRI environments (with importance sampling); it is the first change that makes a path tracer converge usably.
Prefer Multiple Importance Sampling on top of it when the BSDF is glossy and lights are large, so neither strategy fails alone. Prefer ReSTIR DI: Spatiotemporal Reservoir Resampling for Direct Lighting when there are thousands of lights and one sample per pixel. Prefer Bidirectional Path Tracing or Metropolis Light Transport when the shadow ray is blocked by glass and caustics matter. Plain Unidirectional Path Tracing without NEE is acceptable only for large, uniformly bright environments.
Field marks
- Double-counted emission when the BSDF-sampled bounce is allowed to add light already estimated by NEE
- Black shadows behind glass or water because shadow rays cannot pass through refractive materials
- Wrong pdf conversion between area and solid angle gives lights that are too bright or too dim by a distance-squared factor
- Poor light selection with many lights makes noise worse than uniform sampling in large scenes
- Light samples that cross the horizon of a shading normal produce negative or NaN contributions
Presets
Next-Event Estimation — blind BSDF light hits (left) vs explicit direct-light shadow rays (right)
{
"P_LIGHT_SIZE": 0.22,
"P_NOISE_GAIN": 1,
"P_BOUNCE_INT": 1.1,
"P_SPLIT": 0.48
}Show GLSL (138 lines)
const float P_LIGHT_SIZE = 0.22; // P Emitter Radius [0.08, 0.55, 0.02]
const float P_NOISE_GAIN = 1.0; // P BSDF Variance [0.2, 2.0, 0.05]
const float P_BOUNCE_INT = 1.1; // P Light Power [0.4, 2.2, 0.05]
const float P_SPLIT = 0.48; // P Blind / NEE 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);
}
vec2 hash22(vec2 p) {
vec3 p3 = fract(vec3(p.xyx) * vec3(0.1031, 0.1030, 0.0973));
p3 += dot(p3, p3.yzx + 33.33);
return fract((p3.xx + p3.yz) * p3.zy);
}
float sdBox(vec3 p, vec3 b) {
vec3 q = abs(p) - b;
return length(max(q, 0.0)) + min(max(q.x, max(q.y, q.z)), 0.0);
}
vec2 mapScene(vec3 p) {
vec2 res = vec2(p.y + 0.85, 1.0);
float dC = 1.0 - p.y; if (dC < res.x) res = vec2(dC, 1.0);
float dB = p.z + 1.45; if (dB < res.x) res = vec2(dB, 1.0);
float dL = p.x + 1.35; if (dL < res.x) res = vec2(dL, 1.0);
float dR = 1.35 - p.x; if (dR < res.x) res = vec2(dR, 1.0);
// Sculpted sphere + pedestal casting crisp penumbra from the small area light
float dSph = length(p - vec3(0.0, -0.35, -0.22)) - 0.36;
if (dSph < res.x) res = vec2(dSph, 2.0);
float dCol = sdBox(p - vec3(-0.62, -0.45, -0.58), vec3(0.22, 0.40, 0.22)) - 0.02;
if (dCol < res.x) res = vec2(dCol, 3.0);
float dCol2 = sdBox(p - vec3(0.66, -0.55, -0.45), vec3(0.24, 0.30, 0.24)) - 0.02;
if (dCol2 < res.x) res = vec2(dCol2, 3.0);
return res;
}
vec3 calcNormal(vec3 p) {
vec2 e = vec2(0.0022, 0.0);
return normalize(vec3(
mapScene(p + e.xyy).x - mapScene(p - e.xyy).x,
mapScene(p + e.yxy).x - mapScene(p - e.yxy).x,
mapScene(p + e.yyx).x - mapScene(p - e.yyx).x
));
}
float softShadow(vec3 ro, vec3 rd, float maxT, float k) {
float res = 1.0;
float t = 0.03;
for (int i = 0; i < 24; i++) {
float h = mapScene(ro + rd * t).x;
res = min(res, k * h / max(t, 1e-4));
t += clamp(h, 0.02, 0.18);
if (res < 0.01 || t > maxT) break;
}
return clamp(res, 0.0, 1.0);
}
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 isNEE = screenX >= split;
float lRad = clamp(P_LIGHT_SIZE, 0.07, 0.58);
float noiseGain = clamp(P_NOISE_GAIN, 0.15, 2.2);
float power = clamp(P_BOUNCE_INT, 0.3, 2.4);
vec3 lPos = vec3(0.32 * sin(iTime * 0.7), 0.96, -0.25);
vec3 ro = vec3(0.0, 0.04, 2.38);
vec3 rd = normalize(vec3(uv, -1.52));
vec3 col = vec3(0.02);
float t = 0.0;
float matId = 0.0;
bool hit = false;
for (int i = 0; i < 64; i++) {
vec2 h = mapScene(ro + rd * t);
if (h.x < 0.002) { hit = true; matId = h.y; break; }
t += h.x;
if (t > 9.0) break;
}
if (hit) {
vec3 p = ro + rd * t;
vec3 n = calcNormal(p);
if (p.y > 0.98 && length(p.xz - lPos.xz) < lRad) {
col = vec3(3.8, 3.3, 2.6) * power;
} else {
vec3 alb = vec3(0.68, 0.70, 0.74);
if (matId > 1.5 && matId < 2.5) alb = vec3(0.86, 0.56, 0.24);
if (matId > 2.5) alb = vec3(0.30, 0.62, 0.76);
vec3 lVec = lPos - p;
float lDist = length(lVec);
vec3 lDir = lVec / max(lDist, 1e-4);
float ndl = max(dot(n, lDir), 0.0);
float cosL = max(dot(vec3(0.0, -1.0, 0.0), -lDir), 0.0);
// Solid angle subtended by the small area light omega = A * cosL / d^2
float area = 3.1415926 * lRad * lRad;
float solidAngle = clamp(area * cosL / (lDist * lDist + 0.08), 0.004, 1.2);
float sh = softShadow(p + n * 0.012, lDir, lDist - 0.05, 2.2 / max(lRad, 0.08));
// Ground-truth direct illumination (constant total radiant power regardless of light radius)
vec3 directClean = alb * vec3(2.8, 2.45, 1.95) * power * ndl * cosL * sh / (lDist * lDist + 0.45);
vec3 amb = alb * vec3(0.08, 0.10, 0.13) * clamp(0.45 + 0.55 * mapScene(p + n * 0.24).x / 0.24, 0.2, 1.0);
if (!isNEE) {
// Left: Naive unguided BSDF sampling. Hit probability scales with solidAngle / pi!
// Smaller light => tiny hit chance => huge weight (1 / pHit) fireflies & mostly black pixels!
float pHit = clamp(solidAngle * 1.45 / max(noiseGain, 0.2), 0.04, 0.85);
vec2 rnd = hash22(floor(fragCoord * 0.8) + fract(iTime * 6.7) * 23.1);
float didHit = step(1.0 - pHit, rnd.x);
float estimator = didHit / max(pHit, 0.06);
float spike = pow(rnd.y, 4.0) * 1.8 * didHit / max(lRad * 3.0, 0.25);
col = amb + directClean * (estimator * 0.72 + spike * 0.35);
} else {
// Right: Explicit Next-Event Estimation shadow ray samples the emitter directly with low variance
float jitter = (hash21(floor(fragCoord) + fract(iTime * 3.1) * 17.0) - 0.5) * 0.06 * lRad;
col = amb + directClean * (1.0 + jitter);
}
}
}
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 |
|---|---|---|---|
| next-event-estimation-live | Tesla T4 1920x1080 | 35.9× baseline (heavy) · 1.11 ms / 1.20 ms | opengl-timer-query · 36 frames · GPU Weight Atlas · Colab T4 sweep |
| next-event-estimation-live | NVIDIA L4 1920x1080 | 37.1× baseline (heavy) · 0.590 ms / 0.602 ms · 1.9× faster on L4 | opengl-timer-query · Cross-architecture validation |
| next-event-estimation-live | NVIDIA A100-SXM4-40GB 1920x1080 | 22.4× baseline (heavy) · 0.645 ms / 0.647 ms · 1.7× faster on A100 | opengl-timer-query · Cross-architecture validation |
Lineage
Crosses
- Multiple Importance Sampling: NEE and BSDF sampling each estimate the direct term; MIS weights blend them so whichever strategy has the better pdf dominates.
- Light BVH and Adaptive Tree Splitting: Supplies the light-selection pdf so NEE scales to scenes with many emitters.
- Owen-scrambled Sobol and low-discrepancy sampling: Low-discrepancy points choose the light and surface sample per vertex, reducing the remaining variance.
Sources
- primaryMatt Pharr, Wenzel Jakob, Greg Humphreys. A Better Path Tracer. Physically Based Rendering 4th ed., 13.4.Verified via live page · 2026-11-29
- implementationmmp (2017). mmp/pbrt-v4. Source code to pbrt, the ray tracer described in the forthcoming 4th edition of the "Physically Based Rendering: From Theory to Implementation" book.GitHub API · license Apache-2.0 · 2026-11-29
- implementationNVIDIAGameWorks (2017). NVIDIAGameWorks/Falcor. Real-Time Rendering FrameworkGitHub API · license NOASSERTION · 2026-11-29