df shadows
[carveJwlIkooP6JGAAIwe30JlM.git] / shaders / vblend.fs
index 690f5c7b4a956825eefec2100350fd1327cdbf2e..b2e9928777566ecb335d0b419c93c44257abcb76 100644 (file)
@@ -1,38 +1,26 @@
-out vec4 FragColor;
-
 uniform sampler2D uTexGarbage;
 uniform sampler2D uTexGradients;
-uniform sampler2D uTexDepth;
-uniform vec4 uDepthBounds;
 uniform vec3 uCamera;
-uniform vec4 uPlane;
+uniform vec3 uBoard0;
+uniform vec3 uBoard1;
 
 in vec4 aColour;
 in vec2 aUv;
 in vec3 aNorm;
 in vec3 aCo;
+in vec3 aWorldCo;
 
-float water_depth( vec3 pos, vec3 dir, vec4 plane )
-{
-   float d = dot( plane.xyz, dir );
-   float t = dot((plane.xyz*plane.w - pos),plane.xyz) / d;
-   return t*0.04;
-}
+#include "common_world.glsl"
+#include "motion_vectors_fs.glsl"
 
-float sample_height( vec3 pos )
+void main()
 {
-   vec2 depth_coords = (pos.xz-uDepthBounds.xy)*uDepthBounds.zw;
-   return texture( uTexDepth, depth_coords ).r;
-}
+   compute_motion_vectors();
 
-float create_shadowing( vec3 vdir )
-{
-   return clamp( sample_height( aCo+vdir ) - (aCo.y+vdir.y), 0.1, 0.2 )-0.1;
-}
+   vec3 vfrag = vec3(0.5,0.5,0.5);
 
-void main()
-{
-   vec4 wgarbage = texture( uTexGarbage, aCo.xz * 0.160 );
+   // ws modulation
+   vec4 wgarbage = vec4(0.5,0.5,0.5,1.0);//texture( uTexGarbage, aCo.xz * 0.160 );
    
    // Creating normal patches
    vec3 modnorm = (wgarbage.rgb-0.4) * 1.4;
@@ -49,32 +37,23 @@ void main()
    float fblendclip = step(0.380,aColour.r + (rgarbage.r-0.5)*-1.740)*0.320;
    vec2 uvgradients = aUv + vec2( fblendclip, 0.0 );
 
-   vec3 diffuse = texture( uTexGradients, uvgradients ).rgb;
-   diffuse -= rgarbage.a*0.04;
+   vfrag = texture( uTexGradients, uvgradients ).rgb;
+   vfrag -= rgarbage.a*0.04;
+
+   if( g_light_preview == 1 )
+   {
+      vfrag = vec3(0.5);
+   }
 
    // Lighting
-   vec3 lightdir = normalize(vec3(0.5,0.5,-0.1));
-   vec3 shadow = vec3(0.27,0.25,0.34);
-   float light1 = dot( lightdir, aNorm )*0.5+0.5;
-   diffuse = diffuse * (light1*vec3(1.0,0.96,0.9)*1.2 + shadow*(1.0-light1));
-   
-   // Specular lighting
-   vec3 halfview = normalize( uCamera - aCo );
-   vec3 specdir = reflect( -lightdir, qnorm );
-   float spec = pow(max(dot(halfview,specdir),0.0),10.0) * 0.3*rgarbage.r;
-   //diffuse += spec * vec3(1.0,0.8,0.8);
+   vec3 halfview = uCamera - aWorldCo;
+   float fdist = length( halfview );
+   halfview /= fdist;
 
-   float faccum = 0.0;
-   vec3 offs = vec3(rgarbage.x, 0.0, rgarbage.z)*4.0;
-   faccum += create_shadowing( vec3( 0.0, 0.5, 0.0 )*0.6);
-   faccum += create_shadowing( vec3( 2.0, 0.3, 0.0 )*0.6);
-   faccum += create_shadowing( vec3( 3.0, 1.0, 0.0 )*0.6);
-   faccum += create_shadowing( vec3( 5.0, 1.0, 0.0 )*0.6);
-   faccum += create_shadowing( vec3( 0.0, 0.5, 0.0 )*0.6*1.5+offs);
-   faccum += create_shadowing( vec3( 2.0, 0.3, 0.0 )*0.6*1.5);
-   faccum += create_shadowing( vec3( 3.0, 1.0, 0.0 )*0.6*1.5-offs);
-   faccum += create_shadowing( vec3( 5.0, 1.0, 0.0 )*0.6*1.5);
-   diffuse = mix( diffuse, vec3(0.15,0.1,0.2), min(faccum*1.0,1.0));
+   vfrag = do_light_diffuse( vfrag, qnorm );
+   vfrag = do_light_spec( vfrag, qnorm, halfview, 0.1 );
+   vfrag = do_light_shadowing( vfrag );
+   vfrag = apply_fog( vfrag, fdist );
 
-   FragColor = vec4(diffuse, water_depth(aCo,halfview,uPlane));
+   oColour = vec4(vfrag, 1.0 );
 }