[Bf-blender-cvs] [de80c39db23] cycles-x: Cycles X: Cache result of scene's has shadow catcher test

Sergey Sharybin noreply at git.blender.org
Fri Jul 9 11:12:21 CEST 2021


Commit: de80c39db23e1afea8d8433b1185975c7b6785f3
Author: Sergey Sharybin
Date:   Thu Jul 8 14:40:53 2021 +0200
Branches: cycles-x
https://developer.blender.org/rBde80c39db23e1afea8d8433b1185975c7b6785f3

Cycles X: Cache result of scene's has shadow catcher test

The scene is tagged for an update of the flag from object's update tag.
Currently not following the typical nodes update because of couple of
reasons:

- Scene is not a node, and object manager does not store any state at
  this time.

- The access to the flag could happen before scene device update.

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

M	intern/cycles/render/object.cpp
M	intern/cycles/render/scene.cpp
M	intern/cycles/render/scene.h

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

diff --git a/intern/cycles/render/object.cpp b/intern/cycles/render/object.cpp
index e6b658bc224..64093dc3d64 100644
--- a/intern/cycles/render/object.cpp
+++ b/intern/cycles/render/object.cpp
@@ -214,6 +214,10 @@ void Object::tag_update(Scene *scene)
     if (use_holdout_is_modified()) {
       flag |= ObjectManager::HOLDOUT_MODIFIED;
     }
+
+    if (is_shadow_catcher_is_modified()) {
+      scene->tag_shadow_catcher_modified();
+    }
   }
 
   if (geometry) {
diff --git a/intern/cycles/render/scene.cpp b/intern/cycles/render/scene.cpp
index 0896880d7c4..72e97deba9a 100644
--- a/intern/cycles/render/scene.cpp
+++ b/intern/cycles/render/scene.cpp
@@ -667,17 +667,26 @@ int Scene::get_max_closure_count()
   return max_closure_global;
 }
 
-bool Scene::has_shadow_catcher() const
-{
-  /* TODO(sergey): Calculate once when object manager changes. */
-
-  for (Object *object : objects) {
-    if (object->get_is_shadow_catcher()) {
-      return true;
+bool Scene::has_shadow_catcher()
+{
+  if (shadow_catcher_modified_) {
+    has_shadow_catcher_ = false;
+    for (Object *object : objects) {
+      if (object->get_is_shadow_catcher()) {
+        has_shadow_catcher_ = true;
+        break;
+      }
     }
+
+    shadow_catcher_modified_ = false;
   }
 
-  return false;
+  return has_shadow_catcher_;
+}
+
+void Scene::tag_shadow_catcher_modified()
+{
+  shadow_catcher_modified_ = true;
 }
 
 template<> Light *Scene::create_node<Light>()
diff --git a/intern/cycles/render/scene.h b/intern/cycles/render/scene.h
index f6c131b570b..7c04784800a 100644
--- a/intern/cycles/render/scene.h
+++ b/intern/cycles/render/scene.h
@@ -275,7 +275,8 @@ class Scene : public NodeOwner {
   /* Update passes so that they contain all passes required for the configured functionality. */
   void update_passes();
 
-  bool has_shadow_catcher() const;
+  bool has_shadow_catcher();
+  void tag_shadow_catcher_modified();
 
   /* This function is used to create a node of a specified type instead of
    * calling 'new', and sets the scene as the owner of the node.
@@ -336,6 +337,9 @@ class Scene : public NodeOwner {
 
   bool load_kernels(Progress &progress, bool lock_scene = true);
 
+  bool has_shadow_catcher_ = false;
+  bool shadow_catcher_modified_ = true;
+
   /* ** Split kernel routines ** */
 
   DeviceRequestedFeatures get_requested_device_features();



More information about the Bf-blender-cvs mailing list