Cleanup: CryptomatteLayer structure.
Current implementation was to restricting for future enhancements where the CryptomatterLayer could be read from existing metadata.
This commit is contained in:
@@ -38,7 +38,6 @@ struct Object;
|
||||
struct RenderResult;
|
||||
|
||||
struct CryptomatteSession *BKE_cryptomatte_init(void);
|
||||
void BKE_cryptomatte_finish(struct CryptomatteSession *session);
|
||||
void BKE_cryptomatte_free(struct CryptomatteSession *session);
|
||||
|
||||
uint32_t BKE_cryptomatte_hash(const char *name, int name_len);
|
||||
|
@@ -35,7 +35,7 @@
|
||||
#include "BLI_dynstr.h"
|
||||
#include "BLI_hash_mm3.h"
|
||||
#include "BLI_listbase.h"
|
||||
#include "BLI_set.hh"
|
||||
#include "BLI_map.hh"
|
||||
#include "BLI_string.h"
|
||||
|
||||
#include "MEM_guardedalloc.h"
|
||||
@@ -47,54 +47,47 @@
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
|
||||
enum class CryptomatteLayerState {
|
||||
EMPTY,
|
||||
FILLED,
|
||||
CLOSED,
|
||||
};
|
||||
|
||||
struct CryptomatteLayer {
|
||||
CryptomatteLayerState state = CryptomatteLayerState::EMPTY;
|
||||
blender::Set<std::string> names;
|
||||
std::stringstream manifest;
|
||||
blender::Map<std::string, std::string> hashes;
|
||||
|
||||
#ifdef WITH_CXX_GUARDEDALLOC
|
||||
MEM_CXX_CLASS_ALLOC_FUNCS("cryptomatte:CryptomatteLayer")
|
||||
#endif
|
||||
|
||||
void add_hash(std::string name, uint32_t cryptomatte_hash)
|
||||
std::string encode_hash(uint32_t cryptomatte_hash)
|
||||
{
|
||||
BLI_assert(state != CryptomatteLayerState::CLOSED);
|
||||
const bool first_item = names.is_empty();
|
||||
if (!names.add(name)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (first_item) {
|
||||
state = CryptomatteLayerState::FILLED;
|
||||
manifest << "{";
|
||||
}
|
||||
else {
|
||||
manifest << ",";
|
||||
}
|
||||
manifest << quoted(name) << ":\"";
|
||||
manifest << std::setfill('0') << std::setw(sizeof(uint32_t) * 2) << std::hex
|
||||
<< cryptomatte_hash;
|
||||
manifest << "\"";
|
||||
std::stringstream encoded;
|
||||
encoded << std::setfill('0') << std::setw(sizeof(uint32_t) * 2) << std::hex
|
||||
<< cryptomatte_hash;
|
||||
return encoded.str();
|
||||
}
|
||||
|
||||
void close_manifest()
|
||||
void add_hash(blender::StringRef name, uint32_t cryptomatte_hash)
|
||||
{
|
||||
BLI_assert(state != CryptomatteLayerState::CLOSED);
|
||||
if (state == CryptomatteLayerState::FILLED) {
|
||||
manifest << "}";
|
||||
}
|
||||
state = CryptomatteLayerState::CLOSED;
|
||||
hashes.add_overwrite(name, encode_hash(cryptomatte_hash));
|
||||
}
|
||||
|
||||
std::string manifest_get_string()
|
||||
void add_encoded_hash(blender::StringRef name, std::string &cryptomatte_encoded_hash)
|
||||
{
|
||||
BLI_assert(state == CryptomatteLayerState::CLOSED);
|
||||
hashes.add_overwrite(name, cryptomatte_encoded_hash);
|
||||
}
|
||||
|
||||
std::string manifest()
|
||||
{
|
||||
std::stringstream manifest;
|
||||
|
||||
bool is_first = true;
|
||||
const blender::Map<std::string, std::string> &const_map = hashes;
|
||||
manifest << "{";
|
||||
for (blender::Map<std::string, std::string>::Item item : const_map.items()) {
|
||||
if (is_first) {
|
||||
is_first = false;
|
||||
}
|
||||
else {
|
||||
manifest << ",";
|
||||
}
|
||||
manifest << quoted(item.key) << ":\"" << item.value << "\"";
|
||||
}
|
||||
manifest << "}";
|
||||
return manifest.str();
|
||||
}
|
||||
};
|
||||
@@ -107,13 +100,6 @@ struct CryptomatteSession {
|
||||
#ifdef WITH_CXX_GUARDEDALLOC
|
||||
MEM_CXX_CLASS_ALLOC_FUNCS("cryptomatte:CryptomatteSession")
|
||||
#endif
|
||||
|
||||
void finish()
|
||||
{
|
||||
objects.close_manifest();
|
||||
materials.close_manifest();
|
||||
assets.close_manifest();
|
||||
}
|
||||
};
|
||||
|
||||
CryptomatteSession *BKE_cryptomatte_init(void)
|
||||
@@ -122,12 +108,6 @@ CryptomatteSession *BKE_cryptomatte_init(void)
|
||||
return session;
|
||||
}
|
||||
|
||||
void BKE_cryptomatte_finish(CryptomatteSession *session)
|
||||
{
|
||||
BLI_assert(session != nullptr);
|
||||
session->finish();
|
||||
}
|
||||
|
||||
void BKE_cryptomatte_free(CryptomatteSession *session)
|
||||
{
|
||||
BLI_assert(session != nullptr);
|
||||
@@ -147,7 +127,7 @@ static uint32_t cryptomatte_hash(CryptomatteLayer *layer, const ID *id)
|
||||
uint32_t cryptohash_int = BKE_cryptomatte_hash(name, name_len);
|
||||
|
||||
if (layer != nullptr) {
|
||||
layer->add_hash(std::string(name, name_len), cryptohash_int);
|
||||
layer->add_hash(blender::StringRef(name, name_len), cryptohash_int);
|
||||
}
|
||||
|
||||
return cryptohash_int;
|
||||
@@ -336,7 +316,7 @@ void BKE_cryptomatte_store_metadata(struct CryptomatteSession *session,
|
||||
break;
|
||||
}
|
||||
|
||||
const std::string manifest = layer->manifest_get_string();
|
||||
const std::string manifest = layer->manifest();
|
||||
const std::string name = cryptomatte_determine_name(view_layer, cryptomatte_layer_name);
|
||||
|
||||
/* Store the meta data into the render result. */
|
||||
|
@@ -321,12 +321,6 @@ void EEVEE_cryptomatte_cache_populate(EEVEE_Data *vedata, EEVEE_ViewLayerData *s
|
||||
}
|
||||
}
|
||||
|
||||
void EEVEE_cryptomatte_cache_finish(EEVEE_ViewLayerData *UNUSED(sldata), EEVEE_Data *vedata)
|
||||
{
|
||||
EEVEE_PrivateData *g_data = vedata->stl->g_data;
|
||||
BKE_cryptomatte_finish(g_data->cryptomatte_session);
|
||||
}
|
||||
|
||||
/** \} */
|
||||
|
||||
/* -------------------------------------------------------------------- */
|
||||
|
@@ -1341,7 +1341,6 @@ void EEVEE_cryptomatte_output_init(EEVEE_ViewLayerData *sldata,
|
||||
int tot_samples);
|
||||
void EEVEE_cryptomatte_cache_init(EEVEE_ViewLayerData *sldata, EEVEE_Data *vedata);
|
||||
void EEVEE_cryptomatte_cache_populate(EEVEE_Data *vedata, EEVEE_ViewLayerData *sldata, Object *ob);
|
||||
void EEVEE_cryptomatte_cache_finish(EEVEE_ViewLayerData *sldata, EEVEE_Data *vedata);
|
||||
void EEVEE_cryptomatte_particle_hair_cache_populate(EEVEE_Data *vedata,
|
||||
EEVEE_ViewLayerData *sldata,
|
||||
Object *ob);
|
||||
|
@@ -255,10 +255,6 @@ void EEVEE_renderpasses_cache_finish(EEVEE_ViewLayerData *sldata, EEVEE_Data *ve
|
||||
else {
|
||||
psl->renderpass_pass = NULL;
|
||||
}
|
||||
|
||||
if ((g_data->render_passes & (EEVEE_RENDER_PASS_CRYPTOMATTE)) != 0) {
|
||||
EEVEE_cryptomatte_cache_finish(sldata, vedata);
|
||||
}
|
||||
}
|
||||
|
||||
/* Post-process data to construct a specific render-pass
|
||||
|
Reference in New Issue
Block a user