X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=shaderlib%2Fshadow.glsl;h=2fa1fd81686c832f3ce78463467500966c092a8e;hb=bace0b24414abc7b3ba46df3a9fd7408d7479a5e;hp=d751b460778af84155e127b828d21c6f4f614d33;hpb=842c817bb679a5a0abc05e8149e2e6e0ae1a0412;p=libs%2Fgl.git diff --git a/shaderlib/shadow.glsl b/shaderlib/shadow.glsl index d751b460..2fa1fd81 100644 --- a/shaderlib/shadow.glsl +++ b/shaderlib/shadow.glsl @@ -1,20 +1,41 @@ import msp_interface; -layout(constant_id=auto) const bool use_shadow_map = false; +struct ShadowParameters +{ + int type; + float darkness; + int matrix_index; + vec4 region; +}; -#pragma MSP stage(vertex) -void shadow_transform(vec4 eye_vertex) +uniform ShadowMap { - out vec3 shadow_coord = (shd_eye_matrix*eye_vertex).xyz; -} + ShadowParameters shadows[max_lights]; + mat4 shd_world_matrix[max_lights]; +}; + +uniform sampler2DShadow shadow_map; + +layout(constant_id=auto) const bool use_shadow_map = false; #pragma MSP stage(fragment) -float get_shadow_factor(int index) +virtual float get_shadow_factor(int index, vec4 world_pos) { if(use_shadow_map) { - float shadow_sample = texture(shadow_map, shadow_coord); - return mix(1.0, shadow_sample, shadow_darkness); + 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; + + if(shadow_coord.x<0 || shadow_coord.x>1 || shadow_coord.y<0 || shadow_coord.y>1) + 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)); + return mix(1.0, shadow_sample, shadows[index].darkness); } else return 1.0;