water fog material prop; ragdoll float only on drowned
[carveJwlIkooP6JGAAIwe30JlM.git] / shaders / common_world.glsl
index 8926c21586c40d6cdd59d867a291d9f174dbd5ca..0bc4e7b6bbcceb2471c9c31523dcd8b8d1d4a035 100644 (file)
@@ -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 )
 {
@@ -119,7 +107,7 @@ 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) );
@@ -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 );