From 3c23c43c13e48c5a80e722f8560286b90120506f Mon Sep 17 00:00:00 2001 From: Hugo Locurcio Date: Wed, 27 Jul 2022 03:01:12 +0200 Subject: [PATCH] Restore and fix post-process shadow blurring in 3D Co-authored-by: Clay John --- .../shaders/scene_forward_clustered.glsl | 2 +- .../shaders/scene_forward_lights_inc.glsl | 13 ++++--------- .../renderer_rd/shaders/scene_forward_mobile.glsl | 2 +- 3 files changed, 6 insertions(+), 11 deletions(-) diff --git a/servers/rendering/renderer_rd/shaders/scene_forward_clustered.glsl b/servers/rendering/renderer_rd/shaders/scene_forward_clustered.glsl index 5947fc535174..97bae786df56 100644 --- a/servers/rendering/renderer_rd/shaders/scene_forward_clustered.glsl +++ b/servers/rendering/renderer_rd/shaders/scene_forward_clustered.glsl @@ -1683,7 +1683,7 @@ void fragment_shader(in SceneData scene_data) { } #endif - blur_shadow(shadow); + shadow = blur_shadow(shadow); float size_A = sc_use_light_soft_shadows ? directional_lights.data[i].size : 0.0; diff --git a/servers/rendering/renderer_rd/shaders/scene_forward_lights_inc.glsl b/servers/rendering/renderer_rd/shaders/scene_forward_lights_inc.glsl index c92b29b14a28..c464265f958d 100644 --- a/servers/rendering/renderer_rd/shaders/scene_forward_lights_inc.glsl +++ b/servers/rendering/renderer_rd/shaders/scene_forward_lights_inc.glsl @@ -951,21 +951,16 @@ void reflection_process(uint ref_index, vec3 view, vec3 vertex, vec3 normal, flo } float blur_shadow(float shadow) { - return shadow; -#if 0 - //disabling for now, will investigate later float interp_shadow = shadow; - if (gl_HelperInvocation) { - interp_shadow = -4.0; // technically anything below -4 will do but just to make sure - } uvec2 fc2 = uvec2(gl_FragCoord.xy); - interp_shadow -= dFdx(interp_shadow) * (float(fc2.x & 1) - 0.5); - interp_shadow -= dFdy(interp_shadow) * (float(fc2.y & 1) - 0.5); + interp_shadow -= dFdxFine(interp_shadow) * (float(fc2.x & 1) - 0.5); + interp_shadow -= dFdyFine(interp_shadow) * (float(fc2.y & 1) - 0.5); + interp_shadow = min(interp_shadow, 1.0); if (interp_shadow >= 0.0) { shadow = interp_shadow; } + return shadow; -#endif } diff --git a/servers/rendering/renderer_rd/shaders/scene_forward_mobile.glsl b/servers/rendering/renderer_rd/shaders/scene_forward_mobile.glsl index 26d0de46c241..4999abddffe8 100644 --- a/servers/rendering/renderer_rd/shaders/scene_forward_mobile.glsl +++ b/servers/rendering/renderer_rd/shaders/scene_forward_mobile.glsl @@ -1408,7 +1408,7 @@ void main() { shadow = float(shadow1 >> ((i - 4) * 8) & 0xFF) / 255.0; } #endif - blur_shadow(shadow); + shadow = blur_shadow(shadow); light_compute(normal, directional_lights.data[i].direction, normalize(view), 0.0, directional_lights.data[i].color * directional_lights.data[i].energy, shadow, f0, orms, 1.0, albedo, alpha, #ifdef LIGHT_BACKLIGHT_USED