[Bf-blender-cvs] [1d22a45de0f] soc-2022-many-lights-sampling: Cycles: set pdf_lights based on light sampling

Jeffrey Liu noreply at git.blender.org
Fri Jun 17 09:14:54 CEST 2022


Commit: 1d22a45de0fc7d499b73d7e0fb02e851cf048316
Author: Jeffrey Liu
Date:   Fri Jun 17 03:14:45 2022 -0400
Branches: soc-2022-many-lights-sampling
https://developer.blender.org/rB1d22a45de0fc7d499b73d7e0fb02e851cf048316

Cycles: set pdf_lights based on light sampling

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

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

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

diff --git a/intern/cycles/kernel/light/light_tree.h b/intern/cycles/kernel/light/light_tree.h
index 4d62365d23e..7cff13b7c97 100644
--- a/intern/cycles/kernel/light/light_tree.h
+++ b/intern/cycles/kernel/light/light_tree.h
@@ -169,15 +169,6 @@ ccl_device bool light_tree_sample(KernelGlobals kg,
     }
   }
 
-  /* Special case where there's only a single light. */
-  if (knode->num_prims == 1) {
-    if (UNLIKELY(light_select_reached_max_bounces(kg, -knode->child_index, bounce))) {
-      return false;
-    }
-    return light_sample<in_volume_segment>(
-        kg, -knode->child_index, randu, randv, P, path_flag, ls);
-  }
-
   /* Right now, sampling is done by incrementing the CDF by the PDF.
    * However, we first need to calculate the total importance so that we can normalize the CDF. */
   float total_emitter_importance = 0.0f;
@@ -196,15 +187,12 @@ ccl_device bool light_tree_sample(KernelGlobals kg,
   float emitter_cdf = 0.0f;
   for (int i = 0; i < knode->num_prims; i++) {
     const int prim_index = -knode->child_index + i;
-    /* to-do: is there any way to cache these values, so that recalculation isn't needed?
-     * At the very least, we can maybe store the total importance during light tree construction
-     * so that the first for loop isn't necessary. */
+    /* to-do: is there any way to cache these values, so that recalculation isn't needed? */
     const float emitter_pdf = light_tree_emitter_importance(kg, P, N, prim_index) *
                               inv_total_importance;
     emitter_cdf += emitter_pdf;
     if (tree_u < emitter_cdf) {
       *pdf_factor *= emitter_pdf;
-      assert(*pdf_factor != 0.0f);
       if (UNLIKELY(light_select_reached_max_bounces(kg, prim_index, bounce))) {
         return false;
       }
diff --git a/intern/cycles/scene/light.cpp b/intern/cycles/scene/light.cpp
index 3a6d43aa8e9..86a235815c7 100644
--- a/intern/cycles/scene/light.cpp
+++ b/intern/cycles/scene/light.cpp
@@ -532,16 +532,24 @@ void LightManager::device_update_distribution(Device *,
     /* to-do: this pdf is probably going to need adjustment if a light tree is used. */
     kintegrator->num_all_lights = num_lights;
 
-    if (trianglearea > 0.0f) {
-      kintegrator->pdf_triangles = 1.0f / trianglearea;
-      if (num_lights)
-        kintegrator->pdf_triangles *= 0.5f;
+    /* pdf_lights is used when sampling lights, and assumes that
+     * the light has been sampled through the light distribution.
+     * Therefore, we override it for now and adjust the pdf manually in the light tree.*/
+    if (scene->integrator->get_use_light_tree()) {
+      kintegrator->pdf_lights = 1.0f;
     }
+    else {
+      if (trianglearea > 0.0f) {
+        kintegrator->pdf_triangles = 1.0f / trianglearea;
+        if (num_lights)
+          kintegrator->pdf_triangles *= 0.5f;
+      }
 
-    if (num_lights) {
-      kintegrator->pdf_lights = 1.0f / num_lights;
-      if (trianglearea > 0.0f)
-        kintegrator->pdf_lights *= 0.5f;
+      if (num_lights) {
+        kintegrator->pdf_lights = 1.0f / num_lights;
+        if (trianglearea > 0.0f)
+          kintegrator->pdf_lights *= 0.5f;
+      }
     }
 
     kintegrator->use_lamp_mis = use_lamp_mis;



More information about the Bf-blender-cvs mailing list