[Bf-blender-cvs] [dfa5682dce2] soc-2022-many-lights-sampling: Fix bit trail construction and bit trail PDF calulations

Brecht Van Lommel noreply at git.blender.org
Mon Sep 12 20:19:07 CEST 2022


Commit: dfa5682dce20d87b7ca4e0367b377abf7e386a7f
Author: Brecht Van Lommel
Date:   Mon Sep 12 16:21:38 2022 +0200
Branches: soc-2022-many-lights-sampling
https://developer.blender.org/rBdfa5682dce20d87b7ca4e0367b377abf7e386a7f

Fix bit trail construction and bit trail PDF calulations

Contributed by Alaska.

Differential Revision: https://developer.blender.org/D15935

===================================================================

M	intern/cycles/kernel/light/light_tree.h
M	intern/cycles/scene/light_tree.cpp

===================================================================

diff --git a/intern/cycles/kernel/light/light_tree.h b/intern/cycles/kernel/light/light_tree.h
index 3f49b31cd51..6d5118117ec 100644
--- a/intern/cycles/kernel/light/light_tree.h
+++ b/intern/cycles/kernel/light/light_tree.h
@@ -626,13 +626,14 @@ ccl_device float light_tree_pdf(
     float left_probability = left_importance / (left_importance + right_importance);
 
     if (bit_trail & 1) {
-      stack[stack_index] = left_index;
-      pdfs[stack_index] = pdf * left_probability;
-    }
-    else {
       stack[stack_index] = right_index;
       pdfs[stack_index] = pdf * (1.0f - left_probability);
     }
+    else {
+      stack[stack_index] = left_index;
+      pdfs[stack_index] = pdf * left_probability;
+    }
+    bit_trail = bit_trail >> 1;
   }
 
   pdf *= light_leaf_pdf * light_tree_pdf * target_weight / total_weight;
diff --git a/intern/cycles/scene/light_tree.cpp b/intern/cycles/scene/light_tree.cpp
index bda49822680..fc11d93a080 100644
--- a/intern/cycles/scene/light_tree.cpp
+++ b/intern/cycles/scene/light_tree.cpp
@@ -395,7 +395,7 @@ LightTreeBuildNode *LightTree::recursive_build(vector<LightTreePrimitiveInfo> &p
                                                        end,
                                                        total_nodes,
                                                        ordered_prims,
-                                                       bit_trail | (1u << bit_trail),
+                                                       bit_trail | (1u << depth),
                                                        depth + 1);
       node->init_interior(left_node, right_node);
     }
@@ -539,4 +539,4 @@ int LightTree::flatten_tree(const LightTreeBuildNode *node, int &offset, int par
   return current_index;
 }
 
-CCL_NAMESPACE_END
\ No newline at end of file
+CCL_NAMESPACE_END



More information about the Bf-blender-cvs mailing list