Return not shadow if shadow map contains max value
@@ -150,9 +150,15 @@ vec3 attenuate(vec3 light_color, vec3 attenuation, float distance)
float is_visible(sampler2D shadowMap, vec4 shadow_coord, vec2 offset)
{
vec2 uv = (shadow_coord.xy + offset)/shadow_coord.w;
- float true_distance = (shadow_coord.z - 0.005)/shadow_coord.w;
+ if(uv.x < 0.0 || uv.x > 1.0 || uv.y < 0.0 || uv.y > 1.0) {
+ return 1.0;
+ }
float shadow_cast_distance = texture(shadowMap, uv).x;
- return uv.x < 0.0 || uv.x > 1.0 || uv.y < 0.0 || uv.y > 1.0 || shadow_cast_distance > true_distance ? 1.0 : 0.0;
+ if(shadow_cast_distance > 0.999) {
+ return 1.0;
+ }
+ float true_distance = (shadow_coord.z - 0.005)/shadow_coord.w;
+ return shadow_cast_distance > true_distance ? 1.0 : 0.0;
}
float calculate_shadow(sampler2D shadowMap, mat4 shadowMVP, vec3 position)
