From 37fe41d7b78178a1ea7b1110d63c68ec51d2bb67 Mon Sep 17 00:00:00 2001 From: Weizhen Huang Date: Fri, 15 Mar 2024 18:31:24 +0100 Subject: [PATCH] Fix: Cycles NEE not excluding self intersection which resulted in bias when self intersection is excluded in forward scattering. Below is a comparison using principled BSDF with emission. NEE and MIS were much brighter. Pull Request: https://projects.blender.org/blender/blender/pulls/119440 --- intern/cycles/kernel/integrator/shade_surface.h | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/intern/cycles/kernel/integrator/shade_surface.h b/intern/cycles/kernel/integrator/shade_surface.h index bb50ccc9581..ecb2f84b0f9 100644 --- a/intern/cycles/kernel/integrator/shade_surface.h +++ b/intern/cycles/kernel/integrator/shade_surface.h @@ -280,6 +280,16 @@ ccl_device kernel_assert(ls.pdf != 0.0f); + const bool is_transmission = dot(ls.D, sd->N) < 0.0f; + + if (ls.prim != PRIM_NONE && ls.prim == sd->prim && ls.object == sd->object) { + /* Skip self intersection if light direction lies in the same hemisphere as the geometric + * normal. */ + if (dot(ls.D, is_transmission ? -sd->Ng : sd->Ng) > 0.0f) { + return; + } + } + /* Evaluate light shader. * * TODO: can we reuse sd memory? In theory we can move this after @@ -292,8 +302,6 @@ ccl_device Ray ray ccl_optional_struct_init; BsdfEval bsdf_eval ccl_optional_struct_init; - const bool is_transmission = dot(ls.D, sd->N) < 0.0f; - int mnee_vertex_count = 0; #ifdef __MNEE__ IF_KERNEL_FEATURE(MNEE)