From fee2f10208d3d215b640369ae96563f0a4edbef8 Mon Sep 17 00:00:00 2001 From: Alaska Date: Fri, 14 Feb 2025 05:09:08 +0100 Subject: [PATCH] Fix: Incorrect ray depth on emission in Cycles OSL This commit fixes a issue where ray depth for emissive objects (E.g. Lights) was incorrect when using the ray depth output of the light path node in Cycles OSL. Pull Request: https://projects.blender.org/blender/blender/pulls/134496 --- intern/cycles/kernel/osl/services.cpp | 10 +++++++++- intern/cycles/kernel/osl/services_gpu.h | 10 +++++++++- intern/cycles/kernel/svm/light_path.h | 2 +- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/intern/cycles/kernel/osl/services.cpp b/intern/cycles/kernel/osl/services.cpp index cfc659c5dfd..b59df54beec 100644 --- a/intern/cycles/kernel/osl/services.cpp +++ b/intern/cycles/kernel/osl/services.cpp @@ -1028,7 +1028,15 @@ bool OSLRenderServices::get_background_attribute( if (name == u_path_ray_depth) { /* Ray Depth */ - const int f = READ_PATH_STATE(bounce); + int f = READ_PATH_STATE(bounce); + + /* Read bounce from different locations depending on if this is a shadow path. For background, + * light emission and shadow evaluation from a surface or volume we are effectively one bounce + * further. */ + if (globals->raytype & (PATH_RAY_SHADOW | PATH_RAY_EMISSION)) { + f += 1; + } + return set_attribute_int(f, type, derivatives, val); } if (name == u_path_diffuse_depth) { diff --git a/intern/cycles/kernel/osl/services_gpu.h b/intern/cycles/kernel/osl/services_gpu.h index 34bfdef218d..8821d8d2ef4 100644 --- a/intern/cycles/kernel/osl/services_gpu.h +++ b/intern/cycles/kernel/osl/services_gpu.h @@ -1082,7 +1082,15 @@ ccl_device_inline bool get_background_attribute(KernelGlobals kg, if (name == DeviceStrings::u_path_ray_depth) { /* Ray Depth */ - const int f = READ_PATH_STATE(bounce); + int f = READ_PATH_STATE(bounce); + + /* Read bounce from different locations depending on if this is a shadow path. For background, + * light emission and shadow evaluation from a surface or volume we are effectively one bounce + * further. */ + if (sg->raytype & (PATH_RAY_SHADOW | PATH_RAY_EMISSION)) { + f += 1; + } + return set_attribute_int(f, type, derivatives, val); } if (name == DeviceStrings::u_path_diffuse_depth) { diff --git a/intern/cycles/kernel/svm/light_path.h b/intern/cycles/kernel/svm/light_path.h index ebc88f01ca6..72c03e85507 100644 --- a/intern/cycles/kernel/svm/light_path.h +++ b/intern/cycles/kernel/svm/light_path.h @@ -53,7 +53,7 @@ ccl_device_noinline void svm_node_light_path(KernelGlobals kg, info = sd->ray_length; break; case NODE_LP_ray_depth: { - /* Read bounce from difference location depending if this is a shadow + /* Read bounce from different locations depending on if this is a shadow * path. It's a bit dubious to have integrate state details leak into * this function but hard to avoid currently. */ IF_KERNEL_NODES_FEATURE(LIGHT_PATH)