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
This commit is contained in:
Alaska
2025-02-14 05:09:08 +01:00
committed by Alaska
parent 088262dfee
commit fee2f10208
3 changed files with 19 additions and 3 deletions

View File

@@ -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) {

View File

@@ -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) {

View File

@@ -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)