]> git.tdb.fi Git - libs/gl.git/blobdiff - shaderlib/shadow.glsl
Apply shadow depth bias in a different way
[libs/gl.git] / shaderlib / shadow.glsl
index 2fa1fd81686c832f3ce78463467500966c092a8e..438af68d45181a86b6ec16f3cef065ba91ab88c4 100644 (file)
@@ -6,6 +6,7 @@ struct ShadowParameters
        float darkness;
        int matrix_index;
        vec4 region;
+       float bias;
 };
 
 uniform ShadowMap
@@ -26,7 +27,10 @@ virtual float get_shadow_factor(int index, vec4 world_pos)
                int type = shadows[index].type;
                vec3 shadow_coord;
                if(type==1)
+               {
                        shadow_coord = (shd_world_matrix[shadows[index].matrix_index]*world_pos).xyz;
+                       shadow_coord.z -= shadows[index].bias;
+               }
                else
                        return 1.0;
 
@@ -34,7 +38,7 @@ virtual float get_shadow_factor(int index, vec4 world_pos)
                        return 1.0;
 
                vec4 region = shadows[index].region;
-               float shadow_sample = texture(shadow_map, shadow_coord*vec3(region.zw, 1.0)+vec3(region.xy, 0.0));
+               float shadow_sample = texture(shadow_map, vec3(shadow_coord.xy*region.zw+region.xy, shadow_coord.z));
                return mix(1.0, shadow_sample, shadows[index].darkness);
        }
        else