---
id: "next-event-estimation"
title: "Next-event estimation (direct light sampling)"
aliases: [NEE, direct lighting sampling, explicit light sampling, shadow rays]
domain: "gi"
stage: "lighting"
realtime: "interactive"
platforms: [cuda, desktop-gpu, cpu, blender, webgpu, python]
year_introduced: 1996
inputs: [mesh, material-params]
outputs: [radiance]
style: "photoreal"
dynamic: "both"
cost: "medium"
authority: "Pharr et al."
url: "https://texelatlas.vercel.app/t/next-event-estimation/"
sources_verified_at: "2026-11-29"
---
# Next-event estimation (direct light sampling) (Pharr et al.)

> 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.

## 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

## 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](multiple-importance-sampling) weights. The light is chosen by area, power or, with many lights, by a hierarchy ([light-bvh-many-lights](light-bvh-many-lights)); 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 use 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](multiple-importance-sampling) on top of it when the BSDF is glossy and lights are large, so neither strategy fails alone. Prefer [restir-di](restir-di) when there are thousands of lights and one sample per pixel. Prefer [bidirectional-path-tracing](bidirectional-path-tracing) or [metropolis-light-transport](metropolis-light-transport) when the shadow ray is blocked by glass and caustics matter. Plain [path-tracing](path-tracing) without NEE is acceptable only for large, uniformly bright environments.

## Cost

medium — One extra shadow ray and BSDF evaluation per path vertex; usually far cheaper than the variance it removes.
Measured GPU Weight: 35.89× baseline (heavy) — 1.1127 ms median / 1.1983 ms p95 on Tesla T4/PCIe/SSE2 @ 1920x1080 (opengl-timer-query).
Ada L4 scaling: 37.13× baseline (heavy) — 0.5903 ms median (1.88× faster on L4).
Ampere A100 scaling: 22.41× baseline (heavy) — 0.6455 ms median (1.72× faster on A100).

## Failure modes

- 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

## Engine support

- blender: builtin — `Cycles samples lights directly by default; Light > Multiple Importance Sample` (evidence: https://docs.blender.org/manual/en/5.2/render/cycles/light_settings.html, checked 2026-12-01) — Always on in Cycles; MIS is a toggle.
- unity: builtin — `HDRP Volume > Add Override > Ray Tracing > Path Tracing (PathTracingSurface.hlsl runs SampleLights direct-light shadow queries with MIS)` (evidence: https://github.com/Unity-Technologies/Graphics/blob/557f6ac22b948284f57ffae6a789751fd1f63620/Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/PathTracing/Shaders/PathTracingSurface.hlsl, checked 2026-12-01) — HDRP-only path tracer.
- unreal: builtin — `Path Tracer direct light sampling / multiple importance sampling` (evidence: https://dev.epicgames.com/documentation/en-us/unreal-engine/path-tracer-in-unreal-engine, checked 2026-12-01)

## Dataflow

- Inputs: mesh, material-params
- Outputs: radiance
- Platforms: cuda, desktop-gpu, cpu, blender, webgpu, python

## Presets

### Next-Event Estimation — blind BSDF light hits (left) vs explicit direct-light shadow rays (right) (glsl-fragment; rendered 2026-11-30)

```json
{
  "P_LIGHT_SIZE": 0.22,
  "P_NOISE_GAIN": 1,
  "P_BOUNCE_INT": 1.1,
  "P_SPLIT": 0.48
}
```

```glsl
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.

## Lineage

- extends [Unidirectional Path Tracing](https://texelatlas.vercel.app/t/path-tracing.md)
- extended by [Manifold Next-Event Estimation and Specular Manifold Sampling](https://texelatlas.vercel.app/t/manifold-next-event-estimation.md)

## Combines with

- [Multiple Importance Sampling](https://texelatlas.vercel.app/t/multiple-importance-sampling.md): 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](https://texelatlas.vercel.app/t/light-bvh-many-lights.md): Supplies the light-selection pdf so NEE scales to scenes with many emitters.
- [Owen-scrambled Sobol and low-discrepancy sampling](https://texelatlas.vercel.app/t/owen-scrambled-sobol-sampling.md): Low-discrepancy points choose the light and surface sample per vertex, reducing the remaining variance.

## Sources

1. [primary] Matt Pharr, Wenzel Jakob, Greg Humphreys A Better Path Tracer. Physically Based Rendering 4th ed., 13.4. https://pbr-book.org/4ed/Light_Transport_I_Surface_Reflection/A_Better_Path_Tracer (verified via http on 2026-11-29)
2. [implementation] mmp (2017) mmp/pbrt-v4. https://github.com/mmp/pbrt-v4 License: Apache-2.0. (verified via github on 2026-11-29)
3. [implementation] NVIDIAGameWorks (2017) NVIDIAGameWorks/Falcor. https://github.com/NVIDIAGameWorks/Falcor License: NOASSERTION. (verified via github on 2026-11-29)

## Cite this entry

Texel. "Next-event estimation (direct light sampling)." https://texelatlas.vercel.app/t/next-event-estimation/ (accessed 2026-12-01).
