There is in fact a feedback loop problem
GPU_framebuffer_ensure_config(&fbl->composite_fb, {
GPU_ATTACHMENT_TEXTURE(dtxl->depth),
GPU_ATTACHMENT_TEXTURE(e_data.composite_buffer_tx),
});static void workbench_composite_uniforms(WORKBENCH_PrivateData *wpd, DRWShadingGroup *grp)
{
DefaultTextureList *dtxl = DRW_viewport_texture_list_get();
DRW_shgroup_uniform_texture_ref(grp, "depthBuffer", &dtxl->depth);You cannot read the depth buffer and test the stencil buffer in the same pass, it's undefined behaviour : https://stackoverflow.com/questions/36782796/read-depth-values-while-stencil-testingsame-texture
So a few workaround possible:
- Apply shadow in MULTIPLY mode in a separate pass. (not the best, performance wise).
- Split the composite shader to not use the depth buffer (that should be simple since it's only used to handle the background).
So I would suggest the 2nd option.