diff options
-rw-r--r-- | intern/cycles/blender/blender_session.cpp | 29 | ||||
-rw-r--r-- | intern/cycles/blender/blender_session.h | 3 | ||||
-rw-r--r-- | intern/cycles/blender/blender_util.h | 6 | ||||
-rw-r--r-- | intern/cycles/render/object.cpp | 34 | ||||
-rw-r--r-- | intern/cycles/render/object.h | 3 | ||||
-rw-r--r-- | intern/cycles/render/shader.cpp | 16 | ||||
-rw-r--r-- | intern/cycles/render/shader.h | 2 |
7 files changed, 91 insertions, 2 deletions
diff --git a/intern/cycles/blender/blender_session.cpp b/intern/cycles/blender/blender_session.cpp index e05351eea40..75c7dcee05e 100644 --- a/intern/cycles/blender/blender_session.cpp +++ b/intern/cycles/blender/blender_session.cpp @@ -35,6 +35,7 @@ #include "util/util_function.h" #include "util/util_hash.h" #include "util/util_logging.h" +#include "util/util_murmurhash.h" #include "util/util_progress.h" #include "util/util_time.h" @@ -370,6 +371,17 @@ void BlenderSession::update_render_tile(RenderTile& rtile, bool highlight) do_write_update_render_tile(rtile, false, false); } +static void add_cryptomatte_layer(BL::RenderResult& b_rr, string name, string manifest) +{ + string identifier = string_printf("%08x", util_murmur_hash3(name.c_str(), name.length(), 0)); + string prefix = "cryptomatte/" + identifier.substr(0, 7) + "/"; + + render_add_metadata(b_rr, prefix+"name", name); + render_add_metadata(b_rr, prefix+"hash", "MurmurHash3_32"); + render_add_metadata(b_rr, prefix+"conversion", "uint32_to_float32"); + render_add_metadata(b_rr, prefix+"manifest", manifest); +} + void BlenderSession::render() { /* set callback to write out render results */ @@ -477,15 +489,28 @@ void BlenderSession::render() break; } + BL::RenderResult b_full_rr = b_engine.get_result(); if(is_single_layer) { - BL::RenderResult b_rr = b_engine.get_result(); string num_aa_samples = string_printf("%d", session->params.samples); - b_rr.stamp_data_add_field("Cycles Samples", num_aa_samples.c_str()); + render_add_metadata(b_full_rr, "Cycles Samples", num_aa_samples); /* TODO(sergey): Report whether we're doing resumable render * and also start/end sample if so. */ } + if(scene->film->cryptomatte_passes & CRYPT_OBJECT) { + add_cryptomatte_layer(b_full_rr, b_rlay_name+".CryptoObject", + scene->object_manager->get_cryptomatte_objects(scene)); + } + if(scene->film->cryptomatte_passes & CRYPT_MATERIAL) { + add_cryptomatte_layer(b_full_rr, b_rlay_name+".CryptoMaterial", + scene->shader_manager->get_cryptomatte_materials(scene)); + } + if(scene->film->cryptomatte_passes & CRYPT_ASSET) { + add_cryptomatte_layer(b_full_rr, b_rlay_name+".CryptoAsset", + scene->object_manager->get_cryptomatte_assets(scene)); + } + /* free result without merging */ end_render_result(b_engine, b_rr, true, true, false); diff --git a/intern/cycles/blender/blender_session.h b/intern/cycles/blender/blender_session.h index 08f5c873bef..540fa6a8a84 100644 --- a/intern/cycles/blender/blender_session.h +++ b/intern/cycles/blender/blender_session.h @@ -169,6 +169,9 @@ protected: /* Update tile manager to reflect resumable render settings. */ void update_resumable_tile_manager(int num_samples); + + /* Add metadata for cryptomatte layers to the render result. */ + void add_cryptomatte_metadata(string layer_prefix); }; CCL_NAMESPACE_END diff --git a/intern/cycles/blender/blender_util.h b/intern/cycles/blender/blender_util.h index 7e61888348b..09ae9bea313 100644 --- a/intern/cycles/blender/blender_util.h +++ b/intern/cycles/blender/blender_util.h @@ -243,6 +243,12 @@ static inline float *image_get_float_pixels_for_frame(BL::Image& image, return BKE_image_get_float_pixels_for_frame(image.ptr.data, frame); } +static inline void render_add_metadata(BL::RenderResult& b_rr, string name, string value) +{ + b_rr.stamp_data_add_field(name.c_str(), value.c_str()); +} + + /* Utilities */ static inline Transform get_transform(const BL::Array<float, 16>& array) diff --git a/intern/cycles/render/object.cpp b/intern/cycles/render/object.cpp index a56a8a6ec58..dc7a1043208 100644 --- a/intern/cycles/render/object.cpp +++ b/intern/cycles/render/object.cpp @@ -27,6 +27,7 @@ #include "util/util_logging.h" #include "util/util_map.h" #include "util/util_progress.h" +#include "util/util_set.h" #include "util/util_vector.h" #include "util/util_murmurhash.h" @@ -844,4 +845,37 @@ void ObjectManager::tag_update(Scene *scene) scene->light_manager->need_update = true; } +string ObjectManager::get_cryptomatte_objects(Scene *scene) +{ + string manifest = "{"; + + unordered_set<ustring, ustringHash> objects; + foreach(Object *object, scene->objects) { + if(objects.count(object->name)) { + continue; + } + objects.insert(object->name); + uint32_t hash_name = util_murmur_hash3(object->name.c_str(), object->name.length(), 0); + manifest += string_printf("\"%s\":\"%08x\",", object->name.c_str(), hash_name); + } + manifest[manifest.size()-1] = '}'; + return manifest; +} + +string ObjectManager::get_cryptomatte_assets(Scene *scene) +{ + string manifest = "{"; + unordered_set<ustring, ustringHash> assets; + foreach(Object *ob, scene->objects) { + if(assets.count(ob->asset_name)) { + continue; + } + assets.insert(ob->asset_name); + uint32_t hash_asset = util_murmur_hash3(ob->asset_name.c_str(), ob->asset_name.length(), 0); + manifest += string_printf("\"%s\":\"%08x\",", ob->asset_name.c_str(), hash_asset); + } + manifest[manifest.size()-1] = '}'; + return manifest; +} + CCL_NAMESPACE_END diff --git a/intern/cycles/render/object.h b/intern/cycles/render/object.h index bd44b35aba3..288c3f5457a 100644 --- a/intern/cycles/render/object.h +++ b/intern/cycles/render/object.h @@ -116,6 +116,9 @@ public: void apply_static_transforms(DeviceScene *dscene, Scene *scene, Progress& progress); + string get_cryptomatte_objects(Scene *scene); + string get_cryptomatte_assets(Scene *scene); + protected: void device_update_object_transform(UpdateObjectTransformState *state, Object *ob, diff --git a/intern/cycles/render/shader.cpp b/intern/cycles/render/shader.cpp index 8d0cec7b14e..a827f611583 100644 --- a/intern/cycles/render/shader.cpp +++ b/intern/cycles/render/shader.cpp @@ -699,4 +699,20 @@ float ShaderManager::linear_rgb_to_gray(float3 c) return dot(c, rgb_to_y); } +string ShaderManager::get_cryptomatte_materials(Scene *scene) +{ + string manifest = "{"; + unordered_set<ustring, ustringHash> materials; + foreach(Shader *shader, scene->shaders) { + if(materials.count(shader->name)) { + continue; + } + materials.insert(shader->name); + uint32_t cryptomatte_id = util_murmur_hash3(shader->name.c_str(), shader->name.length(), 0); + manifest += string_printf("\"%s\":\"%08x\",", shader->name.c_str(), cryptomatte_id); + } + manifest[manifest.size()-1] = '}'; + return manifest; +} + CCL_NAMESPACE_END diff --git a/intern/cycles/render/shader.h b/intern/cycles/render/shader.h index 58314a1e310..80731384048 100644 --- a/intern/cycles/render/shader.h +++ b/intern/cycles/render/shader.h @@ -197,6 +197,8 @@ public: float linear_rgb_to_gray(float3 c); + string get_cryptomatte_materials(Scene *scene); + protected: ShaderManager(); |