From 49e89ce93387864d048d89e8d498e9f2e6b86e16 Mon Sep 17 00:00:00 2001 From: "Werner, Stefan" Date: Tue, 20 Oct 2026 10:03:43 +0200 Subject: [PATCH] Fix pathtracer double-counting ambient light Skip ambient lights in next-event estimation since they are already added when rays escape the scene. Fixes #491. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- tutorials/pathtracer/pathtracer_device.cpp | 2 ++ tutorials/pathtracer/pathtracer_device.ispc | 2 ++ 2 files changed, 4 insertions(+) diff --git a/tutorials/pathtracer/pathtracer_device.cpp b/tutorials/pathtracer/pathtracer_device.cpp index cb585587cc..9eabebac1b 100644 --- a/tutorials/pathtracer/pathtracer_device.cpp +++ b/tutorials/pathtracer/pathtracer_device.cpp @@ -1564,6 +1564,8 @@ Vec3fa renderPixelFunction(const TutorialData& data, float x, float y, RandomSam for (unsigned int i=0; inumLights; i++) { const Light* l = data.ispc_scene->lights[i]; + /* ambient light is already accounted for when rays escape */ + if (l->type == LIGHT_AMBIENT) continue; //Light_SampleRes ls = l->sample(l,dg,RandomSampler_get2D(sampler)); Light_SampleRes ls = Lights_sample(l,dg,RandomSampler_get2D(sampler)); if (ls.pdf <= 0.0f) continue; diff --git a/tutorials/pathtracer/pathtracer_device.ispc b/tutorials/pathtracer/pathtracer_device.ispc index 2b7fc04979..3ce6574966 100644 --- a/tutorials/pathtracer/pathtracer_device.ispc +++ b/tutorials/pathtracer/pathtracer_device.ispc @@ -1562,6 +1562,8 @@ Vec3f renderPixelFunction(const uniform TutorialData& data, float x, float y, Ra for (uniform unsigned int i=0; inumLights; i++) { const uniform Light* uniform l = data.ispc_scene->lights[i]; + /* ambient light is already accounted for when rays escape */ + if (l->type == LIGHT_AMBIENT) continue; //Light_SampleRes ls = l->sample(l,dg,RandomSampler_get2D(sampler)); Light_SampleRes ls = Lights_sample(l,dg,RandomSampler_get2D(sampler)); if (ls.pdf <= 0.0f) continue;