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)