water fog material prop; ragdoll float only on drowned
[carveJwlIkooP6JGAAIwe30JlM.git] / shaders / common_world.glsl
index 57b45411a1e924f7f581cd75b96c8784c3bfed1e..0bc4e7b6bbcceb2471c9c31523dcd8b8d1d4a035 100644 (file)
@@ -16,9 +16,12 @@ layout (std140) uniform ub_world_lighting
    vec4 g_sunset_ambient;
    vec4 g_sun_colour;
    vec4 g_sun_dir;
+   vec4 g_board_0;
+   vec4 g_board_1;
 
    float g_water_fog;
    float g_time;
+   float g_realtime;
    float g_shadow_length;
    float g_shadow_spread;
 
@@ -47,24 +50,19 @@ float world_depth_sample( vec3 pos )
 
 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;
+   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;
    }
 
@@ -72,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;
 }
@@ -91,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 )
 {
@@ -117,18 +107,18 @@ vec3 scene_calculate_light( int light_index,
    light_delta = normalize( light_delta );
 
    float quadratic = dist2*100.0;
-   float attenuation  = 1.0f/( 1.0f + quadratic );
+   float attenuation  = 1.0/( 1.0 + quadratic );
          attenuation *= max( dot( light_delta, normal ), 0.0 );
 
    float falloff = max( 0.0, 1.0-(dist2*light_co.w) );
 
-   if( light_dir.w < 0.999999 )
-   {
+   if( light_dir.w < 0.999999 ){
       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.rgb * attenuation * falloff;
+   return light_colour.rgb * attenuation * falloff 
+            * step( g_day_phase, light_colour.w );
 }
 
 vec3 scene_calculate_packed_light_patch( uint packed_index, 
@@ -138,20 +128,17 @@ vec3 scene_calculate_packed_light_patch( uint packed_index,
 
    vec3 l = vec3(0.0);
 
-   if( light_count >= 1u )
-   {
+   if( light_count >= 1u ){
       int index_0 = int( ((packed_index >>  2u) & 0x3ffu) * 3u );
       int index_1 = int( ((packed_index >> 12u) & 0x3ffu) * 3u );
       int index_2 = int( ((packed_index >> 22u) & 0x3ffu) * 3u );
 
       l += scene_calculate_light( index_0, halfview, co, normal );
 
-      if( light_count >= 2u )
-      {
+      if( light_count >= 2u ){
          l += scene_calculate_light( index_1, halfview, co, normal );
 
-         if( light_count >= 3u )
-         {
+         if( light_count >= 3u ){
             l += scene_calculate_light( index_2, halfview, co, normal );
          }
       }
@@ -171,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 );