[Bf-blender-cvs] [00f984f9ae4] cycles_path_guiding: Guiding: Code cleanup as well as adding functions to validate bsdf_label and bsdf_roughness_eta

Sebastian Herhoz noreply at git.blender.org
Mon Sep 19 10:51:20 CEST 2022


Commit: 00f984f9ae4f47df9a5e47d57a2e35a402392df7
Author: Sebastian Herhoz
Date:   Sun Sep 18 11:52:16 2022 +0200
Branches: cycles_path_guiding
https://developer.blender.org/rB00f984f9ae4f47df9a5e47d57a2e35a402392df7

Guiding: Code cleanup as well as adding functions to validate bsdf_label and bsdf_roughness_eta

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

M	intern/cycles/integrator/path_trace.cpp
M	intern/cycles/kernel/integrator/shade_volume.h
M	intern/cycles/kernel/integrator/surface_shader.h

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

diff --git a/intern/cycles/integrator/path_trace.cpp b/intern/cycles/integrator/path_trace.cpp
index 2ee8718d4de..673f2b39076 100644
--- a/intern/cycles/integrator/path_trace.cpp
+++ b/intern/cycles/integrator/path_trace.cpp
@@ -1338,43 +1338,27 @@ void PathTrace::guiding_update_structures()
 {
 #ifdef WITH_PATH_GUIDING
 #  ifdef WITH_PATH_GUIDING_DEBUG_PRINT
-  VLOG_WORK << "Path Guiding: update guiding structures";
-  VLOG_WORK << "SampleDataStrorage: #surface samples = "
+  VLOG_INFO << "Path Guiding: update guiding structures";
+  VLOG_INFO << "SampleDataStrorage: #surface samples = "
             << guiding_sample_data_storage_->GetSizeSurface()
             << "\t#volumesamples = " << guiding_sample_data_storage_->GetSizeVolume();
 #  endif
-  if (true) {
-    const size_t num_valid_samples = guiding_sample_data_storage_->GetSizeSurface() +
-                                     guiding_sample_data_storage_->GetSizeVolume();
-    if (num_valid_samples >= 128) {
-
-      /*
-            if(guiding_update_count == 128)
-            {
-              std::string dump_sds_file_name =
-         "/data/sherholz/Data/openpgl/guiding_sample_storage_" +
-         std::to_string(guiding_update_count) +  ".sds";
-              guiding_sample_data_storage_->Store(dump_sds_file_name);
-
-              if(guiding_update_count>0)
-              {
-                std::string fieldFileName = "/data/sherholz/Data/openpgl/guiding_field_" +
-         std::to_string(guiding_update_count) +  ".field"; guiding_field_->Store(fieldFileName);
-              }
-            }
-      */
+  const size_t num_valid_samples = guiding_sample_data_storage_->GetSizeSurface() +
+                                   guiding_sample_data_storage_->GetSizeVolume();
+  /* we wait until we have at least 1024 samples */
+  if (num_valid_samples >= 1024) {
+
 #  if OPENPGL_VERSION_MINOR < 4
-      const size_t num_samples = 1;
-      guiding_field_->Update(*guiding_sample_data_storage_, num_samples);
+    const size_t num_samples = 1;
+    guiding_field_->Update(*guiding_sample_data_storage_, num_samples);
 #  else
-      guiding_field_->Update(*guiding_sample_data_storage_);
+    guiding_field_->Update(*guiding_sample_data_storage_);
 #  endif
-      guiding_update_count++;
+    guiding_update_count++;
 #  if defined(WITH_PATH_GUIDING_DEBUG_PRINT) && PATH_GUIDING_DEBUG_VALIDATE
-      VLOG_WORK << "Field: valid = " << guiding_field_->Validate();
+    VLOG_DEBUG << "Field: valid = " << guiding_field_->Validate();
 #  endif
-      guiding_sample_data_storage_->Clear();
-    }
+    guiding_sample_data_storage_->Clear();
   }
 #endif
 }
diff --git a/intern/cycles/kernel/integrator/shade_volume.h b/intern/cycles/kernel/integrator/shade_volume.h
index 45557e8858f..33f7875368a 100644
--- a/intern/cycles/kernel/integrator/shade_volume.h
+++ b/intern/cycles/kernel/integrator/shade_volume.h
@@ -852,10 +852,6 @@ ccl_device_forceinline void integrate_volume_direct_light(
       state, path, transmission_bounce);
   INTEGRATOR_STATE_WRITE(shadow_state, shadow_path, throughput) = throughput_phase;
 
-#  ifdef __PATH_GUIDING__
-  // TODO add scattered contriubtion
-#  endif
-
   if (kernel_data.kernel_features & KERNEL_FEATURE_SHADOW_PASS) {
     INTEGRATOR_STATE_WRITE(shadow_state, shadow_path, unshadowed_throughput) = throughput;
   }
diff --git a/intern/cycles/kernel/integrator/surface_shader.h b/intern/cycles/kernel/integrator/surface_shader.h
index 8024385b77a..5b6a4facd3e 100644
--- a/intern/cycles/kernel/integrator/surface_shader.h
+++ b/intern/cycles/kernel/integrator/surface_shader.h
@@ -14,6 +14,8 @@
 
 #include "kernel/svm/svm.h"
 
+#include "util/log.h"
+
 #ifdef __OSL__
 #  include "kernel/osl/shader.h"
 #endif
@@ -186,6 +188,49 @@ ccl_device_inline bool surface_shader_is_transmission_sc(const ShaderClosure *sc
   return dot(sc->N, omega_in) < 0.0f;
 }
 
+ccl_device_inline bool surface_shader_validate_bsdf_label(const KernelGlobals kg,
+                                                          const ShaderClosure *sc,
+                                                          const float3 *omega_in,
+                                                          const int org_label)
+{
+  bool is_transmission = surface_shader_is_transmission_sc(sc, *omega_in);
+  int comp_label = bsdf_label(kg, sc, is_transmission);
+  if (org_label != comp_label) {
+    VLOG_DEBUG << "VALIDATE BSDF LABEL: False";
+    VLOG_DEBUG << "org_label:  reflect = " << (org_label & LABEL_REFLECT)
+               << "\t transmit = " << (org_label & LABEL_TRANSMIT)
+               << "\t diffuse = " << (org_label & LABEL_DIFFUSE)
+               << "\t glossy = " << (org_label & LABEL_GLOSSY)
+               << "\t singular = " << (org_label & LABEL_SINGULAR);
+    VLOG_DEBUG << "comp_label: reflect = " << (comp_label & LABEL_REFLECT)
+               << "\t transmit = " << (comp_label & LABEL_TRANSMIT)
+               << "\t diffuse = " << (comp_label & LABEL_DIFFUSE)
+               << "\t glossy = " << (comp_label & LABEL_GLOSSY)
+               << "\t singular = " << (comp_label & LABEL_SINGULAR);
+    return false;
+  }
+  return true;
+}
+
+ccl_device_inline bool surface_shader_validate_bsdf_roughness_eta(const KernelGlobals kg,
+                                                                  const ShaderClosure *sc,
+                                                                  const float2 org_roughness,
+                                                                  const float org_eta)
+{
+  float2 comp_roughness;
+  float comp_eta;
+  bsdf_roughness_eta(kg, sc, &comp_roughness, &comp_eta);
+  if ((org_eta != comp_eta) || (org_roughness.x != comp_roughness.x) ||
+      (org_roughness.y != comp_roughness.y)) {
+    VLOG_DEBUG << "VALIDATE ROUGHNESS ETA: FALSE";
+    VLOG_DEBUG << "org_eta = " << org_eta << "\t comp_eta = " << comp_eta << "\t org_roughness = ["
+               << org_roughness.x << "\t" << org_roughness.y << "]\t comp_roughness = ["
+               << comp_roughness.x << "\t" << comp_roughness.y << "]";
+    return false;
+  }
+  return true;
+}
+
 ccl_device_forceinline bool _surface_shader_exclude(ClosureType type, uint light_shader_flags)
 {
   if (!(light_shader_flags & SHADER_EXCLUDE_ANY)) {
@@ -472,45 +517,13 @@ ccl_device int surface_shader_bsdf_guided_sample_closure(KernelGlobals kg,
     *guided_bsdf_pdf = 0.0f;
     label = bsdf_sample(
         kg, sd, sc, rand_bsdf.x, rand_bsdf.y, &eval, omega_in, bsdf_pdf, sampled_rougness, eta);
-#  ifdef WITH_CYCLES_DEBUG
-    ///////
-    // validation code to test the bsdf_label function
-    ///////
-    bool is_transmission3 = surface_shader_is_transmission_sc(sc, *omega_in);
-    int label2 = bsdf_label(kg, sc, is_transmission3);
-    /*
-        if (*bsdf_pdf > 0.f && label != label2) {
-          std::cout << "LABEL ERROR: " << std::endl;
-          std::cout << "LABEL:  reflect = " << (label & LABEL_REFLECT)
-                    << "\t transmit = " << (label & LABEL_TRANSMIT)
-                    << "\t diffuse = " << (label & LABEL_DIFFUSE)
-                    << "\t glossy = " << (label & LABEL_GLOSSY)
-                    << "\t singular = " << (label & LABEL_SINGULAR) << std::endl;
-          std::cout << "LABEL2: reflect = " << (label2 & LABEL_REFLECT)
-                    << "\t transmit = " << (label2 & LABEL_TRANSMIT)
-                    << "\t diffuse = " << (label2 & LABEL_DIFFUSE)
-                    << "\t glossy = " << (label2 & LABEL_GLOSSY)
-                    << "\t singular = " << (label2 & LABEL_SINGULAR) << std::endl;
-          // int label2 = bsdf_label(kg, sc, is_transmission3);
-        }
-    */
-    float2 sampled_rougness2;
-    float eta2;
-    bsdf_roughness_eta(kg, sc, &sampled_rougness2, &eta2);
-    if (*bsdf_pdf > 0.f && (*eta != eta2 || sampled_rougness->x != sampled_rougness2.x ||
-                            sampled_rougness->y != sampled_rougness2.y)) {
-      /*
-            std::cout << "ROUGHNESS ETA ERROR: " << std::endl;
-            std::cout << "ETA:  eta = " << *eta << "\t eta2 = " << eta2
-                      << "\t rough.x = " << sampled_rougness->x << "\t rough.y = " <<
-         sampled_rougness->y
-                      << "\t rough2.x = " << sampled_rougness2.x
-                      << "\t rough2.y = " << sampled_rougness2.y << std::endl;
-      */
-      bsdf_roughness_eta(kg, sc, &sampled_rougness2, &eta2);
-    }
-
-    ////////
+#  if defined(WITH_CYCLES_DEBUG) && defined(__PATH_GUIDING__)
+    /* validate the the bsdf_label and bsdf_roughness_eta functions
+     * by estimating the values after a bsdf sample*/
+    if (*bsdf_pdf > 0.f) {
+      kernel_assert(surface_shader_validate_bsdf_label(kg, sc, oemga_in, label));
+      kernel_assert(surface_shader_validate_bsdf_roughness_eta(kg, sc, sampled_roughness, eta));
+    }
 #  endif
 
     if (*bsdf_pdf != 0.0f) {



More information about the Bf-blender-cvs mailing list