From 5ce4e91a80c41ab9c76d40c95e4f82ec0bf51767 Mon Sep 17 00:00:00 2001 From: Sergey Sharybin Date: Sat, 22 Mar 2025 04:51:42 +0100 Subject: [PATCH] Fix #136319: Incorrect transparent bounce count with spatial splits The transparent bounce test was too optimistic in regards to the intersection being considered. The check needs to happen after it has been validated that it is not duplicate. It was already the case for Metal and HIP-RT, but not for Embree and BVH2. Tests updated by: Alaska Pull Request: https://projects.blender.org/blender/blender/pulls/136325 --- intern/cycles/kernel/bvh/shadow_all.h | 15 ++++++++------- intern/cycles/kernel/device/cpu/bvh.h | 6 +++++- tests/data | 2 +- 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/intern/cycles/kernel/bvh/shadow_all.h b/intern/cycles/kernel/bvh/shadow_all.h index bb927ec37be..67372a578b0 100644 --- a/intern/cycles/kernel/bvh/shadow_all.h +++ b/intern/cycles/kernel/bvh/shadow_all.h @@ -222,14 +222,12 @@ ccl_device_inline /* shadow ray early termination */ if (hit) { - /* detect if this surface has a shader with transparent shadows */ - /* todo: optimize so primitive visibility flag indicates if - * the primitive has a transparent shadow shader? */ + /* Detect if this surface has a shader with transparent shadows. */ + /* TODO: optimize so primitive visibility flag indicates if the primitive has a + * transparent shadow shader? */ const int flags = intersection_get_shader_flags(kg, isect.prim, isect.type); - - if (!(flags & SD_HAS_TRANSPARENT_SHADOW) || num_hits >= max_hits) { - /* If no transparent shadows, all light is blocked and we can - * stop immediately. */ + if ((flags & SD_HAS_TRANSPARENT_SHADOW) == 0) { + /* If no transparent shadows, all light is blocked and we can stop immediately. */ return true; } @@ -244,6 +242,9 @@ ccl_device_inline } num_hits++; + if (num_hits > max_hits) { + return true; + } bool record_intersection = true; diff --git a/intern/cycles/kernel/device/cpu/bvh.h b/intern/cycles/kernel/device/cpu/bvh.h index 2dd576351e2..366b24b0a6e 100644 --- a/intern/cycles/kernel/device/cpu/bvh.h +++ b/intern/cycles/kernel/device/cpu/bvh.h @@ -345,7 +345,7 @@ ccl_device_forceinline void kernel_embree_filter_occluded_shadow_all_func_impl( /* If no transparent shadows or max number of hits exceeded, all light is blocked. */ const int flags = intersection_get_shader_flags(kg, current_isect.prim, current_isect.type); - if (!(flags & (SD_HAS_TRANSPARENT_SHADOW)) || ctx->num_hits >= ctx->max_hits) { + if ((flags & SD_HAS_TRANSPARENT_SHADOW) == 0) { ctx->opaque_hit = true; return; } @@ -358,6 +358,10 @@ ccl_device_forceinline void kernel_embree_filter_occluded_shadow_all_func_impl( } ++ctx->num_hits; + if (ctx->num_hits > ctx->max_hits) { + ctx->opaque_hit = true; + return; + } /* Always use baked shadow transparency for curves. */ if (current_isect.type & PRIMITIVE_CURVE) { diff --git a/tests/data b/tests/data index 90bc81396bb..dd2adcac331 160000 --- a/tests/data +++ b/tests/data @@ -1 +1 @@ -Subproject commit 90bc81396bb52e494715ffd2a90aaa11ca2b2ca6 +Subproject commit dd2adcac331b60ae026ca6711dd1cbec9c20c10a