[Bf-blender-cvs] [31de7719b86] soc-2020-production-ready-light-tree: Fixed bug when not using light tree from merge.

Sam Kottler noreply at git.blender.org
Tue Jun 9 16:50:08 CEST 2020


Commit: 31de7719b86db19a07fa66bc3918804fc3d535be
Author: Sam Kottler
Date:   Tue Jun 9 08:25:10 2020 -0600
Branches: soc-2020-production-ready-light-tree
https://developer.blender.org/rB31de7719b86db19a07fa66bc3918804fc3d535be

Fixed bug when not using light tree from merge.

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

M	intern/cycles/kernel/kernel_light.h
M	intern/cycles/kernel/kernel_path_surface.h
M	intern/cycles/kernel/kernel_path_volume.h
M	intern/cycles/kernel/split/kernel_direct_lighting.h
M	intern/cycles/render/light.cpp

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

diff --git a/intern/cycles/kernel/kernel_light.h b/intern/cycles/kernel/kernel_light.h
index f2cebbe4f23..cea1656ede6 100644
--- a/intern/cycles/kernel/kernel_light.h
+++ b/intern/cycles/kernel/kernel_light.h
@@ -1768,6 +1768,7 @@ ccl_device void light_distribution_sample(
 
 /* picks a point on a given light and computes the probability of picking this point*/
 ccl_device void light_point_sample(KernelGlobals *kg,
+                                   int lamp,
                                    float randu,
                                    float randv,
                                    float time,
@@ -1776,36 +1777,38 @@ ccl_device void light_point_sample(KernelGlobals *kg,
                                    int distribution_id,
                                    LightSample *ls)
 {
-  /* fetch light data and compute rest of light pdf */
-  const ccl_global KernelLightDistribution *kdistribution = &kernel_tex_fetch(__light_distribution,
-                                                                              distribution_id);
-  int prim = kdistribution->prim;
-
-  if (prim >= 0) {
-    int object = kdistribution->mesh_light.object_id;
-    int shader_flag = kdistribution->mesh_light.shader_flag;
+  if (lamp < 0) {
+    /* fetch light data and compute rest of light pdf */
+    const ccl_global KernelLightDistribution *kdistribution = &kernel_tex_fetch(
+        __light_distribution, distribution_id);
+    int prim = kdistribution->prim;
 
-    triangle_light_sample(kg, prim, object, randu, randv, time, ls, P);
-    ls->shader |= shader_flag;
-  }
-  else {
-    int lamp = -prim - 1;
+    if (prim >= 0) {
+      int object = kdistribution->mesh_light.object_id;
+      int shader_flag = kdistribution->mesh_light.shader_flag;
 
-    if (UNLIKELY(light_select_reached_max_bounces(kg, lamp, bounce))) {
-      ls->pdf = 0.0f;
+      triangle_light_sample(kg, prim, object, randu, randv, time, ls, P);
+      ls->shader |= shader_flag;
       return;
     }
+    lamp = -prim - 1;
+  }
 
-    if (!lamp_light_sample(kg, lamp, randu, randv, P, ls)) {
-      ls->pdf = 0.0f;
-      return;
-    }
+  if (UNLIKELY(light_select_reached_max_bounces(kg, lamp, bounce))) {
+    ls->pdf = 0.0f;
+    return;
+  }
+
+  if (!lamp_light_sample(kg, lamp, randu, randv, P, ls)) {
+    ls->pdf = 0.0f;
+    return;
   }
 }
 
 /* picks a light and then picks a point on the light and computes the
  * probability of doing so. */
 ccl_device_noinline bool light_sample(KernelGlobals *kg,
+                                      int lamp,
                                       float randu,
                                       float randv,
                                       float time,
@@ -1825,7 +1828,7 @@ ccl_device_noinline bool light_sample(KernelGlobals *kg,
   }
 
   /* pick a point on the light and the probability of picking this point */
-  light_point_sample(kg, randu, randv, time, P, bounce, index, ls);
+  light_point_sample(kg, lamp, randu, randv, time, P, bounce, index, ls);
 
   /* combine pdfs */
   ls->pdf *= pdf_factor;
diff --git a/intern/cycles/kernel/kernel_path_surface.h b/intern/cycles/kernel/kernel_path_surface.h
index 98a20b12c75..9047d57ee16 100644
--- a/intern/cycles/kernel/kernel_path_surface.h
+++ b/intern/cycles/kernel/kernel_path_surface.h
@@ -116,7 +116,7 @@ ccl_device void accum_light_tree_contribution(KernelGlobals *kg,
     /* pick a point on the chosen light(distribution_id) and calculate the
      * probability of picking this point */
     LightSample ls;
-    light_point_sample(kg, randu, randv, time, P, bounce, distribution_id, &ls);
+    light_point_sample(kg, -1, randu, randv, time, P, bounce, distribution_id, &ls);
 
     /* combine pdfs */
     ls.pdf *= pdf_factor;
@@ -292,7 +292,7 @@ ccl_device_noinline_cpu void kernel_branched_path_surface_connect_light(
 
     /* sample a point on the given distant/background light */
     LightSample ls;
-    light_point_sample(kg, randu, randv, sd->time, sd->P, state->bounce, index, &ls);
+    light_point_sample(kg, -1, randu, randv, sd->time, sd->P, state->bounce, index, &ls);
 
     /* combine pdfs */
     ls.pdf *= group_prob;
@@ -315,10 +315,10 @@ ccl_device_noinline_cpu void kernel_branched_path_surface_connect_light(
                              throughput,
                              num_samples_adjust);
   }
-  else if (!use_light_tree) {
+  else {
     int num_lights = 0;
     if (kernel_data.integrator.use_direct_light) {
-      if (sample_all_lights) {
+      if (sample_all_lights && !use_light_tree) {
         num_lights = kernel_data.integrator.num_all_lights;
         if (kernel_data.integrator.pdf_triangles != 0.0f) {
           num_lights += 1;
@@ -332,13 +332,12 @@ ccl_device_noinline_cpu void kernel_branched_path_surface_connect_light(
     for (int i = 0; i < num_lights; i++) {
       /* sample one light at random */
       int num_samples = 1;
-      int num_all_lights = 1;
       uint lamp_rng_hash = state->rng_hash;
       bool double_pdf = false;
       bool is_mesh_light = false;
       bool is_lamp = false;
 
-      if (sample_all_lights) {
+      if (sample_all_lights && !use_light_tree) {
         /* lamp sampling */
         is_lamp = i < kernel_data.integrator.num_all_lights;
         if (is_lamp) {
@@ -346,7 +345,6 @@ ccl_device_noinline_cpu void kernel_branched_path_surface_connect_light(
             continue;
           }
           num_samples = ceil_to_int(num_samples_adjust * light_select_num_samples(kg, i));
-          num_all_lights = kernel_data.integrator.num_all_lights;
           lamp_rng_hash = cmj_hash(state->rng_hash, i);
           double_pdf = kernel_data.integrator.pdf_triangles != 0.0f;
         }
@@ -367,7 +365,6 @@ ccl_device_noinline_cpu void kernel_branched_path_surface_connect_light(
 #    ifdef __OBJECT_MOTION__
         light_ray.time = sd->time;
 #    endif
-        bool has_emission = false;
         float light_u, light_v;
         float terminate;
 
@@ -383,7 +380,9 @@ ccl_device_noinline_cpu void kernel_branched_path_surface_connect_light(
           }
 
           LightSample ls ccl_optional_struct_init;
+          const int lamp = is_lamp ? i : -1;
           if (light_sample(kg,
+                           lamp,
                            light_u,
                            light_v,
                            sd->time,
@@ -398,26 +397,6 @@ ccl_device_noinline_cpu void kernel_branched_path_surface_connect_light(
             if (double_pdf) {
               ls.pdf *= 2.0f;
             }
-            has_emission = direct_emission(
-                kg, sd, emission_sd, &ls, state, &light_ray, &L_light, &is_lamp, terminate);
-          }
-        }
-
-        /* trace shadow ray */
-        float3 shadow;
-
-        if (has_emission) {
-          /* accumulate */
-          LightSample ls;
-          if (light_sample(kg,
-                           light_u,
-                           light_v,
-                           sd->time,
-                           sd->P_pick,
-                           sd->N_pick,
-                           state->bounce,
-                           &ls,
-                           false)) {
             accum_light_contribution(kg,
                                      sd,
                                      emission_sd,
@@ -542,6 +521,7 @@ ccl_device_inline void kernel_path_surface_connect_light(KernelGlobals *kg,
 
     LightSample ls ccl_optional_struct_init;
     if (light_sample(kg,
+                     -1,
                      light_u,
                      light_v,
                      sd->time,
diff --git a/intern/cycles/kernel/kernel_path_volume.h b/intern/cycles/kernel/kernel_path_volume.h
index c27f1e68a3d..3546ebc0c4c 100644
--- a/intern/cycles/kernel/kernel_path_volume.h
+++ b/intern/cycles/kernel/kernel_path_volume.h
@@ -43,8 +43,16 @@ ccl_device_inline void kernel_path_volume_connect_light(KernelGlobals *kg,
     path_state_rng_2D(kg, state, PRNG_LIGHT_U, &light_u, &light_v);
 
     LightSample ls ccl_optional_struct_init;
-    if (light_sample(
-            kg, light_u, light_v, sd->time, sd->P_pick, sd->N_pick, state->bounce, &ls, true)) {
+    if (light_sample(kg,
+                     -1,
+                     light_u,
+                     light_v,
+                     sd->time,
+                     sd->P_pick,
+                     sd->N_pick,
+                     state->bounce,
+                     &ls,
+                     true)) {
       float terminate = path_state_rng_light_termination(kg, state);
       has_emission = direct_emission(
           kg, sd, emission_sd, &ls, state, &light_ray, &L_light, &is_lamp, terminate);
@@ -141,169 +149,131 @@ ccl_device void kernel_branched_path_volume_connect_light(KernelGlobals *kg,
 {
 #    ifdef __EMISSION__
   BsdfEval L_light ccl_optional_struct_init;
-  if (sample_all_lights && !kernel_data.integrator.use_light_tree) {
-    int num_lights = 1;
-    if (sample_all_lights) {
-      num_lights = kernel_data.integrator.num_all_lights;
-      if (kernel_data.integrator.pdf_triangles != 0.0f) {
-        num_lights += 1;
-      }
+  bool use_light_tree = kernel_data.integrator.use_light_tree;
+  int num_lights = 1;
+  if (sample_all_lights && !use_light_tree) {
+    num_lights = kernel_data.integrator.num_all_lights;
+    if (kernel_data.integrator.pdf_triangles != 0.0f) {
+      num_lights += 1;
     }
-    for (int i = 0; i < num_lights; ++i) {
-      /* sample one light at random */
-      int num_samples = 1;
-      int num_all_lights = 1;
-      uint lamp_rng_hash = state->rng_hash;
-      bool double_pdf = false;
-      bool is_mesh_light = false;
-      bool is_lamp = false;
-
-      if (sample_all_lights) {
-        /* lamp sampling */
-        is_lamp = i < kernel_data.integrator.num_all_lights;
-        if (is_lamp) {
-          if (UNLIKELY(light_select_reached_max_bounces(kg, i, state->bounce))) {
-            continue;
-          }
-          num_samples = light_select_num_samples(kg, i);
-          num_all_lights = kernel_data.integrator.num_all_lights;
-          lamp_rng_hash = cmj_hash(state->rng_hash, i);
-          double_pdf = kernel_data.integrator.pdf_triangles != 0.0f;
-        }
-        /* m

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list