]> git.tdb.fi Git - libs/gl.git/blobdiff - shaderlib/shadow.glsl
Add tetrahedron shadow maps for point lights
[libs/gl.git] / shaderlib / shadow.glsl
index 438af68d45181a86b6ec16f3cef065ba91ab88c4..d6e2b385f8955009abf737d998fbe7dd984f8996 100644 (file)
@@ -6,13 +6,13 @@ struct ShadowParameters
        float darkness;
        int matrix_index;
        vec4 region;
-       float bias;
+       vec2 bias;
 };
 
 uniform ShadowMap
 {
        ShadowParameters shadows[max_lights];
-       mat4 shd_world_matrix[max_lights];
+       mat4 shd_world_matrix[max_lights*4];
 };
 
 uniform sampler2DShadow shadow_map;
@@ -29,7 +29,21 @@ virtual float get_shadow_factor(int index, vec4 world_pos)
                if(type==1)
                {
                        shadow_coord = (shd_world_matrix[shadows[index].matrix_index]*world_pos).xyz;
-                       shadow_coord.z -= shadows[index].bias;
+                       shadow_coord.z -= shadows[index].bias.x;
+               }
+               else if(type==2)
+               {
+                       int base = shadows[index].matrix_index;
+                       vec4 clip_coord = shd_world_matrix[base]*world_pos;
+                       for(int i=1; i<4; ++i)
+                       {
+                               vec4 c = shd_world_matrix[base+i]*world_pos;
+                               if(c.w>clip_coord.w)
+                                       clip_coord = c;
+                       }
+                       shadow_coord = clip_coord.xyz/clip_coord.w;
+                       vec2 bias = shadows[index].bias;
+                       shadow_coord.z = (shadow_coord.z+bias.x)/bias.y-bias.x;
                }
                else
                        return 1.0;