3 struct ShadowParameters
14 ShadowParameters shadows[max_lights];
15 mat4 shd_world_matrix[max_lights*4];
18 uniform sampler2DShadow shadow_map;
20 layout(constant_id=auto) const bool use_shadow_map = false;
22 #pragma MSP stage(fragment)
23 virtual float get_shadow_factor(int index, vec4 world_pos)
27 int type = shadows[index].type;
31 shadow_coord = (shd_world_matrix[shadows[index].matrix_index]*world_pos).xyz;
32 shadow_coord.z -= shadows[index].bias.x;
36 int base = shadows[index].matrix_index;
37 vec4 clip_coord = shd_world_matrix[base]*world_pos;
38 for(int i=1; i<4; ++i)
40 vec4 c = shd_world_matrix[base+i]*world_pos;
44 shadow_coord = clip_coord.xyz/clip_coord.w;
45 vec2 bias = shadows[index].bias;
46 shadow_coord.z = (shadow_coord.z+bias.x)/bias.y-bias.x;
51 if(shadow_coord.x<0 || shadow_coord.x>1 || shadow_coord.y<0 || shadow_coord.y>1)
54 vec4 region = shadows[index].region;
55 float shadow_sample = texture(shadow_map, vec3(shadow_coord.xy*region.zw+region.xy, shadow_coord.z));
56 return mix(1.0, shadow_sample, shadows[index].darkness);