diff --git a/files/shaders/objects_fragment.glsl b/files/shaders/objects_fragment.glsl index 98b11f420..7ba3d1de0 100644 --- a/files/shaders/objects_fragment.glsl +++ b/files/shaders/objects_fragment.glsl @@ -124,8 +124,19 @@ void main() float shadowing = 1.0; #if SHADOWS + bool doneShadows = false; @foreach shadow_texture_unit_index @shadow_texture_unit_list - shadowing *= shadow2DProj(shadowTexture@shadow_texture_unit_index, shadowSpaceCoords@shadow_texture_unit_index).r; + if (!doneShadows) + { + vec2 shadowXY = shadowSpaceCoords@shadow_texture_unit_index.xy / shadowSpaceCoords@shadow_texture_unit_index.w; + if (all(lessThan(shadowXY, vec2(1.0, 1.0))) && all(greaterThan(shadowXY, vec2(0.0, 0.0)))) + { + shadowing *= shadow2DProj(shadowTexture@shadow_texture_unit_index, shadowSpaceCoords@shadow_texture_unit_index).r; + + if (all(lessThan(shadowXY, vec2(0.95, 0.95))) && all(greaterThan(shadowXY, vec2(0.05, 0.05)))) + doneShadows = true; + } + } @endforeach #endif // SHADOWS diff --git a/files/shaders/terrain_fragment.glsl b/files/shaders/terrain_fragment.glsl index 77b41eab9..68ab1bbdd 100644 --- a/files/shaders/terrain_fragment.glsl +++ b/files/shaders/terrain_fragment.glsl @@ -76,8 +76,19 @@ void main() float shadowing = 1.0; #if SHADOWS + bool doneShadows = false; @foreach shadow_texture_unit_index @shadow_texture_unit_list - shadowing *= shadow2DProj(shadowTexture@shadow_texture_unit_index, shadowSpaceCoords@shadow_texture_unit_index).r; + if (!doneShadows) + { + vec2 shadowXY = shadowSpaceCoords@shadow_texture_unit_index.xy / shadowSpaceCoords@shadow_texture_unit_index.w; + if (all(lessThan(shadowXY, vec2(1.0, 1.0))) && all(greaterThan(shadowXY, vec2(0.0, 0.0)))) + { + shadowing *= shadow2DProj(shadowTexture@shadow_texture_unit_index, shadowSpaceCoords@shadow_texture_unit_index).r; + + if (all(lessThan(shadowXY, vec2(0.95, 0.95))) && all(greaterThan(shadowXY, vec2(0.05, 0.05)))) + doneShadows = true; + } + } @endforeach #endif // SHADOWS diff --git a/files/shaders/water_fragment.glsl b/files/shaders/water_fragment.glsl index c277e86bc..e953b2611 100644 --- a/files/shaders/water_fragment.glsl +++ b/files/shaders/water_fragment.glsl @@ -168,9 +168,19 @@ void main(void) #if SHADOWS float shadowing = 1.0; - + bool doneShadows = false; @foreach shadow_texture_unit_index @shadow_texture_unit_list - shadowing *= shadow2DProj(shadowTexture@shadow_texture_unit_index, shadowSpaceCoords@shadow_texture_unit_index).r; + if (!doneShadows) + { + vec2 shadowXY = shadowSpaceCoords@shadow_texture_unit_index.xy / shadowSpaceCoords@shadow_texture_unit_index.w; + if (all(lessThan(shadowXY, vec2(1.0, 1.0))) && all(greaterThan(shadowXY, vec2(0.0, 0.0)))) + { + shadowing *= shadow2DProj(shadowTexture@shadow_texture_unit_index, shadowSpaceCoords@shadow_texture_unit_index).r; + + if (all(lessThan(shadowXY, vec2(0.95, 0.95))) && all(greaterThan(shadowXY, vec2(0.05, 0.05)))) + doneShadows = true; + } + } @endforeach float shadow = shadowing;