]> git.tdb.fi Git - libs/gl.git/blobdiff - shaderlib/shadow.glsl
Refactor ShadowMap to allow different types of lights
[libs/gl.git] / shaderlib / shadow.glsl
index 52cd7c13ab767a4cb07b24e11b4be7bb1c898df4..2fa1fd81686c832f3ce78463467500966c092a8e 100644 (file)
@@ -2,15 +2,16 @@ import msp_interface;
 
 struct ShadowParameters
 {
-       int enabled;
+       int type;
        float darkness;
-       mat4 shd_world_matrix;
+       int matrix_index;
        vec4 region;
 };
 
 uniform ShadowMap
 {
        ShadowParameters shadows[max_lights];
+       mat4 shd_world_matrix[max_lights];
 };
 
 uniform sampler2DShadow shadow_map;
@@ -22,10 +23,13 @@ virtual float get_shadow_factor(int index, vec4 world_pos)
 {
        if(use_shadow_map)
        {
-               if(shadows[index].enabled==0)
+               int type = shadows[index].type;
+               vec3 shadow_coord;
+               if(type==1)
+                       shadow_coord = (shd_world_matrix[shadows[index].matrix_index]*world_pos).xyz;
+               else
                        return 1.0;
 
-               vec3 shadow_coord = (shadows[index].shd_world_matrix*world_pos).xyz;
                if(shadow_coord.x<0 || shadow_coord.x>1 || shadow_coord.y<0 || shadow_coord.y>1)
                        return 1.0;