[Bf-blender-cvs] [329ec115000] compositor-cryptomatte-workflow: Merge branch 'master' into compositor-cryptomatte-workflow
Jeroen Bakker
noreply at git.blender.org
Fri Feb 26 16:59:11 CET 2021
Commit: 329ec1150008dc1452662bc51dcbfdf8f48216c2
Author: Jeroen Bakker
Date: Fri Feb 26 16:59:01 2021 +0100
Branches: compositor-cryptomatte-workflow
https://developer.blender.org/rB329ec1150008dc1452662bc51dcbfdf8f48216c2
Merge branch 'master' into compositor-cryptomatte-workflow
===================================================================
===================================================================
diff --cc source/blender/blenkernel/BKE_cryptomatte.h
index 10842261bdf,1b1c4deeb8a..a3bb04ecb37
--- a/source/blender/blenkernel/BKE_cryptomatte.h
+++ b/source/blender/blenkernel/BKE_cryptomatte.h
@@@ -49,11 -48,9 +48,13 @@@ uint32_t BKE_cryptomatte_material_hash(
uint32_t BKE_cryptomatte_asset_hash(struct CryptomatteSession *session,
const struct Object *object);
float BKE_cryptomatte_hash_to_float(uint32_t cryptomatte_hash);
- struct ID *BKE_cryptomatte_find_id(const struct Main *bmain, const float encoded_hash);
++bool BKE_cryptomatte_find_name(const struct Main *bmain,
++ 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(const struct Main *bmain,
- struct NodeCryptomatte *node_storage,
+ void BKE_cryptomatte_matte_id_to_entries(struct NodeCryptomatte *node_storage,
const char *matte_id);
void BKE_cryptomatte_store_metadata(struct CryptomatteSession *session,
diff --cc source/blender/blenkernel/intern/cryptomatte.cc
index 15d7434952e,42158dced96..30cabc09b45
--- a/source/blender/blenkernel/intern/cryptomatte.cc
+++ b/source/blender/blenkernel/intern/cryptomatte.cc
@@@ -172,56 -121,14 +121,30 @@@ uint32_t BKE_cryptomatte_asset_hash(Cry
while (asset_object->parent != nullptr) {
asset_object = asset_object->parent;
}
- return cryptomatte_hash(&session->assets, &asset_object->id);
+ return session->assets.add_ID(asset_object->id);
}
- /* Convert a cryptomatte hash to a float.
- *
- * Cryptomatte hashes are stored in float textures and images. The conversion is taken from the
- * cryptomatte specification. See Floating point conversion section in
- * https://github.com/Psyop/Cryptomatte/blob/master/specification/cryptomatte_specification.pdf.
- *
- * The conversion uses as many 32 bit floating point values as possible to minimize hash
- * collisions. Unfortunately not all 32 bits can be used as NaN and Inf can be problematic.
- *
- * Note that this conversion assumes to be running on a L-endian system. */
float BKE_cryptomatte_hash_to_float(uint32_t cryptomatte_hash)
{
- uint32_t mantissa = cryptomatte_hash & ((1 << 23) - 1);
- uint32_t exponent = (cryptomatte_hash >> 23) & ((1 << 8) - 1);
- exponent = MAX2(exponent, (uint32_t)1);
- exponent = MIN2(exponent, (uint32_t)254);
- exponent = exponent << 23;
- uint32_t sign = (cryptomatte_hash >> 31);
- sign = sign << 31;
- uint32_t float_bits = sign | exponent | mantissa;
- float f;
- memcpy(&f, &float_bits, sizeof(uint32_t));
- return f;
- }
-
- static ID *cryptomatte_find_id(const ListBase *ids, const float encoded_hash)
- {
- LISTBASE_FOREACH (ID *, id, ids) {
- uint32_t hash = BKE_cryptomatte_hash((id->name + 2), BLI_strnlen(id->name + 2, MAX_NAME));
- if (BKE_cryptomatte_hash_to_float(hash) == encoded_hash) {
- return id;
- }
- }
- return nullptr;
+ return blender::bke::cryptomatte::CryptomatteHash(cryptomatte_hash).float_encoded();
}
+/* Find an ID in the given main that matches the given encoded float. */
- struct ID *BKE_cryptomatte_find_id(const Main *bmain, const float encoded_hash)
++bool BKE_cryptomatte_find_name(const Main *bmain,
++ const float encoded_hash,
++ char *r_name,
++ int name_len)
+{
- ID *result;
- result = cryptomatte_find_id(&bmain->objects, encoded_hash);
- if (result == nullptr) {
- result = cryptomatte_find_id(&bmain->materials, encoded_hash);
++ CryptomatteSession session(bmain);
++ std::optional<std::string> name = session[encoded_hash];
++ if (!name) {
++ return false;
+ }
- return result;
++
++ 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();
diff --cc source/blender/nodes/composite/nodes/node_composite_cryptomatte.c
index 861e9512231,f5308fe2671..852ef165195
--- a/source/blender/nodes/composite/nodes/node_composite_cryptomatte.c
+++ b/source/blender/nodes/composite/nodes/node_composite_cryptomatte.c
@@@ -45,24 -37,14 +45,17 @@@ static CryptomatteEntry *cryptomatte_fi
return NULL;
}
-static void cryptomatte_add(NodeCryptomatte *n, float f)
+static void cryptomatte_add(Main *bmain, NodeCryptomatte *n, float encoded_hash)
{
/* Check if entry already exist. */
- if (cryptomatte_find(n, f) != NULL) {
+ if (cryptomatte_find(n, encoded_hash) != NULL) {
return;
}
+
- const char *name = NULL;
- const ID *matching_id = BKE_cryptomatte_find_id(bmain, encoded_hash);
- if (matching_id != NULL) {
- name = matching_id->name + 2;
- }
-
CryptomatteEntry *entry = MEM_callocN(sizeof(CryptomatteEntry), __func__);
- entry->encoded_hash = f;
+ entry->encoded_hash = encoded_hash;
- if (name != NULL) {
- BLI_strncpy(entry->name, name, sizeof(entry->name));
- }
++ BKE_cryptomatte_find_name(bmain, encoded_hash, entry->name, sizeof(entry->name));
++
BLI_addtail(&n->entries, entry);
}
More information about the Bf-blender-cvs
mailing list