]> git.tdb.fi Git - libs/gl.git/blob - shaderlib/shadow.glsl
Don't dismantle aggregates which are function parameters
[libs/gl.git] / shaderlib / shadow.glsl
1 import msp_interface;
2
3 struct ShadowParameters
4 {
5         int enabled;
6         float darkness;
7         mat4 shd_world_matrix;
8         vec4 region;
9 };
10
11 uniform ShadowMap
12 {
13         ShadowParameters shadows[max_lights];
14 };
15
16 uniform sampler2DShadow shadow_map;
17
18 layout(constant_id=auto) const bool use_shadow_map = false;
19
20 #pragma MSP stage(fragment)
21 virtual float get_shadow_factor(int index, vec4 world_pos)
22 {
23         if(use_shadow_map)
24         {
25                 if(shadows[index].enabled==0)
26                         return 1.0;
27
28                 vec3 shadow_coord = (shadows[index].shd_world_matrix*world_pos).xyz;
29                 if(shadow_coord.x<0 || shadow_coord.x>1 || shadow_coord.y<0 || shadow_coord.y>1)
30                         return 1.0;
31
32                 vec4 region = shadows[index].region;
33                 float shadow_sample = texture(shadow_map, shadow_coord*vec3(region.zw, 1.0)+vec3(region.xy, 0.0));
34                 return mix(1.0, shadow_sample, shadows[index].darkness);
35         }
36         else
37                 return 1.0;
38 }