X-Git-Url: https://harrygodden.com/git/?a=blobdiff_plain;f=shaders%2Fcommon_world.glsl;h=ccf416eadd9a3d88469cb89388bab31167838ebc;hb=791f807111a1f740f745c67db642aa7a8bee56e8;hp=b5c79dfac683779b4ddfe6977f7c20c823b929f5;hpb=aa4c26eae2208872824e0eb5b71bc05c16d43242;p=carveJwlIkooP6JGAAIwe30JlM.git diff --git a/shaders/common_world.glsl b/shaders/common_world.glsl index b5c79df..ccf416e 100644 --- a/shaders/common_world.glsl +++ b/shaders/common_world.glsl @@ -9,12 +9,18 @@ layout (std140) uniform ub_world_lighting vec4 g_water_plane; vec4 g_depth_bounds; float g_water_fog; + float g_time; int g_light_count; int g_light_preview; int g_shadow_samples; - vec4 g_point_light_positions[32]; - vec4 g_point_light_colours[32]; + int g_debug_indices; + int g_debug_complexity; + + // g_time ? + + //vec4 g_point_light_positions[32]; + //vec4 g_point_light_colours[32]; }; uniform sampler2D g_world_depth; @@ -25,6 +31,13 @@ float world_depth_sample( vec3 pos ) return texture( g_world_depth, depth_coord ).r; } +float world_water_depth( vec3 pos ) +{ + vec2 depth_coord = (pos.xz - g_depth_bounds.xy) * g_depth_bounds.zw; + float ref_depth = g_water_plane.y*g_water_plane.w; + return texture( g_world_depth, depth_coord ).g - ref_depth; +} + float shadow_sample( vec3 vdir ) { vec3 sample_pos = aWorldCo + vdir; @@ -34,15 +47,6 @@ float shadow_sample( vec3 vdir ) return clamp( fdelta, 0.1, 0.2 )-0.1; } -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 apply_fog( vec3 vfrag, float fdist ) { float dist = pow(fdist*0.0008,1.2); @@ -57,7 +61,7 @@ vec3 newlight_compute_ambient() return g_ambient_colour.rgb; } -float newlight_compute_sun_shadow() +float newlight_compute_sun_shadow( vec3 dir ) { if( g_shadow_samples == 0 ) { @@ -65,7 +69,7 @@ float newlight_compute_sun_shadow() } float fspread = g_light_colours[0].w; - vec3 vdir = g_light_directions[0].xyz; + vec3 vdir = dir; float flength = g_light_directions[0].w; float famt = 0.0; @@ -78,12 +82,7 @@ float newlight_compute_sun_shadow() 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.1 ); - float player_shadow = max( 1.0-dist_to_player*2.7, 0.0 ); - player_shadow *= player_shadow*player_shadow*player_shadow; - - return 1.0 - max( player_shadow*0.8, famt ); + return 1.0 - famt; } vec3 newlight_compute_world_diffuse( vec3 wnormal ) @@ -112,8 +111,14 @@ vec3 newlight_compute_sun_spec( vec3 wnormal, vec3 halfview, float fintensity ) return vcolour*spec*fintensity; } +float newlight_specular( vec3 wnormal, vec3 dir, vec3 halfview, float exponent ) +{ + vec3 specdir = reflect( -dir, wnormal ); + return pow(max(dot( halfview, specdir ), 0.0), exponent); +} + vec3 newlight_compute_quadratic( vec3 wnormal, vec3 halfview, - vec3 light_pos, vec3 light_colour ) + vec3 light_colour, vec3 light_pos ) { vec3 light_delta = (light_pos-aWorldCo) * 10.0; @@ -123,3 +128,21 @@ vec3 newlight_compute_quadratic( vec3 wnormal, vec3 halfview, return light_colour*attenuation; } + +vec3 newlight_compute_spot( vec3 wnormal, vec3 halfview, + vec3 light_colour, vec3 light_pos, + vec4 light_dir ) +{ + vec3 light_delta = (light_pos-aWorldCo) * 10.0; + + float quadratic = dot(light_delta,light_delta); + float attenuation = 1.0f/( 1.0f + quadratic ); + + light_delta = normalize( light_delta ); + attenuation *= max( 0.0, dot( light_delta, wnormal ) ); + + float spot_theta = max( 0.0, dot( light_delta, -light_dir.xyz ) ), + falloff = max( 0.0,( spot_theta - light_dir.w ) / (1.0-light_dir.w) ); + + return light_colour*attenuation*falloff; +}