X-Git-Url: https://harrygodden.com/git/?a=blobdiff_plain;f=shaders%2Fcommon_world.glsl;h=ccf416eadd9a3d88469cb89388bab31167838ebc;hb=791f807111a1f740f745c67db642aa7a8bee56e8;hp=329226a65a971340bcdd6092147fadfe34c02eb8;hpb=ecc4dfbfb3adf91d2dfc03ba0ec9a821fcc2390c;p=carveJwlIkooP6JGAAIwe30JlM.git diff --git a/shaders/common_world.glsl b/shaders/common_world.glsl index 329226a..ccf416e 100644 --- a/shaders/common_world.glsl +++ b/shaders/common_world.glsl @@ -1,30 +1,29 @@ +layout (location = 0) out vec4 oColour; + layout (std140) uniform ub_world_lighting { - vec3 g_directional; - vec3 g_sun_colour; - vec3 g_shadow_colour; + vec4 g_light_colours[3]; + vec4 g_light_directions[3]; + vec4 g_ambient_colour; + 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; -uniform sampler2D g_world_depth; + int g_debug_indices; + int g_debug_complexity; -// Standard diffuse + spec models -// ============================== + // g_time ? -vec3 do_light_diffuse( vec3 vfrag, vec3 wnormal ) -{ - float flight = dot( g_directional, wnormal )*0.5+0.5; - return vfrag * mix( g_shadow_colour, g_sun_colour, flight ); -} + //vec4 g_point_light_positions[32]; + //vec4 g_point_light_colours[32]; +}; -vec3 do_light_spec( vec3 vfrag, vec3 wnormal, vec3 halfview, float fintensity ) -{ - vec3 specdir = reflect( -g_directional, wnormal ); - float spec = pow(max(dot( halfview, specdir ), 0.0), 10.0); - return vfrag + g_sun_colour*spec*fintensity; -} +uniform sampler2D g_world_depth; float world_depth_sample( vec3 pos ) { @@ -32,26 +31,118 @@ 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 = aCo + vdir; + vec3 sample_pos = aWorldCo + vdir; float height_sample = world_depth_sample( sample_pos ); float fdelta = height_sample - sample_pos.y; return clamp( fdelta, 0.1, 0.2 )-0.1; } -vec3 do_light_shadowing( vec3 vfrag ) +vec3 apply_fog( vec3 vfrag, float fdist ) +{ + float dist = pow(fdist*0.0008,1.2); + return mix( vfrag, vec3(0.55,0.76,1.0), min( 1.0, dist ) ); +} + + +// New lighting model + +vec3 newlight_compute_ambient() { - float faccum = 0.0; - faccum += shadow_sample( vec3( 0.0, 0.5, 0.0 )); - faccum += shadow_sample( vec3( 2.0, 0.3, 0.0 )); - faccum += shadow_sample( vec3( 3.0, 1.0, 0.0 )); - faccum += shadow_sample( vec3( 5.0, 1.0, 0.0 )); - faccum += shadow_sample( vec3( 0.0, 0.5, 0.0 )*1.5); - faccum += shadow_sample( vec3( 2.0, 0.3, 0.0 )*1.5); - faccum += shadow_sample( vec3( 3.0, 1.0, 0.0 )*1.5); - faccum += shadow_sample( vec3( 5.0, 1.0, 0.0 )*1.5); - return mix( vfrag, g_shadow_colour, faccum ); + return g_ambient_colour.rgb; +} + +float newlight_compute_sun_shadow( vec3 dir ) +{ + if( g_shadow_samples == 0 ) + { + return 1.0; + } + + float fspread = g_light_colours[0].w; + vec3 vdir = dir; + float flength = g_light_directions[0].w; + + float famt = 0.0; + famt+=shadow_sample((vdir+vec3(-0.563, 0.550, 0.307)*fspread)*flength*0.1); + famt+=shadow_sample((vdir+vec3( 0.808, 0.686, 0.346)*fspread)*flength*0.2); + famt+=shadow_sample((vdir+vec3( 0.787, 0.074,-0.065)*fspread)*flength*0.3); + famt+=shadow_sample((vdir+vec3(-0.593, 0.071,-0.425)*fspread)*flength*0.4); + famt+=shadow_sample((vdir+vec3(-0.790,-0.933,-0.875)*fspread)*flength*0.5); + 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); + + return 1.0 - famt; } +vec3 newlight_compute_world_diffuse( vec3 wnormal ) +{ + vec3 vtotal = g_ambient_colour.rgb; + + for( int i=0; i