X-Git-Url: https://harrygodden.com/git/?a=blobdiff_plain;ds=sidebyside;f=shaders%2Fcommon_world.glsl;h=a3b5ae3488b7acb8e083c82ab5827800a65c97b5;hb=98b9bcf0e10bc02cf679d03fa269613e140ba878;hp=45e12dff48267ba71c814a07a3272ea3eb29c339;hpb=f3a2490079baf440238b78e54f4476649eddbda2;p=carveJwlIkooP6JGAAIwe30JlM.git diff --git a/shaders/common_world.glsl b/shaders/common_world.glsl index 45e12df..a3b5ae3 100644 --- a/shaders/common_world.glsl +++ b/shaders/common_world.glsl @@ -2,6 +2,9 @@ layout (location = 0) out vec4 oColour; layout (std140) uniform ub_world_lighting { + vec4 g_cube_min; + vec4 g_cube_inv_range; + vec4 g_light_colours[3]; vec4 g_light_directions[3]; vec4 g_ambient_colour; @@ -9,12 +12,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; @@ -41,15 +50,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); @@ -64,7 +64,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 ) { @@ -72,7 +72,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; @@ -85,12 +85,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 ) @@ -119,14 +114,41 @@ vec3 newlight_compute_sun_spec( vec3 wnormal, vec3 halfview, float fintensity ) return vcolour*spec*fintensity; } -vec3 newlight_compute_quadratic( vec3 wnormal, vec3 halfview, - vec3 light_pos, vec3 light_colour ) +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, float max_dist, + vec3 light_colour, vec3 light_pos ) +{ + vec3 light_delta = light_pos-aWorldCo; + + float dist2 = dot(light_delta,light_delta); + + float quadratic = dist2*100.0; + float attenuation = 1.0f/( 1.0f + quadratic ); + attenuation *= max( dot( normalize(light_delta), wnormal ), 0.0 ); + + float falloff = max( 0.0, 1.0-(dist2*max_dist) ); + return light_colour * attenuation * falloff; +} + +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 ); - attenuation *= max( 0.0, dot( normalize(light_delta), wnormal ) ); - return light_colour*attenuation; + 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; }