diff options
Diffstat (limited to 'source/blender/draw/engines/eevee/eevee_cryptomatte.c')
-rw-r--r-- | source/blender/draw/engines/eevee/eevee_cryptomatte.c | 52 |
1 files changed, 48 insertions, 4 deletions
diff --git a/source/blender/draw/engines/eevee/eevee_cryptomatte.c b/source/blender/draw/engines/eevee/eevee_cryptomatte.c index 9150de7184a..ce714715c6c 100644 --- a/source/blender/draw/engines/eevee/eevee_cryptomatte.c +++ b/source/blender/draw/engines/eevee/eevee_cryptomatte.c @@ -125,6 +125,7 @@ void EEVEE_cryptomatte_renderpasses_init(EEVEE_Data *vedata) return; } if (eevee_cryptomatte_active_layers(view_layer) != 0) { + g_data->cryptomatte_session = BKE_cryptomatte_init(); g_data->render_passes |= EEVEE_RENDER_PASS_CRYPTOMATTE | EEVEE_RENDER_PASS_VOLUME_LIGHT; g_data->cryptomatte_accurate_mode = (view_layer->cryptomatte_flag & VIEW_LAYER_CRYPTOMATTE_ACCURATE) != 0; @@ -193,24 +194,26 @@ static DRWShadingGroup *eevee_cryptomatte_shading_group_create(EEVEE_Data *vedat const ViewLayer *view_layer = draw_ctx->view_layer; const eViewLayerCryptomatteFlags cryptomatte_layers = eevee_cryptomatte_active_layers( view_layer); + EEVEE_PrivateData *g_data = vedata->stl->g_data; float cryptohash[4] = {0.0f}; EEVEE_PassList *psl = vedata->psl; int layer_offset = 0; if ((cryptomatte_layers & VIEW_LAYER_CRYPTOMATTE_OBJECT) != 0) { - uint32_t cryptomatte_hash = BKE_cryptomatte_object_hash(ob); + uint32_t cryptomatte_hash = BKE_cryptomatte_object_hash(g_data->cryptomatte_session, ob); float cryptomatte_color_value = BKE_cryptomatte_hash_to_float(cryptomatte_hash); cryptohash[layer_offset] = cryptomatte_color_value; layer_offset++; } if ((cryptomatte_layers & VIEW_LAYER_CRYPTOMATTE_MATERIAL) != 0) { - uint32_t cryptomatte_hash = BKE_cryptomatte_material_hash(material); + uint32_t cryptomatte_hash = BKE_cryptomatte_material_hash(g_data->cryptomatte_session, + material); float cryptomatte_color_value = BKE_cryptomatte_hash_to_float(cryptomatte_hash); cryptohash[layer_offset] = cryptomatte_color_value; layer_offset++; } if ((cryptomatte_layers & VIEW_LAYER_CRYPTOMATTE_ASSET) != 0) { - uint32_t cryptomatte_hash = BKE_cryptomatte_asset_hash(ob); + uint32_t cryptomatte_hash = BKE_cryptomatte_asset_hash(g_data->cryptomatte_session, ob); float cryptomatte_color_value = BKE_cryptomatte_hash_to_float(cryptomatte_hash); cryptohash[layer_offset] = cryptomatte_color_value; layer_offset++; @@ -310,6 +313,12 @@ 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); +} + /** \} */ /* -------------------------------------------------------------------- */ @@ -677,6 +686,37 @@ void EEVEE_cryptomatte_render_result(RenderLayer *rl, } } +void EEVEE_cryptomatte_store_metadata(EEVEE_Data *vedata, RenderResult *render_result) +{ + EEVEE_PrivateData *g_data = vedata->stl->g_data; + const DRWContextState *draw_ctx = DRW_context_state_get(); + const ViewLayer *view_layer = draw_ctx->view_layer; + const eViewLayerCryptomatteFlags cryptomatte_layers = view_layer->cryptomatte_flag & + VIEW_LAYER_CRYPTOMATTE_ALL; + BLI_assert(g_data->cryptomatte_session); + if ((cryptomatte_layers & VIEW_LAYER_CRYPTOMATTE_OBJECT) != 0) { + BKE_cryptomatte_store_metadata(g_data->cryptomatte_session, + render_result, + view_layer, + VIEW_LAYER_CRYPTOMATTE_OBJECT, + "CryptoObject"); + } + if ((cryptomatte_layers & VIEW_LAYER_CRYPTOMATTE_MATERIAL) != 0) { + BKE_cryptomatte_store_metadata(g_data->cryptomatte_session, + render_result, + view_layer, + VIEW_LAYER_CRYPTOMATTE_MATERIAL, + "CryptoMaterial"); + } + if ((cryptomatte_layers & VIEW_LAYER_CRYPTOMATTE_ASSET) != 0) { + BKE_cryptomatte_store_metadata(g_data->cryptomatte_session, + render_result, + view_layer, + VIEW_LAYER_CRYPTOMATTE_ASSET, + "CryptoAsset"); + } +} + /** \} */ void EEVEE_cryptomatte_free(EEVEE_Data *vedata) @@ -684,4 +724,8 @@ void EEVEE_cryptomatte_free(EEVEE_Data *vedata) EEVEE_PrivateData *g_data = vedata->stl->g_data; MEM_SAFE_FREE(g_data->cryptomatte_accum_buffer); MEM_SAFE_FREE(g_data->cryptomatte_download_buffer); -} + if (g_data->cryptomatte_session) { + BKE_cryptomatte_free(g_data->cryptomatte_session); + g_data->cryptomatte_session = NULL; + } +}
\ No newline at end of file |