EEVEE-Next: Fix decrepancy in shadow rendering on mac M1

The difference was that the depth slope bias was not
written to the depth buffer which could lead to situation
where the value written to the color target was greater
than it should.

Use the depth write feature to output the slope biased
depth. Output 1 depth to not discard and loose the benefit
of early depth test.
This commit is contained in:
Clément Foucault
2024-04-26 23:18:59 +02:00
parent 7e2075b809
commit d11c6962b0
2 changed files with 17 additions and 9 deletions

View File

@@ -26,10 +26,20 @@ void main()
{
float f_depth = gl_FragCoord.z + fwidth(gl_FragCoord.z);
#ifdef SHADOW_UPDATE_TBDR
/* We need to write to gl_FragDepth un-conditionnally. So we cannot early exit or use discard. */
# define discard_result f_depth = 1.0;
#else
# define discard_result \
discard; \
return;
#endif
/* Avoid values greater than 1. */
f_depth = saturate(f_depth);
/* Clip to light shape. */
if (length_squared(shadow_clip.vector) < 1.0) {
discard;
return;
discard_result;
}
#ifdef MAT_TRANSPARENT
@@ -42,8 +52,7 @@ void main()
float transparency = average(g_transmittance);
if (transparency > random_threshold) {
discard;
return;
discard_result;
}
#endif
@@ -78,8 +87,7 @@ void main()
#endif
#ifdef SHADOW_UPDATE_TBDR
/* Store output depth in tile memory using F32 attachment. NOTE: As depth testing is enabled,
* only the closest fragment will store the result. */
gl_FragDepth = f_depth;
out_depth = f_depth;
#endif
}

View File

@@ -250,9 +250,6 @@ GPU_SHADER_CREATE_INFO(eevee_surf_shadow_atomic)
.additional_info("eevee_surf_shadow")
.define("SHADOW_UPDATE_ATOMIC_RASTER")
.builtins(BuiltinBits::TEXTURE_ATOMIC)
/* Early fragment test for speeding up platforms that requires a depth buffer. */
/* NOTE: This removes the possibility of using gl_FragDepth. */
.early_fragment_test(true)
.vertex_out(eevee_surf_shadow_atomic_iface)
.storage_buf(SHADOW_RENDER_MAP_BUF_SLOT,
Qualifier::READ,
@@ -268,6 +265,9 @@ GPU_SHADER_CREATE_INFO(eevee_surf_shadow_tbdr)
.additional_info("eevee_surf_shadow")
.define("SHADOW_UPDATE_TBDR")
.builtins(BuiltinBits::LAYER)
/* Use greater depth write to avoid loosing the early Z depth test but ensure correct fragment
ordering after slope bias. */
.depth_write(DepthWrite::GREATER)
/* F32 color attachment for on-tile depth accumulation without atomics. */
.fragment_out(0, Type::FLOAT, "out_depth", DualBlend::NONE, SHADOW_ROG_ID);