[Bf-blender-cvs] [8defd9d3ba2] compositor-cryptomatte-workflow: Cryptomatte read layer names from session.

Jeroen Bakker noreply at git.blender.org
Mon Mar 8 15:05:56 CET 2021


Commit: 8defd9d3ba2a9d096b6de33c1f80dccf6225efdc
Author: Jeroen Bakker
Date:   Mon Mar 8 15:03:25 2021 +0100
Branches: compositor-cryptomatte-workflow
https://developer.blender.org/rB8defd9d3ba2a9d096b6de33c1f80dccf6225efdc

Cryptomatte read layer names from session.

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

M	source/blender/blenkernel/BKE_cryptomatte.hh
M	source/blender/blenkernel/BKE_node.h
M	source/blender/blenkernel/intern/cryptomatte.cc
M	source/blender/blenkernel/intern/node.cc
M	source/blender/makesdna/DNA_node_types.h
M	source/blender/makesrna/intern/rna_nodetree.c
M	source/blender/nodes/composite/nodes/node_composite_cryptomatte.cc

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

diff --git a/source/blender/blenkernel/BKE_cryptomatte.hh b/source/blender/blenkernel/BKE_cryptomatte.hh
index f10b4c1f7c4..7c325932b7c 100644
--- a/source/blender/blenkernel/BKE_cryptomatte.hh
+++ b/source/blender/blenkernel/BKE_cryptomatte.hh
@@ -26,6 +26,8 @@
 #include <optional>
 #include <string>
 
+#include "BKE_cryptomatte.h"
+
 #include "BLI_map.hh"
 #include "BLI_string_ref.hh"
 
@@ -103,4 +105,7 @@ struct CryptomatteStampDataCallbackData {
   static void extract_layer_manifest(void *_data, const char *propname, char *propvalue, int len);
 };
 
+blender::Vector<blender::StringRef> BKE_cryptomatte_layer_names_get(
+    const CryptomatteSession &session);
+
 }  // namespace blender::bke::cryptomatte
diff --git a/source/blender/blenkernel/BKE_node.h b/source/blender/blenkernel/BKE_node.h
index b5be28da9ab..75636c7f42b 100644
--- a/source/blender/blenkernel/BKE_node.h
+++ b/source/blender/blenkernel/BKE_node.h
@@ -1286,7 +1286,9 @@ void ntreeCompositColorBalanceSyncFromCDL(bNodeTree *ntree, bNode *node);
 void ntreeCompositCryptomatteSyncFromAdd(bNode *node);
 void ntreeCompositCryptomatteSyncFromRemove(bNode *node);
 const char *ntreeCompositCryptomatteLayerPrefix(const bNode *node);
-struct CryptomatteSession *ntreeCompositCryptomatteSessionInitFromNode(const bNode *node);
+/* Update the runtime layer names with the cryptomatte layer names of the references
+ * render layer or image. */
+void ntreeCompositCryptomatteUpdateLayerNames(bNode *node);
 /** \} */
 
 /* -------------------------------------------------------------------- */
diff --git a/source/blender/blenkernel/intern/cryptomatte.cc b/source/blender/blenkernel/intern/cryptomatte.cc
index bb8b0de7b65..ad9bafa4999 100644
--- a/source/blender/blenkernel/intern/cryptomatte.cc
+++ b/source/blender/blenkernel/intern/cryptomatte.cc
@@ -614,4 +614,14 @@ void CryptomatteStampDataCallbackData::extract_layer_manifest(void *_data,
   blender::bke::cryptomatte::manifest::from_manifest(layer, propvalue);
 }
 
+blender::Vector<blender::StringRef> BKE_cryptomatte_layer_names_get(
+    const CryptomatteSession &session)
+{
+  blender::Vector<blender::StringRef> layer_names;
+  for (std::string layer_name : session.layers.keys()) {
+    layer_names.append(layer_name);
+  }
+  return layer_names;
+}
+
 }  // namespace blender::bke::cryptomatte
diff --git a/source/blender/blenkernel/intern/node.cc b/source/blender/blenkernel/intern/node.cc
index 8ca835baac2..b7c1fbd887b 100644
--- a/source/blender/blenkernel/intern/node.cc
+++ b/source/blender/blenkernel/intern/node.cc
@@ -707,6 +707,7 @@ void ntreeBlendReadData(BlendDataReader *reader, bNodeTree *ntree)
           NodeCryptomatte *nc = (NodeCryptomatte *)node->storage;
           BLO_read_data_address(reader, &nc->matte_id);
           BLO_read_list(reader, &nc->entries);
+          BLI_listbase_clear(&nc->runtime.layers);
           break;
         }
         case TEX_NODE_IMAGE: {
diff --git a/source/blender/makesdna/DNA_node_types.h b/source/blender/makesdna/DNA_node_types.h
index f470d51794a..a8b2d8d54f9 100644
--- a/source/blender/makesdna/DNA_node_types.h
+++ b/source/blender/makesdna/DNA_node_types.h
@@ -1067,6 +1067,19 @@ typedef struct CryptomatteEntry {
   char _pad[4];
 } CryptomatteEntry;
 
+typedef struct CryptomatteLayer {
+  struct CryptomatteEntry *next, *prev;
+  char name[64];
+} CryptomatteLayer;
+
+typedef struct NodeCryptomatte_Runtime {
+  /* Contains `CryptomatteLayer`. */
+  ListBase layers;
+  /* Temp storage for the cryptomatte picker. */
+  float add[3];
+  float remove[3];
+} NodeCryptomatte_Runtime;
+
 typedef struct NodeCryptomatte {
   /* iuser needs to be first element due to RNA limitations.
    * When we define the ImageData properties, we can't define them from
@@ -1076,12 +1089,12 @@ typedef struct NodeCryptomatte {
   /* Contains `CryptomatteEntry`. */
   ListBase entries;
 
-  float add[3];
-  float remove[3];
   /* MAX_NAME */
   char layer_name[64];
   /* Stores `entries` as a string for opening in 2.80-2.91. */
   char *matte_id;
+
+  NodeCryptomatte_Runtime runtime;
 } NodeCryptomatte;
 
 typedef struct NodeDenoise {
diff --git a/source/blender/makesrna/intern/rna_nodetree.c b/source/blender/makesrna/intern/rna_nodetree.c
index 0e9dd30075a..1705d2b5f76 100644
--- a/source/blender/makesrna/intern/rna_nodetree.c
+++ b/source/blender/makesrna/intern/rna_nodetree.c
@@ -398,6 +398,12 @@ static const EnumPropertyItem prop_shader_output_target_items[] = {
     {0, NULL, 0, NULL, NULL},
 };
 
+static const EnumPropertyItem node_cryptomatte_layer_name_items[] = {
+    {0, "CryptoObject", 0, "Object", "Use Object layer"},
+    {1, "CryptoMaterial", 0, "Material", "Use Material layer"},
+    {2, "CryptoAsset", 0, "Asset", "Use Asset layer"},
+    {0, NULL, 0, NULL, NULL}};
+
 #endif
 
 #define ITEM_ATTRIBUTE \
@@ -3735,7 +3741,6 @@ static void rna_NodeCryptomatte_source_set(PointerRNA *ptr, int value)
   node->custom1 = value;
 }
 
-#  if 0
 static int rna_NodeCryptomatte_layer_name_get(PointerRNA *ptr)
 {
   return 0;
@@ -3751,27 +3756,25 @@ static const EnumPropertyItem *rna_NodeCryptomatte_layer_name_itemf(bContext *C,
                                                                     bool *r_free)
 {
   bNode *node = (bNode *)ptr->data;
-
+  NodeCryptomatte *storage = node->storage;
   EnumPropertyItem *item = NULL;
-  EnumPropertyItem tmp = {0, "", 0, "", ""};
+  EnumPropertyItem template = {0, "", 0, "", ""};
   int totitem = 0;
 
-  struct CryptomatteSession *session = ntreeCompositCryptomatteSessionInitFromNode(node);
-  tmp.value = 0;
-  tmp.identifier = "test";
-  tmp.name = "test";
-  RNA_enum_item_add(&item, &totitem, &tmp);
-
-  if (session) {
-    BKE_cryptomatte_free(session);
+  ntreeCompositCryptomatteUpdateLayerNames(node);
+  int layer_index;
+  LISTBASE_FOREACH_INDEX (CryptomatteLayer *, layer, &storage->runtime.layers, layer_index) {
+    template.value = layer_index;
+    template.identifier = layer->name;
+    template.name = layer->name;
+    RNA_enum_item_add(&item, &totitem, &template);
   }
 
   RNA_enum_item_end(&item, &totitem);
   *r_free = true;
 
-  return NULL;
+  return item;
 }
-#  endif
 
 static PointerRNA rna_NodeCryptomatte_scene_get(PointerRNA *ptr)
 {
@@ -8518,13 +8521,6 @@ static void def_cmp_cryptomatte(StructRNA *srna)
       {CMP_CRYPTOMATTE_SRC_RENDER, "RENDER", 0, "Render", "Use Cryptomatte passes from a render"},
       {CMP_CRYPTOMATTE_SRC_IMAGE, "IMAGE", 0, "Image", "Use Cryptomatte passes from an image"},
       {0, NULL, 0, NULL, NULL}};
-#  if 0
-  static const EnumPropertyItem cryptomatte_layer_name_items[] = {
-      {0, "CryptoObject", 0, "Object", "Use Object layer"},
-      // {CMP_CRYPTOMATTE_TYPE_MATERIAL, "CryptoMaterial", 0, "Material", "Use Material layer"},
-      // {CMP_CRYPTOMATTE_TYPE_ASSET, "CryptoAsset", 0, "Asset", "Use Asset layer"},
-      {0, NULL, 0, NULL, NULL}};
-#  endif
 
   prop = RNA_def_property(srna, "source", PROP_ENUM, PROP_NONE);
   RNA_def_property_enum_sdna(prop, NULL, "custom1");
@@ -8564,10 +8560,10 @@ static void def_cmp_cryptomatte(StructRNA *srna)
    * layer in the `layer_name` DNA field. Might need to look at AOVs where we did
    * a similar trick. The enabled `cryptomatte_layer_name` is just a quick workaround
    * for testing purposes. */
-#  if 0
-  prop = RNA_def_property(srna, "cryptomatte_layer_name", PROP_ENUM, PROP_NONE);
+#  if 1
+  prop = RNA_def_property(srna, "layer_name", PROP_ENUM, PROP_NONE);
   // RNA_def_property_enum_sdna(prop, NULL, "layer_name");
-  RNA_def_property_enum_items(prop, cryptomatte_layer_name_items);
+  RNA_def_property_enum_items(prop, node_cryptomatte_layer_name_items);
   RNA_def_property_enum_funcs(prop,
                               "rna_NodeCryptomatte_layer_name_get",
                               "rna_NodeCryptomatte_layer_name_set",
@@ -8582,6 +8578,7 @@ static void def_cmp_cryptomatte(StructRNA *srna)
 #  endif
 
   prop = RNA_def_property(srna, "add", PROP_FLOAT, PROP_COLOR);
+  RNA_def_property_float_sdna(prop, NULL, "runtime.add");
   RNA_def_property_float_array_default(prop, default_1);
   RNA_def_property_range(prop, -FLT_MAX, FLT_MAX);
   RNA_def_property_ui_text(
@@ -8589,6 +8586,7 @@ static void def_cmp_cryptomatte(StructRNA *srna)
   RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_NodeCryptomatte_update_add");
 
   prop = RNA_def_property(srna, "remove", PROP_FLOAT, PROP_COLOR);
+  RNA_def_property_float_sdna(prop, NULL, "runtime.remove");
   RNA_def_property_float_array_default(prop, default_1);
   RNA_def_property_range(prop, -FLT_MAX, FLT_MAX);
   RNA_def_property_ui_text(
diff --git a/source/blender/nodes/composite/nodes/node_composite_cryptomatte.cc b/source/blender/nodes/composite/nodes/node_composite_cryptomatte.cc
index 77f1be6025a..2b9ee17e6c0 100644
--- a/source/blender/nodes/composite/nodes/node_composite_cryptomatte.cc
+++ b/source/blender/nodes/composite/nodes/node_composite_cryptomatte.cc
@@ -26,10 +26,11 @@
 #include "BLI_assert.h"
 #include "BLI_dynstr.h"
 #include "BLI_hash_mm3.h"
+#include "BLI_string_ref.hh"
 #include "BLI_utildefines.h"
 
 #include "BKE_context.h"
-#include "BKE_cryptomatte.h"
+#include "BKE_cryptomatte.hh"
 #include "BKE_global.h"
 #include "BKE_lib_id.h"
 #include "BKE_library.h"
@@ -133,29 +134,39 @@ static bNodeSocketTemplate cmp_node_cryptomatte_out[] = {
 void ntreeCompositCryptomatteSyncFromAdd(bNode *node)
 {
   NodeCryptomatte *n = static_cast<NodeCryptomatte *>(node->storage);
-  if (n->add[0] != 0.0f) {
-    cryptomatte_add(*node, *n, n->add[0]);
-    zero_v3(n->add);
+  if (n->runtime.add[0] != 0.0f) {
+    cryptomatte_add(*node, *n, n->runtime.add[0]);
+    zero_v3(n->runtime.add);
   }
 }
 
 void ntreeCompositCryptomatteSyncFromRemove(bNode *node)
 {
   NodeCryptomatte *n = static_cast<NodeCryptomatte *>(node->storage);
-  if (n->remove[0] != 0.0f) {
-    cryptomatte_remove(*n, n->remove[0]);
-    zero_v3(n->remove);
+  if (n->runtime.remove[0] != 0.0f) {
+    cryptomatte_remove(*n, n->runtime.remove[0]);
+    zero_v3(n->runtime.remove);
   }
 }
-CryptomatteSession *ntreeCompositCryptomatteSessionInitFromNode(const bNode *node)
+void ntreeCompositCryptomatteUpdateLayerNames(bNode *node)
 {
-  return crypto

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list