X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=shaderlib%2Fshadow.glsl;h=d6e2b385f8955009abf737d998fbe7dd984f8996;hb=54fdd850d1e657bc357d859a532497905ded741a;hp=2fa1fd81686c832f3ce78463467500966c092a8e;hpb=bace0b24414abc7b3ba46df3a9fd7408d7479a5e;p=libs%2Fgl.git diff --git a/shaderlib/shadow.glsl b/shaderlib/shadow.glsl index 2fa1fd81..d6e2b385 100644 --- a/shaderlib/shadow.glsl +++ b/shaderlib/shadow.glsl @@ -6,12 +6,13 @@ struct ShadowParameters float darkness; int matrix_index; vec4 region; + 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; @@ -26,7 +27,24 @@ 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.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; @@ -34,7 +52,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