chaos pt 1
[carveJwlIkooP6JGAAIwe30JlM.git] / shaders / common_world.glsl
index cb68f35a4cf7f2ebac919722825990b4d8a3eca4..b734743bc697d8daf4e3860c9e84bc75c0f3c40b 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;
 }
@@ -170,8 +166,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 );