-out vec4 FragColor;
-
uniform sampler2D uTexGarbage;
uniform sampler2D uTexGradients;
-uniform sampler2D uTexDepth;
-uniform vec4 uDepthBounds;
uniform vec3 uCamera;
-uniform vec4 uPlane;
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;
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 );
}