X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=shaderlib%2Fshadow.glsl;h=d6e2b385f8955009abf737d998fbe7dd984f8996;hb=a01be4f86739fec1ab25d5dc2180c9b0a1a5380c;hp=438af68d45181a86b6ec16f3cef065ba91ab88c4;hpb=b733c793381e78637f52c7f77cc4f69e914918e1;p=libs%2Fgl.git diff --git a/shaderlib/shadow.glsl b/shaderlib/shadow.glsl index 438af68d..d6e2b385 100644 --- a/shaderlib/shadow.glsl +++ b/shaderlib/shadow.glsl @@ -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;