[Bf-blender-cvs] [ee2fc1eb773] cycles_path_guiding: Guiding: Added option to enable deterministic path guiding

Sebastian Herholz noreply at git.blender.org
Thu Sep 8 14:25:56 CEST 2022


Commit: ee2fc1eb7730c48b3880c0366449f43760ad6a05
Author: Sebastian Herholz
Date:   Thu Sep 8 14:25:26 2022 +0200
Branches: cycles_path_guiding
https://developer.blender.org/rBee2fc1eb7730c48b3880c0366449f43760ad6a05

Guiding: Added option to enable deterministic path guiding

This commits enables to run the training of the guiding caches in a deterministic way.
As a result two individual renderings should result in exactly the same image.
Note: this option can increase the training time by 5-10%.

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

M	intern/cycles/blender/addon/properties.py
M	intern/cycles/blender/addon/ui.py
M	intern/cycles/blender/sync.cpp
M	intern/cycles/integrator/guiding.h
M	intern/cycles/integrator/path_trace.cpp
M	intern/cycles/integrator/path_trace.h
M	intern/cycles/integrator/render_scheduler.cpp
M	intern/cycles/integrator/render_scheduler.h
M	intern/cycles/scene/integrator.cpp
M	intern/cycles/scene/integrator.h

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

diff --git a/intern/cycles/blender/addon/properties.py b/intern/cycles/blender/addon/properties.py
index bc913f4c2c6..3afb27a1ac7 100644
--- a/intern/cycles/blender/addon/properties.py
+++ b/intern/cycles/blender/addon/properties.py
@@ -521,6 +521,14 @@ class CyclesRenderSettings(bpy.types.PropertyGroup):
         default=False,
     )
 
+    deterministic_guiding: BoolProperty(
+        name="Deterministic",
+        description="Makes path guiding deterministic which means renderings will be"
+        "reproducable (i.e., same pixel noise/value). This feature increases the"
+        "compute time during training",
+        default=False,
+    )
+
     guiding_distribution_type: EnumProperty(
         name="Guiding Distribution Type",
         description="Type of representation for the guiding distribution",
diff --git a/intern/cycles/blender/addon/ui.py b/intern/cycles/blender/addon/ui.py
index cfccbb9edb9..5181a41e993 100644
--- a/intern/cycles/blender/addon/ui.py
+++ b/intern/cycles/blender/addon/ui.py
@@ -349,6 +349,7 @@ class CYCLES_RENDER_PT_sampling_path_guiding(CyclesButtonsPanel, Panel):
         layout.active = cscene.use_guiding
 
         col = layout.column(align=True)
+        col.prop(cscene, "deterministic_guiding", text="Deterministic")
         col.prop(cscene, "use_surface_guiding", text="Surface Guiding")
         col.prop(cscene, "use_volume_guiding", text="Volume Guiding")
         col.prop(cscene, "training_iterations", text="Training Iterations")
diff --git a/intern/cycles/blender/sync.cpp b/intern/cycles/blender/sync.cpp
index b1e66f2ee3b..8e7d9e31c68 100644
--- a/intern/cycles/blender/sync.cpp
+++ b/intern/cycles/blender/sync.cpp
@@ -414,6 +414,7 @@ void BlenderSync::sync_integrator(BL::ViewLayer &b_view_layer, bool background)
 #endif
 
   integrator->set_use_guiding(get_boolean(cscene, "use_guiding"));
+  integrator->set_deterministic_guiding(get_boolean(cscene, "deterministic_guiding"));
   integrator->set_use_surface_guiding(get_boolean(cscene, "use_surface_guiding"));
   integrator->set_use_volume_guiding(get_boolean(cscene, "use_volume_guiding"));
   integrator->set_training_iterations(get_int(cscene, "training_iterations"));
diff --git a/intern/cycles/integrator/guiding.h b/intern/cycles/integrator/guiding.h
index a1c6139567c..9bb87b88b23 100644
--- a/intern/cycles/integrator/guiding.h
+++ b/intern/cycles/integrator/guiding.h
@@ -11,12 +11,14 @@ struct GuidingParams {
   bool use = false;
   GuidingDistributionType type = GUIDING_TYPE_PARALLAX_AWARE_VMM;
   int training_iterations = 128;
+  bool deterministic = false;
   GuidingParams() = default;
 
   bool modified(const GuidingParams &other) const
   {
     return !((use == other.use) && (type == other.type) &&
-             (training_iterations == other.training_iterations));
+             (training_iterations == other.training_iterations) &&
+             (deterministic == other.deterministic));
   }
 };
 
diff --git a/intern/cycles/integrator/path_trace.cpp b/intern/cycles/integrator/path_trace.cpp
index 069fda92a53..2ee8718d4de 100644
--- a/intern/cycles/integrator/path_trace.cpp
+++ b/intern/cycles/integrator/path_trace.cpp
@@ -1288,7 +1288,9 @@ void PathTrace::set_guiding_params(const GuidingParams &guiding_params, const bo
           break;
         }
       }
-
+#  if OPENPGL_VERSION_MINOR >= 4
+      field_args.deterministic = guiding_params.deterministic;
+#  endif
       openpgl::cpp::Device *guiding_device = static_cast<openpgl::cpp::Device *>(
           device_->get_guiding_device());
       if (guiding_device) {
@@ -1323,9 +1325,11 @@ void PathTrace::guiding_prepare_structures()
   if ((guiding_params_.training_iterations == -1) ||
       (guiding_field_->GetIteration() < guiding_params_.training_iterations)) {
     device_scene_->data.integrator.train_guiding = true;
+    render_scheduler_.set_limit_spp_for_guiding(true);
   }
   else {
     device_scene_->data.integrator.train_guiding = false;
+    render_scheduler_.set_limit_spp_for_guiding(false);
   }
 #endif
 }
@@ -1359,12 +1363,12 @@ void PathTrace::guiding_update_structures()
               }
             }
       */
-#if OPENPGL_VERSION_MINOR < 4
+#  if OPENPGL_VERSION_MINOR < 4
       const size_t num_samples = 1;
       guiding_field_->Update(*guiding_sample_data_storage_, num_samples);
-#else
+#  else
       guiding_field_->Update(*guiding_sample_data_storage_);
-#endif
+#  endif
       guiding_update_count++;
 #  if defined(WITH_PATH_GUIDING_DEBUG_PRINT) && PATH_GUIDING_DEBUG_VALIDATE
       VLOG_WORK << "Field: valid = " << guiding_field_->Validate();
diff --git a/intern/cycles/integrator/path_trace.h b/intern/cycles/integrator/path_trace.h
index 59a0ef6d742..0523fcf6398 100644
--- a/intern/cycles/integrator/path_trace.h
+++ b/intern/cycles/integrator/path_trace.h
@@ -17,8 +17,8 @@
 #include "util/vector.h"
 
 #ifdef WITH_PATH_GUIDING
-#  include <openpgl/version.h>
 #  include <openpgl/cpp/OpenPGL.h>
+#  include <openpgl/version.h>
 #endif
 
 CCL_NAMESPACE_BEGIN
diff --git a/intern/cycles/integrator/render_scheduler.cpp b/intern/cycles/integrator/render_scheduler.cpp
index 75e591c52a4..438b2fabf37 100644
--- a/intern/cycles/integrator/render_scheduler.cpp
+++ b/intern/cycles/integrator/render_scheduler.cpp
@@ -45,6 +45,11 @@ void RenderScheduler::set_denoiser_params(const DenoiseParams &params)
   denoiser_params_ = params;
 }
 
+void RenderScheduler::set_limit_spp_for_guiding(const bool limit_spp)
+{
+  limit_spp_for_guiding_ = limit_spp;
+}
+
 void RenderScheduler::set_adaptive_sampling(const AdaptiveSampling &adaptive_sampling)
 {
   adaptive_sampling_ = adaptive_sampling;
@@ -808,6 +813,7 @@ int RenderScheduler::get_num_samples_to_path_trace() const
     return 1;
   }
 
+  int num_samples_per_update = calculate_num_samples_per_update();
 #ifdef WITH_PATH_GUIDING
   /*
    * Note: For training the guiding distribution we
@@ -818,10 +824,9 @@ int RenderScheduler::get_num_samples_to_path_trace() const
    *       iterations are rendered
    * TODO: only do this when path guiding is enabled.
    */
-
-  const int num_samples_per_update = std::min(4, calculate_num_samples_per_update());
-#else
-  const int num_samples_per_update = calculate_num_samples_per_update();
+  if (limit_spp_for_guiding_) {
+    num_samples_per_update = std::min(4, num_samples_per_update);
+  }
 #endif
   const int path_trace_start_sample = get_start_sample_to_path_trace();
 
diff --git a/intern/cycles/integrator/render_scheduler.h b/intern/cycles/integrator/render_scheduler.h
index dce876d44bd..fba1d200e9d 100644
--- a/intern/cycles/integrator/render_scheduler.h
+++ b/intern/cycles/integrator/render_scheduler.h
@@ -187,6 +187,8 @@ class RenderScheduler {
    * times, and so on. */
   string full_report() const;
 
+  void set_limit_spp_for_guiding(const bool limit_spp);
+
  protected:
   /* Check whether all work has been scheduled and time limit was not exceeded.
    *
@@ -450,6 +452,10 @@ class RenderScheduler {
    * (quadratic dependency from the resolution divider): resolution divider of 2 brings render time
    * down by a factor of 4. */
   int calculate_resolution_divider_for_time(double desired_time, double actual_time);
+
+  /* If the number of samples per rendering progression should be limited because of path guiding
+   * being activated or is still inside its training phase */
+  bool limit_spp_for_guiding_ = false;
 };
 
 int calculate_resolution_divider_for_resolution(int width, int height, int resolution);
diff --git a/intern/cycles/scene/integrator.cpp b/intern/cycles/scene/integrator.cpp
index 3deee83a356..ee5e2cfe6de 100644
--- a/intern/cycles/scene/integrator.cpp
+++ b/intern/cycles/scene/integrator.cpp
@@ -66,6 +66,7 @@ NODE_DEFINE(Integrator)
   guiding_ditribution_enum.insert("VMM", GUIDING_TYPE_VMM);
 
   SOCKET_BOOLEAN(use_guiding, "Guiding", true);
+  SOCKET_BOOLEAN(deterministic_guiding, "Deterministic", false);
   SOCKET_BOOLEAN(use_surface_guiding, "Surface Guiding", true);
   SOCKET_FLOAT(surface_guiding_probability, "Surface Guiding Probability", 0.5f);
   SOCKET_BOOLEAN(use_volume_guiding, "Volume Guiding", true);
@@ -389,6 +390,7 @@ GuidingParams Integrator::get_guiding_params(const Device *device) const
   guiding_params.use = use_guiding && device->info.has_guiding;
   guiding_params.type = guiding_distribution_type;
   guiding_params.training_iterations = training_iterations;
+  guiding_params.deterministic = deterministic_guiding;
   return guiding_params;
 }
 CCL_NAMESPACE_END
diff --git a/intern/cycles/scene/integrator.h b/intern/cycles/scene/integrator.h
index 5dbf23b375f..2c605ebdbb8 100644
--- a/intern/cycles/scene/integrator.h
+++ b/intern/cycles/scene/integrator.h
@@ -45,6 +45,7 @@ class Integrator : public Node {
   NODE_SOCKET_API(float, volume_step_rate)
 
   NODE_SOCKET_API(bool, use_guiding);
+  NODE_SOCKET_API(bool, deterministic_guiding);
   NODE_SOCKET_API(bool, use_surface_guiding);
   NODE_SOCKET_API(float, surface_guiding_probability);
   NODE_SOCKET_API(bool, use_volume_guiding);



More information about the Bf-blender-cvs mailing list