[Bf-blender-cvs] [0484d5ca5b1] soc-2022-many-lights-sampling: Merge branch 'master' into soc-2022-many-lights-sampling

Jeffrey Liu noreply at git.blender.org
Sun Sep 4 00:10:50 CEST 2022


Commit: 0484d5ca5b17cece7f4cd55156a128c13de32bb5
Author: Jeffrey Liu
Date:   Sat Sep 3 17:10:34 2022 -0500
Branches: soc-2022-many-lights-sampling
https://developer.blender.org/rB0484d5ca5b17cece7f4cd55156a128c13de32bb5

Merge branch 'master' into soc-2022-many-lights-sampling

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



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

diff --cc intern/cycles/blender/sync.cpp
index 3e46e668d3a,fe16f19556e..02889c9c6a0
--- a/intern/cycles/blender/sync.cpp
+++ b/intern/cycles/blender/sync.cpp
@@@ -342,15 -342,8 +342,15 @@@ void BlenderSync::sync_integrator(BL::V
  
    integrator->set_light_sampling_threshold(get_float(cscene, "light_sampling_threshold"));
  
 +  integrator->set_use_light_tree(get_boolean(cscene, "use_light_tree"));
 +  integrator->set_splitting_threshold(get_float(cscene, "splitting_threshold"));
 +
 +  if (integrator->use_light_tree_is_modified()) {
 +    scene->light_manager->tag_update(scene, LightManager::UPDATE_ALL);
 +  }
 +
    SamplingPattern sampling_pattern = (SamplingPattern)get_enum(
-       cscene, "sampling_pattern", SAMPLING_NUM_PATTERNS, SAMPLING_PATTERN_SOBOL);
+       cscene, "sampling_pattern", SAMPLING_NUM_PATTERNS, SAMPLING_PATTERN_PMJ);
    integrator->set_sampling_pattern(sampling_pattern);
  
    int samples = 1;
diff --cc intern/cycles/kernel/integrator/shade_background.h
index c5beda0a5ec,30ce0999258..041a8df8e9d
--- a/intern/cycles/kernel/integrator/shade_background.h
+++ b/intern/cycles/kernel/integrator/shade_background.h
@@@ -3,10 -3,11 +3,12 @@@
  
  #pragma once
  
- #include "kernel/film/accumulate.h"
- #include "kernel/integrator/shader_eval.h"
+ #include "kernel/film/light_passes.h"
+ 
+ #include "kernel/integrator/surface_shader.h"
+ 
  #include "kernel/light/light.h"
 +#include "kernel/light/light_tree.h"
  #include "kernel/light/sample.h"
  
  CCL_NAMESPACE_BEGIN
@@@ -122,13 -98,33 +99,37 @@@ ccl_device_inline void integrate_backgr
  #endif /* __MNEE__ */
  
    /* Evaluate background shader. */
-   Spectrum L = (eval_background) ? integrator_eval_background_shader(kg, state, render_buffer) :
-                                    zero_spectrum();
+   Spectrum L = zero_spectrum();
+ 
+   if (eval_background) {
+     L = integrator_eval_background_shader(kg, state, render_buffer);
+ 
+     /* When using the ao bounces approximation, adjust background
+      * shader intensity with ao factor. */
+     if (path_state_ao_bounce(kg, state)) {
+       L *= kernel_data.integrator.ao_bounces_factor;
+     }
  
-   /* When using the ao bounces approximation, adjust background
-    * shader intensity with ao factor. */
-   if (path_state_ao_bounce(kg, state)) {
-     L *= kernel_data.integrator.ao_bounces_factor;
+     /* Background MIS weights. */
+     float mis_weight = 1.0f;
+     /* Check if background light exists or if we should skip pdf. */
+     if (!(INTEGRATOR_STATE(state, path, flag) & PATH_RAY_MIS_SKIP) &&
+         kernel_data.background.use_mis) {
+       const float3 ray_P = INTEGRATOR_STATE(state, ray, P);
+       const float3 ray_D = INTEGRATOR_STATE(state, ray, D);
+       const float mis_ray_pdf = INTEGRATOR_STATE(state, path, mis_ray_pdf);
+ 
+       /* multiple importance sampling, get background light pdf for ray
+        * direction, and compute weight with respect to BSDF pdf */
+       const float pdf = background_light_pdf(kg, ray_P, ray_D);
++      if (kernel_data.integrator.use_light_tree) {
++        const float3 N = INTEGRATOR_STATE(state, path, mis_origin_n);
++        pdf *= distant_lights_pdf(kg, ray_P, N, kernel_data.background.light_index);
++      }
+       mis_weight = light_sample_mis_weight_forward(kg, mis_ray_pdf, pdf);
+     }
+ 
+     L *= mis_weight;
    }
  
    /* Write to render buffer. */
@@@ -184,13 -181,7 +186,12 @@@ ccl_device_inline void integrate_distan
          /* multiple importance sampling, get regular light pdf,
           * and compute weight with respect to BSDF pdf */
          const float mis_ray_pdf = INTEGRATOR_STATE(state, path, mis_ray_pdf);
 -        mis_weight = light_sample_mis_weight_forward(kg, mis_ray_pdf, ls.pdf);
 +        if (kernel_data.integrator.use_light_tree) {
 +          const float3 ray_P = INTEGRATOR_STATE(state, ray, P);
 +          const float3 N = INTEGRATOR_STATE(state, path, mis_origin_n);
 +          ls.pdf *= distant_lights_pdf(kg, ray_P, N, lamp);
 +        }
 +        const float mis_weight = light_sample_mis_weight_forward(kg, mis_ray_pdf, ls.pdf);
-         light_eval *= mis_weight;
        }
  
        /* Write to render buffer. */
diff --cc intern/cycles/kernel/integrator/shade_surface.h
index 0b32680c017,c19f56a9b70..62eaf6b3882
--- a/intern/cycles/kernel/integrator/shade_surface.h
+++ b/intern/cycles/kernel/integrator/shade_surface.h
@@@ -127,25 -125,13 +126,21 @@@ ccl_device_forceinline void integrate_s
      /* Multiple importance sampling, get triangle light pdf,
       * and compute weight with respect to BSDF pdf. */
      float pdf = triangle_light_pdf(kg, sd, t);
 -    mis_weight = light_sample_mis_weight_forward(kg, bsdf_pdf, pdf);
 +    if (kernel_data.integrator.use_light_tree) {
 +      float3 ray_P = INTEGRATOR_STATE(state, ray, P);
 +      const float3 ray_D = INTEGRATOR_STATE(state, ray, D);
 +      const float3 N = INTEGRATOR_STATE(state, path, mis_origin_n);
 +      uint lookup_offset = kernel_data_fetch(object_lookup_offset, sd->object);
 +      uint prim_offset = kernel_data_fetch(object_prim_offset, sd->object);
 +      pdf *= light_tree_pdf(kg, state, ray_P, N, sd->prim - prim_offset + lookup_offset);
 +    }
 +    float mis_weight = light_sample_mis_weight_forward(kg, bsdf_pdf, pdf);
-     L *= mis_weight;
    }
  
-   const Spectrum throughput = INTEGRATOR_STATE(state, path, throughput);
-   kernel_accum_emission(
-       kg, state, throughput * L, render_buffer, object_lightgroup(kg, sd->object));
+   film_write_surface_emission(
+       kg, state, L, mis_weight, render_buffer, object_lightgroup(kg, sd->object));
  }
- #endif /* __EMISSION__ */
  
- #ifdef __EMISSION__
  /* Path tracing: sample point on light and evaluate light shader, then
   * queue shadow ray to be traced. */
  template<uint node_feature_mask>
@@@ -164,20 -150,11 +159,19 @@@ ccl_device_forceinline void integrate_s
    {
      const uint32_t path_flag = INTEGRATOR_STATE(state, path, flag);
      const uint bounce = INTEGRATOR_STATE(state, path, bounce);
-     float light_u, light_v;
-     path_state_rng_2D(kg, rng_state, PRNG_LIGHT_U, &light_u, &light_v);
+     const float2 rand_light = path_state_rng_2D(kg, rng_state, PRNG_LIGHT);
  
 -    if (!light_distribution_sample_from_position(
 -            kg, rand_light.x, rand_light.y, sd->time, sd->P, bounce, path_flag, &ls)) {
 -      return;
 +    if (kg->data.integrator.use_light_tree) {
 +      if (!light_tree_sample_from_position(
-               kg, rng_state, light_u, light_v, sd->time, sd->P, sd->N, bounce, path_flag, &ls)) {
++              kg, rng_state, rand_light.x, rand_light.y, sd->time, sd->P, sd->N, bounce, path_flag, &ls)) {
 +        return;
 +      }
 +    }
 +    else {
 +      if (!light_distribution_sample_from_position(
-               kg, light_u, light_v, sd->time, sd->P, bounce, path_flag, &ls)) {
++              kg, rand_light.x, rand_light.y, sd->time, sd->P, bounce, path_flag, &ls)) {
 +        return;
 +      }
      }
    }
  
diff --cc intern/cycles/scene/integrator.cpp
index 0ff6e32ca66,e9cd753854f..4b9263541e7
--- a/intern/cycles/scene/integrator.cpp
+++ b/intern/cycles/scene/integrator.cpp
@@@ -86,14 -85,10 +85,13 @@@ NODE_DEFINE(Integrator
  
    SOCKET_FLOAT(light_sampling_threshold, "Light Sampling Threshold", 0.01f);
  
 +  SOCKET_BOOLEAN(use_light_tree, "Use light tree to optimize many light sampling", false);
 +  SOCKET_FLOAT(splitting_threshold, "Splitting threshold", 0.85f);
 +
    static NodeEnum sampling_pattern_enum;
-   sampling_pattern_enum.insert("sobol", SAMPLING_PATTERN_SOBOL);
-   sampling_pattern_enum.insert("pmj", SAMPLING_PATTERN_PMJ);
    sampling_pattern_enum.insert("sobol_burley", SAMPLING_PATTERN_SOBOL_BURLEY);
-   SOCKET_ENUM(sampling_pattern, "Sampling Pattern", sampling_pattern_enum, SAMPLING_PATTERN_SOBOL);
+   sampling_pattern_enum.insert("pmj", SAMPLING_PATTERN_PMJ);
+   SOCKET_ENUM(sampling_pattern, "Sampling Pattern", sampling_pattern_enum, SAMPLING_PATTERN_PMJ);
    SOCKET_FLOAT(scrambling_distance, "Scrambling Distance", 1.0f);
  
    static NodeEnum denoiser_type_enum;
diff --cc release/scripts/addons
index d2325587d73,67f1fbca148..25ffc6f430f
--- a/release/scripts/addons
+++ b/release/scripts/addons
@@@ -1,1 -1,1 +1,1 @@@
- Subproject commit d2325587d73bc825986af3a1baba51cb4a9ce355
 -Subproject commit 67f1fbca1482d9d9362a4001332e785c3fd5d230
++Subproject commit 25ffc6f430fc995b1c046b01acba1c3e6c1896b0



More information about the Bf-blender-cvs mailing list