X-Git-Url: https://harrygodden.com/git/?a=blobdiff_plain;f=shaders%2Fcommon_world.glsl;h=ccf416eadd9a3d88469cb89388bab31167838ebc;hb=791f807111a1f740f745c67db642aa7a8bee56e8;hp=043cf26898971b270032a2b5ff5bd78c4bacd202;hpb=409edea2cf6271956137918e4e0b4f1c2addf620;p=carveJwlIkooP6JGAAIwe30JlM.git diff --git a/shaders/common_world.glsl b/shaders/common_world.glsl index 043cf26..ccf416e 100644 --- a/shaders/common_world.glsl +++ b/shaders/common_world.glsl @@ -9,10 +9,14 @@ 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; + int g_debug_indices; + int g_debug_complexity; + // g_time ? //vec4 g_point_light_positions[32]; @@ -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; @@ -107,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; @@ -118,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; +}