X-Git-Url: https://harrygodden.com/git/?a=blobdiff_plain;f=shaders%2Fcommon_world.glsl;h=da87204bbebe620f803961ae4755b45cf5d0870d;hb=fc1d543772607ab0643e54ebd2db9ec9dce614d1;hp=5e1a8919070e9f1865a1250c745f98f329222ed1;hpb=6d66c67945f84476d6ac75a0497007cc30bcf58c;p=carveJwlIkooP6JGAAIwe30JlM.git diff --git a/shaders/common_world.glsl b/shaders/common_world.glsl index 5e1a891..da87204 100644 --- a/shaders/common_world.glsl +++ b/shaders/common_world.glsl @@ -1,3 +1,5 @@ +layout (location = 0) out vec4 oColour; + layout (std140) uniform ub_world_lighting { vec4 g_light_colours[3]; @@ -9,6 +11,7 @@ layout (std140) uniform ub_world_lighting float g_water_fog; int g_light_count; int g_light_preview; + int g_shadow_samples; }; uniform sampler2D g_world_depth; @@ -71,8 +74,23 @@ vec3 do_light_shadowing_old( vec3 vfrag ) return mix( vfrag, g_ambient_colour.rgb, faccum ); } +// FIXME +float sdLine( vec3 p, vec3 a, vec3 b ) +{ + vec3 pa = p - a; + vec3 ba = b - a; + + float h = clamp( dot(pa,ba)/dot(ba,ba), 0.0, 1.0 ); + return length( pa - ba*h ); +} + vec3 do_light_shadowing( vec3 vfrag ) { + if( g_shadow_samples == 0 ) + { + return vfrag; + } + float fspread = g_light_colours[0].w; vec3 vdir = g_light_directions[0].xyz; float flength = g_light_directions[0].w; @@ -86,6 +104,13 @@ vec3 do_light_shadowing( vec3 vfrag ) famt+=shadow_sample((vdir+vec3( 0.807,-0.690, 0.472)*fspread)*flength*0.6); famt+=shadow_sample((vdir+vec3( 0.522,-0.379, 0.350)*fspread)*flength*0.7); famt+=shadow_sample((vdir+vec3( 0.483, 0.201, 0.306)*fspread)*flength*0.8); + + // player shadow + float dist_to_player = max( 0.0, sdLine( aWorldCo, uBoard0, uBoard1 )-0.03 ); + float player_shadow = max( 1.0-dist_to_player*1.7, 0.0 ); + player_shadow *= player_shadow*player_shadow*player_shadow; + + famt = max( player_shadow*0.6, famt ); return mix( vfrag, g_ambient_colour.rgb, famt ); }