[Bf-blender-cvs] [5b396924091] tmp-eevee-shadow-commit-mp: EEVEE Shadows: Prevent the far plane from casting shadows onto farther objects

Miguel Pozo noreply at git.blender.org
Mon Feb 6 18:05:34 CET 2023


Commit: 5b39692409143f9783a9ed1731821c3b3a0b37ac
Author: Miguel Pozo
Date:   Mon Feb 6 18:03:22 2023 +0100
Branches: tmp-eevee-shadow-commit-mp
https://developer.blender.org/rB5b39692409143f9783a9ed1731821c3b3a0b37ac

EEVEE Shadows: Prevent the far plane from casting shadows onto farther objects

===================================================================

M	source/blender/draw/engines/eevee_next/shaders/eevee_shadow_lib.glsl
M	source/blender/draw/engines/eevee_next/shaders/eevee_shadow_page_clear_comp.glsl

===================================================================

diff --git a/source/blender/draw/engines/eevee_next/shaders/eevee_shadow_lib.glsl b/source/blender/draw/engines/eevee_next/shaders/eevee_shadow_lib.glsl
index 89bfca6c14d..cf2fcf9dc28 100644
--- a/source/blender/draw/engines/eevee_next/shaders/eevee_shadow_lib.glsl
+++ b/source/blender/draw/engines/eevee_next/shaders/eevee_shadow_lib.glsl
@@ -158,6 +158,8 @@ ShadowSample shadow_punctual_sample_get(
   samp.bias = shadow_slope_bias_get(atlas_size, light, lNg, lP, samp.uv, samp.tile.lod);
 
   float occluder_ndc = shadow_tile_depth_get(atlas_tx, samp.tile, samp.uv);
+  /* Depth is cleared to FLT_MAX, we clamp it to 1 in punctual shadows for better precission */
+  occluder_ndc = clamp(occluder_ndc, 0, 1);
 
   /* NOTE: Given to be both positive, so can use intBitsToFloat instead of orderedInt version. */
   float near = intBitsToFloat(light.clip_near);
@@ -217,4 +219,4 @@ ShadowSample shadow_sample(const bool is_directional,
   }
 }
 
-/** \} */
\ No newline at end of file
+/** \} */
diff --git a/source/blender/draw/engines/eevee_next/shaders/eevee_shadow_page_clear_comp.glsl b/source/blender/draw/engines/eevee_next/shaders/eevee_shadow_page_clear_comp.glsl
index 1135af01376..3179b1667ca 100644
--- a/source/blender/draw/engines/eevee_next/shaders/eevee_shadow_page_clear_comp.glsl
+++ b/source/blender/draw/engines/eevee_next/shaders/eevee_shadow_page_clear_comp.glsl
@@ -12,5 +12,6 @@ void main()
   uvec2 page_co = unpackUvec2x16(clear_page_buf[gl_GlobalInvocationID.z]);
   uvec2 page_texel = page_co * pages_infos_buf.page_size + gl_GlobalInvocationID.xy;
 
-  imageStore(atlas_img, ivec2(page_texel), uvec4(floatBitsToUint(1.0)));
-}
\ No newline at end of file
+  /* Clear to FLT_MAX instead of 1 so the far plane doesn't cast shadows onto farther objects */
+  imageStore(atlas_img, ivec2(page_texel), uvec4(floatBitsToUint(FLT_MAX)));
+}



More information about the Bf-blender-cvs mailing list