From b9c727e255173568c727032c490df79d1130815c Mon Sep 17 00:00:00 2001 From: Sergey Sharybin Date: Fri, 28 Feb 2025 10:42:29 +0100 Subject: [PATCH] Fix #135200: Linking linking artifacts with light trees Ensure that the light tree flattening code does not try to share node in cases when we need to modify its bit trail. Pull Request: https://projects.blender.org/blender/blender/pulls/135249 --- intern/cycles/scene/light.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/intern/cycles/scene/light.cpp b/intern/cycles/scene/light.cpp index 899ec6466d2..b474173ba1c 100644 --- a/intern/cycles/scene/light.cpp +++ b/intern/cycles/scene/light.cpp @@ -687,7 +687,8 @@ static std::pair light_tree_specialize_nodes_flatten( const uint64_t light_link_mask, const int depth, vector &knodes, - int &next_node_index) + int &next_node_index, + bool can_share = true) { assert(!node->is_instance()); @@ -703,7 +704,7 @@ static std::pair light_tree_specialize_nodes_flatten( node_index = next_node_index++; new_node.make_leaf(-1, 0); } - else if (node->light_link.shareable && node->light_link.shared_node_index != -1) { + else if (can_share && node->light_link.shareable && node->light_link.shared_node_index != -1) { /* Share subtree already built for another light link set. */ return std::make_pair(node->light_link.shared_node_index, node->measure); } @@ -755,8 +756,11 @@ static std::pair light_tree_specialize_nodes_flatten( only_node = left_node; } if (only_node) { + /* Can not share the node as its bit_skip will be modified. + * Also don't store shareable_index so other branches of the tree that do not skip any nodes + * do not share node created here. */ const auto [only_index, only_measure] = light_tree_specialize_nodes_flatten( - flatten, only_node, light_link_mask, depth + 1, knodes, next_node_index); + flatten, only_node, light_link_mask, depth + 1, knodes, next_node_index, false); assert(only_index != -1); knodes[only_index].bit_skip++;