diff options
Diffstat (limited to 'source/blender/blenkernel')
-rw-r--r-- | source/blender/blenkernel/BKE_cryptomatte.h | 9 | ||||
-rw-r--r-- | source/blender/blenkernel/BKE_cryptomatte.hh | 5 | ||||
-rw-r--r-- | source/blender/blenkernel/BKE_node.h | 20 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/cryptomatte.cc | 58 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/node.cc | 9 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/scene.c | 5 |
6 files changed, 95 insertions, 11 deletions
diff --git a/source/blender/blenkernel/BKE_cryptomatte.h b/source/blender/blenkernel/BKE_cryptomatte.h index 7d295929e77..576a2c1effd 100644 --- a/source/blender/blenkernel/BKE_cryptomatte.h +++ b/source/blender/blenkernel/BKE_cryptomatte.h @@ -30,14 +30,17 @@ extern "C" { #endif +/* Forward declarations. */ struct CryptomatteSession; struct Material; struct Object; struct RenderResult; +struct Scene; struct CryptomatteSession *BKE_cryptomatte_init(void); struct CryptomatteSession *BKE_cryptomatte_init_from_render_result( const struct RenderResult *render_result); +struct CryptomatteSession *BKE_cryptomatte_init_from_scene(const struct Scene *scene); void BKE_cryptomatte_free(struct CryptomatteSession *session); void BKE_cryptomatte_add_layer(struct CryptomatteSession *session, const char *layer_name); @@ -52,6 +55,10 @@ uint32_t BKE_cryptomatte_asset_hash(struct CryptomatteSession *session, const char *layer_name, const struct Object *object); float BKE_cryptomatte_hash_to_float(uint32_t cryptomatte_hash); +bool BKE_cryptomatte_find_name(const struct CryptomatteSession *session, + const float encoded_hash, + char *r_name, + int name_len); char *BKE_cryptomatte_entries_to_matte_id(struct NodeCryptomatte *node_storage); void BKE_cryptomatte_matte_id_to_entries(struct NodeCryptomatte *node_storage, @@ -63,4 +70,4 @@ void BKE_cryptomatte_store_metadata(const struct CryptomatteSession *session, #ifdef __cplusplus } -#endif +#endif
\ No newline at end of file diff --git a/source/blender/blenkernel/BKE_cryptomatte.hh b/source/blender/blenkernel/BKE_cryptomatte.hh index 98fdfc965bc..9e205d01765 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" @@ -105,6 +107,9 @@ struct CryptomatteStampDataCallbackData { static void extract_layer_manifest(void *_data, const char *propname, char *propvalue, int len); }; +const blender::Vector<std::string> &BKE_cryptomatte_layer_names_get( + const CryptomatteSession &session); + struct CryptomatteSessionDeleter { void operator()(CryptomatteSession *session) { diff --git a/source/blender/blenkernel/BKE_node.h b/source/blender/blenkernel/BKE_node.h index 0379dea9e8c..42022cce5a5 100644 --- a/source/blender/blenkernel/BKE_node.h +++ b/source/blender/blenkernel/BKE_node.h @@ -47,6 +47,7 @@ struct BlendLibReader; struct BlendWriter; struct ColorManagedDisplaySettings; struct ColorManagedViewSettings; +struct CryptomatteSession; struct FreestyleLineStyle; struct GPUMaterial; struct GPUNodeStack; @@ -1204,9 +1205,10 @@ void ntreeGPUMaterialNodes(struct bNodeTree *localtree, #define CMP_NODE_PLANETRACKDEFORM 320 #define CMP_NODE_CORNERPIN 321 #define CMP_NODE_SWITCH_VIEW 322 -#define CMP_NODE_CRYPTOMATTE 323 +#define CMP_NODE_CRYPTOMATTE_LEGACY 323 #define CMP_NODE_DENOISE 324 #define CMP_NODE_EXPOSURE 325 +#define CMP_NODE_CRYPTOMATTE 326 /* channel toggles */ #define CMP_CHAN_RGB 1 @@ -1236,6 +1238,10 @@ void ntreeGPUMaterialNodes(struct bNodeTree *localtree, #define CMP_TRACKPOS_RELATIVE_FRAME 2 #define CMP_TRACKPOS_ABSOLUTE_FRAME 3 +/* Cryptomatte source. */ +#define CMP_CRYPTOMATTE_SRC_RENDER 0 +#define CMP_CRYPTOMATTE_SRC_IMAGE 1 + /* API */ void ntreeCompositExecTree(struct Scene *scene, struct bNodeTree *ntree, @@ -1278,11 +1284,15 @@ void ntreeCompositOutputFileUniqueLayer(struct ListBase *list, void ntreeCompositColorBalanceSyncFromLGG(bNodeTree *ntree, bNode *node); void ntreeCompositColorBalanceSyncFromCDL(bNodeTree *ntree, bNode *node); -void ntreeCompositCryptomatteSyncFromAdd(bNodeTree *ntree, bNode *node); -void ntreeCompositCryptomatteSyncFromRemove(bNodeTree *ntree, bNode *node); -struct bNodeSocket *ntreeCompositCryptomatteAddSocket(struct bNodeTree *ntree, struct bNode *node); -int ntreeCompositCryptomatteRemoveSocket(struct bNodeTree *ntree, struct bNode *node); +void ntreeCompositCryptomatteSyncFromAdd(bNode *node); +void ntreeCompositCryptomatteSyncFromRemove(bNode *node); +bNodeSocket *ntreeCompositCryptomatteAddSocket(bNodeTree *ntree, bNode *node); +int ntreeCompositCryptomatteRemoveSocket(bNodeTree *ntree, bNode *node); +void ntreeCompositCryptomatteLayerPrefix(const bNode *node, char *r_prefix, size_t prefix_len); +/* 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 55426f738ff..74576b8bbbb 100644 --- a/source/blender/blenkernel/intern/cryptomatte.cc +++ b/source/blender/blenkernel/intern/cryptomatte.cc @@ -30,6 +30,7 @@ #include "DNA_material_types.h" #include "DNA_node_types.h" #include "DNA_object_types.h" +#include "DNA_scene_types.h" #include "BLI_compiler_attrs.h" #include "BLI_dynstr.h" @@ -50,10 +51,13 @@ struct CryptomatteSession { blender::Map<std::string, blender::bke::cryptomatte::CryptomatteLayer> layers; + /* Layer names in order of creation. */ + blender::Vector<std::string> layer_names; CryptomatteSession(); CryptomatteSession(const Main *bmain); CryptomatteSession(StampData *stamp_data); + CryptomatteSession(const Scene *scene); blender::bke::cryptomatte::CryptomatteLayer &add_layer(std::string layer_name); std::optional<std::string> operator[](float encoded_hash) const; @@ -99,8 +103,32 @@ CryptomatteSession::CryptomatteSession(StampData *stamp_data) false); } +CryptomatteSession::CryptomatteSession(const Scene *scene) +{ + LISTBASE_FOREACH (ViewLayer *, view_layer, &scene->view_layers) { + eViewLayerCryptomatteFlags cryptoflags = static_cast<eViewLayerCryptomatteFlags>( + view_layer->cryptomatte_flag & VIEW_LAYER_CRYPTOMATTE_ALL); + if (cryptoflags == 0) { + cryptoflags = static_cast<eViewLayerCryptomatteFlags>(VIEW_LAYER_CRYPTOMATTE_ALL); + } + + if (cryptoflags & VIEW_LAYER_CRYPTOMATTE_OBJECT) { + add_layer(blender::StringRefNull(view_layer->name) + ".CryptoObject"); + } + if (cryptoflags & VIEW_LAYER_CRYPTOMATTE_ASSET) { + add_layer(blender::StringRefNull(view_layer->name) + ".CryptoAsset"); + } + if (cryptoflags & VIEW_LAYER_CRYPTOMATTE_MATERIAL) { + add_layer(blender::StringRefNull(view_layer->name) + ".CryptoMaterial"); + } + } +} + blender::bke::cryptomatte::CryptomatteLayer &CryptomatteSession::add_layer(std::string layer_name) { + if (!layer_names.contains(layer_name)) { + layer_names.append(layer_name); + } return layers.lookup_or_add_default(layer_name); } @@ -128,6 +156,12 @@ struct CryptomatteSession *BKE_cryptomatte_init_from_render_result( return session; } +struct CryptomatteSession *BKE_cryptomatte_init_from_scene(const struct Scene *scene) +{ + CryptomatteSession *session = new CryptomatteSession(scene); + return session; +} + void BKE_cryptomatte_add_layer(struct CryptomatteSession *session, const char *layer_name) { session->add_layer(layer_name); @@ -182,6 +216,21 @@ float BKE_cryptomatte_hash_to_float(uint32_t cryptomatte_hash) return blender::bke::cryptomatte::CryptomatteHash(cryptomatte_hash).float_encoded(); } +/* Find an ID in the given main that matches the given encoded float. */ +bool BKE_cryptomatte_find_name(const CryptomatteSession *session, + const float encoded_hash, + char *r_name, + int name_len) +{ + std::optional<std::string> name = (*session)[encoded_hash]; + if (!name) { + return false; + } + + BLI_strncpy(r_name, name->c_str(), name_len); + return true; +} + char *BKE_cryptomatte_entries_to_matte_id(NodeCryptomatte *node_storage) { DynStr *matte_id = BLI_dynstr_new(); @@ -213,7 +262,8 @@ void BKE_cryptomatte_matte_id_to_entries(NodeCryptomatte *node_storage, const ch } /* Update the matte_id so the files can be opened in versions that don't * use `CryptomatteEntry`. */ - if (matte_id != node_storage->matte_id && STREQ(node_storage->matte_id, matte_id)) { + if (matte_id != node_storage->matte_id && node_storage->matte_id && + STREQ(node_storage->matte_id, matte_id)) { MEM_SAFE_FREE(node_storage->matte_id); node_storage->matte_id = static_cast<char *>(MEM_dupallocN(matte_id)); } @@ -599,4 +649,10 @@ void CryptomatteStampDataCallbackData::extract_layer_manifest(void *_data, blender::bke::cryptomatte::manifest::from_manifest(layer, propvalue); } +const blender::Vector<std::string> &BKE_cryptomatte_layer_names_get( + const CryptomatteSession &session) +{ + return session.layer_names; +} + } // namespace blender::bke::cryptomatte diff --git a/source/blender/blenkernel/intern/node.cc b/source/blender/blenkernel/intern/node.cc index b6f02128353..66c0e724fdf 100644 --- a/source/blender/blenkernel/intern/node.cc +++ b/source/blender/blenkernel/intern/node.cc @@ -538,7 +538,8 @@ void ntreeBlendWrite(BlendWriter *writer, bNodeTree *ntree) } BLO_write_struct_by_name(writer, node->typeinfo->storagename, node->storage); } - else if ((ntree->type == NTREE_COMPOSIT) && (node->type == CMP_NODE_CRYPTOMATTE)) { + else if ((ntree->type == NTREE_COMPOSIT) && + (ELEM(node->type, CMP_NODE_CRYPTOMATTE, CMP_NODE_CRYPTOMATTE_LEGACY))) { NodeCryptomatte *nc = (NodeCryptomatte *)node->storage; BLO_write_string(writer, nc->matte_id); LISTBASE_FOREACH (CryptomatteEntry *, entry, &nc->entries) { @@ -703,10 +704,12 @@ void ntreeBlendReadData(BlendDataReader *reader, bNodeTree *ntree) iuser->scene = nullptr; break; } + case CMP_NODE_CRYPTOMATTE_LEGACY: case CMP_NODE_CRYPTOMATTE: { 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: { @@ -903,7 +906,8 @@ void ntreeBlendReadExpand(BlendExpander *expander, bNodeTree *ntree) } LISTBASE_FOREACH (bNode *, node, &ntree->nodes) { - if (node->id && node->type != CMP_NODE_R_LAYERS) { + if (node->id && !(node->type == CMP_NODE_R_LAYERS) && + !(node->type == CMP_NODE_CRYPTOMATTE && node->custom1 == CMP_CRYPTOMATTE_SRC_RENDER)) { BLO_expand(expander, node->id); } @@ -4607,6 +4611,7 @@ static void registerCompositNodes() register_node_type_cmp_keyingscreen(); register_node_type_cmp_keying(); register_node_type_cmp_cryptomatte(); + register_node_type_cmp_cryptomatte_legacy(); register_node_type_cmp_translate(); register_node_type_cmp_rotate(); diff --git a/source/blender/blenkernel/intern/scene.c b/source/blender/blenkernel/intern/scene.c index 3633dff8690..de3e1023b08 100644 --- a/source/blender/blenkernel/intern/scene.c +++ b/source/blender/blenkernel/intern/scene.c @@ -1377,9 +1377,10 @@ static void scene_blend_read_data(BlendDataReader *reader, ID *id) /* patch for missing scene IDs, can't be in do-versions */ static void composite_patch(bNodeTree *ntree, Scene *scene) { - LISTBASE_FOREACH (bNode *, node, &ntree->nodes) { - if (node->id == NULL && node->type == CMP_NODE_R_LAYERS) { + if (node->id == NULL && + ((node->type == CMP_NODE_R_LAYERS) || + (node->type == CMP_NODE_CRYPTOMATTE && node->custom1 == CMP_CRYPTOMATTE_SRC_RENDER))) { node->id = &scene->id; } } |