Hey People!
I am trying to get Eevee to output a rough approximated thickness of a given camera view, it needs to get outputted as a render layer so I can render it to an EXR.
My basic approach is the following:
- Hijack the Mist Shader to just output depth.
- Render the depth prepass twice once with GREATER EQUAL
- Then render mist (e.g. just copy depth to mist rendertarget)
- Render depth normally and proceed as usual (without rendering mist again).
I have succeeded in getting Mist to output depth (modified shader, set g_data->renderpass_postprocess = PASS_POST_DEPTH),
however my efforts to get the inverse depth pass to work have been flaunted.
So far I tried adding a new pass to Eevee by adding it to eevee_materials.c:
DRWState state_invdepth = DRW_STATE_WRITE_DEPTH |
DRW_STATE_DEPTH_GREATER_EQUAL;
EEVEE_PASS_CREATE(invdepth, state_invdepth);
EEVEE_CLIP_PASS_CREATE(invdepth, state_invdepth);
And trying to invoke it before the depth prepass:
{
/* Inverse Depth for Thickness! */
if (fbl->mist_accum_fb != NULL) {
GPU_framebuffer_bind(fbl->main_fb);
GPU_framebuffer_clear_color_depth_stencil(fbl->main_fb, clear_col, 0.0f, clear_stencil);
DRW_draw_pass(psl->invdepth_ps);
GPU_framebuffer_bind(fbl->mist_accum_fb);
const float clear[4] = {0.0f, 0.0f, 0.0f, 0.0f};
GPU_framebuffer_clear_color(fbl->mist_accum_fb, clear);
DRW_draw_pass(psl->mist_accum_ps);
/* Restore */
GPU_framebuffer_bind(fbl->main_fb);
}
}
GPU_framebuffer_clear_color_depth_stencil(fbl->main_fb, clear_col, clear_depth, clear_stencil);
/* Depth prepass */
DRW_draw_pass(psl->depth_ps);
Unfortunately mist still ends up outputting normal prepass depth!
Maybe someone has a hint for me of how to get it working?
I am fairly new to working in the blender codebase so it is not quite obvious to me how it works exactly e.g. order of draw calls and all that! Would be glad if someone can point me into the right direction!
Thank you!