Eevee Cryptomatte: Store hashes in render result meta data
Stores cryptomatte hashes as meta data to the render result. Compositors could use this for lookup on names in stead of hashes. Differential Revision: https://developer.blender.org/D9553
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -570,8 +570,6 @@ static void eevee_render_to_image(void *vedata,
|
||||
EEVEE_motion_blur_data_free(&ved->stl->effects->motion_blur);
|
||||
|
||||
if (RE_engine_test_break(engine)) {
|
||||
/* Cryptomatte buffers are freed during render_read_result */
|
||||
EEVEE_cryptomatte_free(vedata);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -586,6 +584,16 @@ static void eevee_render_to_image(void *vedata,
|
||||
}
|
||||
}
|
||||
|
||||
static void eevee_store_metadata(void *vedata, struct RenderResult *render_result)
|
||||
{
|
||||
EEVEE_Data *ved = (EEVEE_Data *)vedata;
|
||||
EEVEE_PrivateData *g_data = ved->stl->g_data;
|
||||
if (g_data->render_passes & EEVEE_RENDER_PASS_CRYPTOMATTE) {
|
||||
EEVEE_cryptomatte_store_metadata(ved, render_result);
|
||||
EEVEE_cryptomatte_free(ved);
|
||||
}
|
||||
}
|
||||
|
||||
static void eevee_engine_free(void)
|
||||
{
|
||||
EEVEE_shaders_free();
|
||||
@@ -611,6 +619,7 @@ DrawEngineType draw_engine_eevee_type = {
|
||||
&eevee_view_update,
|
||||
&eevee_id_update,
|
||||
&eevee_render_to_image,
|
||||
&eevee_store_metadata,
|
||||
};
|
||||
|
||||
RenderEngineType DRW_engine_viewport_eevee_type = {
|
||||
|
||||
@@ -977,6 +977,7 @@ typedef struct EEVEE_PrivateData {
|
||||
eViewLayerEEVEEPassType render_passes;
|
||||
int aov_hash;
|
||||
int num_aovs_used;
|
||||
struct CryptomatteSession *cryptomatte_session;
|
||||
bool cryptomatte_accurate_mode;
|
||||
EEVEE_CryptomatteSample *cryptomatte_accum_buffer;
|
||||
float *cryptomatte_download_buffer;
|
||||
@@ -1246,6 +1247,7 @@ 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);
|
||||
@@ -1261,6 +1263,7 @@ void EEVEE_cryptomatte_render_result(struct RenderLayer *rl,
|
||||
const rcti *rect,
|
||||
EEVEE_Data *vedata,
|
||||
EEVEE_ViewLayerData *sldata);
|
||||
void EEVEE_cryptomatte_store_metadata(EEVEE_Data *vedata, struct RenderResult *render_result);
|
||||
void EEVEE_cryptomatte_free(EEVEE_Data *vedata);
|
||||
|
||||
/* eevee_occlusion.c */
|
||||
|
||||
@@ -510,7 +510,6 @@ static void eevee_render_result_cryptomatte(RenderLayer *rl,
|
||||
if ((vedata->stl->g_data->render_passes & EEVEE_RENDER_PASS_CRYPTOMATTE) != 0) {
|
||||
EEVEE_cryptomatte_render_result(rl, viewname, rect, vedata, sldata);
|
||||
}
|
||||
EEVEE_cryptomatte_free(vedata);
|
||||
}
|
||||
|
||||
static void eevee_render_draw_background(EEVEE_Data *vedata)
|
||||
|
||||
@@ -255,6 +255,10 @@ 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