X-Git-Url: https://harrygodden.com/git/?a=blobdiff_plain;f=shaders%2Fcommon_world.glsl;h=0bc4e7b6bbcceb2471c9c31523dcd8b8d1d4a035;hb=be5e25dee2c54c2a22ca3bbb5bbe0eb6149343be;hp=cb68f35a4cf7f2ebac919722825990b4d8a3eca4;hpb=6190deb68aa1c9e92ede62ea05c2a755bf5516de;p=carveJwlIkooP6JGAAIwe30JlM.git diff --git a/shaders/common_world.glsl b/shaders/common_world.glsl index cb68f35..0bc4e7b 100644 --- a/shaders/common_world.glsl +++ b/shaders/common_world.glsl @@ -54,19 +54,15 @@ float world_water_depth( vec3 pos ) return world_depth_sample( pos ) - ref_depth; } -float shadow_sample( vec3 vdir ) -{ - vec3 sample_pos = aWorldCo + vdir; - float height_sample = world_depth_sample( sample_pos ); +float shadow_sample( vec3 co ){ + float height_sample = world_depth_sample( co ); - float fdelta = height_sample - sample_pos.y; + float fdelta = height_sample - co.y; return clamp( fdelta, 0.2, 0.4 )-0.2; } -float newlight_compute_sun_shadow( vec3 dir ) -{ - if( g_shadow_samples == 0 ) - { +float newlight_compute_sun_shadow( vec3 co, vec3 dir ){ + if( g_shadow_samples == 0 ){ return 1.0; } @@ -74,15 +70,15 @@ float newlight_compute_sun_shadow( vec3 dir ) float flength = g_shadow_length; float famt = 0.0; - famt += shadow_sample((dir+vec3(-0.56,0.55, 0.30)*fspread)*flength*0.1); - famt += shadow_sample((dir+vec3( 0.80,0.68, 0.34)*fspread)*flength*0.2); - famt += shadow_sample((dir+vec3( 0.78,0.07,-0.06)*fspread)*flength*0.3); - famt += shadow_sample((dir+vec3(-0.59,0.07,-0.42)*fspread)*flength*0.4); + famt += shadow_sample(co+(dir+vec3(-0.56,0.55, 0.30)*fspread)*flength*0.1); + famt += shadow_sample(co+(dir+vec3( 0.80,0.68, 0.34)*fspread)*flength*0.2); + famt += shadow_sample(co+(dir+vec3( 0.78,0.07,-0.06)*fspread)*flength*0.3); + famt += shadow_sample(co+(dir+vec3(-0.59,0.07,-0.42)*fspread)*flength*0.4); - //famt+=shadow_sample((dir+vec3(-0.790,-0.933,-0.875)*fspread)*flength*0.5); - //famt+=shadow_sample((dir+vec3( 0.807,-0.690, 0.472)*fspread)*flength*0.6); - //famt+=shadow_sample((dir+vec3( 0.522,-0.379, 0.350)*fspread)*flength*0.7); - //famt+=shadow_sample((dir+vec3( 0.483, 0.201, 0.306)*fspread)*flength*0.8); + //famt+=shadow_sample(co+(dir+vec3(-0.790,-0.933,-0.875)*fspread)*flength*0.5); + //famt+=shadow_sample(co+(dir+vec3( 0.807,-0.690, 0.472)*fspread)*flength*0.6); + //famt+=shadow_sample(co+(dir+vec3( 0.522,-0.379, 0.350)*fspread)*flength*0.7); + //famt+=shadow_sample(co+(dir+vec3( 0.483, 0.201, 0.306)*fspread)*flength*0.8); return 1.0 - famt; } @@ -93,19 +89,11 @@ float newlight_specular( vec3 wnormal, vec3 dir, vec3 halfview, float exponent ) return pow(max(dot( halfview, specdir ), 0.0), exponent); } -vec3 scene_apply_fog( vec3 vfrag, vec3 colour, float fdist ) -{ +vec3 scene_apply_fog( vec3 vfrag, vec3 colour, float fdist ){ float dist = pow(fdist*0.0010,0.78); return mix( vfrag, colour, min( 1.0, dist ) ); } -vec3 rand33(vec3 p3) -{ - p3 = fract(p3 * vec3(.1031, .1030, .0973)); - p3 += dot(p3, p3.yxz+33.33); - return fract((p3.xxy + p3.yxx)*p3.zyx); -} - vec3 scene_calculate_light( int light_index, vec3 halfview, vec3 co, vec3 normal ) { @@ -170,8 +158,8 @@ vec3 world_compute_lighting( vec3 diffuse, vec3 normal, vec3 co, float fdist = length(halfview); halfview /= fdist; - float world_shadow = newlight_compute_sun_shadow( g_sun_dir.xyz - * (1.0/(max(g_sun_dir.y,0.0)+0.2)) ); + float world_shadow = newlight_compute_sun_shadow( + co, g_sun_dir.xyz * (1.0/(max(g_sun_dir.y,0.0)+0.2)) ); vec3 total_light = clearskies_lighting( normal, min( light_mask, world_shadow ), halfview );