+#include "water_ref.glsl"
+
out vec4 FragColor;
uniform sampler2D uTexMain;
void main()
{
- // Reflected and warped texture
+ // Create texture coords
vec2 ssuv = gl_FragCoord.xy*uInvRes;
-
- vec4 dudva = texture( uTexDudv, aUv.xy - vec2(uTime*0.004f,uTime*0.003f) );
- vec4 dudvb = texture( uTexDudv, aUv.xy*0.7 - vec2(uTime*0.01,uTime*0.0054) );
- vec2 distortamt = (dudva.rg-0.5) * (dudvb.ba-0.5) * 0.6;
-
- vec4 reflected = texture( uTexMain, ssuv+distortamt );
// Surface colour composite
float depthvalue = texture( uTexDepth, aUv.zw ).r;
- vec3 colour_shore = vec3( 0.21, 0.6, 0.8 );
- vec3 colour_ocean = vec3( 0.01, 0.1, 0.2 );
- vec3 surface_tint = mix(colour_shore, colour_ocean, pow(depthvalue,1.8))*1.5;
+ vec4 dudva = texture(uTexDudv, aUv.xy + vec2(uTime*0.008,uTime*0.006))-0.5;
+ vec4 dudvb = texture(uTexDudv, aUv.xy*7.0-vec2(uTime*0.003,uTime*0.03))-0.5;
+
+ vec3 surfnorm = dudva.rgb + dudvb.rgb;
+ surfnorm = normalize(vec3(0.0,1.0,0.0) + dudva.xyz*0.4 + dudvb.xyz*0.1);
// Foam
- float fband = fract( aCo.z*0.1+uTime*0.1-depthvalue*10.0 );
- fband = step( fband+dudvb.g*0.8, 0.5 ) * max((1.0-depthvalue*4.0),0.0);
+ float fband = fract( aCo.z*0.02+uTime*0.1+depthvalue*10.0 );
+ fband = step( fband+dudva.a*0.8, 0.3 ) * max((1.0-depthvalue*4.0),0.0);
// Lighting
- vec3 surfnorm = vec3(distortamt.x,1.0,distortamt.y);
-
vec3 halfview = -normalize( aCo-uCamera );
- float ffresnel = pow(1.0-dot( surfnorm, halfview ),5.0);
- vec3 lightdir = vec3(0.95,0.0,-0.3);
- vec3 specdir = reflect( -lightdir, surfnorm );
- float spec = pow(max(dot(halfview,specdir),0.0),20.0)*0.3;
-
- // Depth
- vec4 backsample = texture( uTexBack, ssuv+distortamt*0.1 );
- float depthblend = pow(backsample.a,0.8);
+ // Sample textures
+ vec4 above = texture( uTexMain, ssuv+ surfnorm.xz*0.2 );
+ vec4 beneath = texture( uTexBack, ssuv );
+
+ // Fog
+ //vec4 horizon = vec4( 0.5, 0.6, 0.9, 1.0 );
+ vec4 horizon = vec4( 0.7,0.8,0.88, 1.0 );
+ float fdist = pow(length( aCo.xz-uCamera.xz ) * 0.00047, 2.6);
// Composite
- vec3 vsurface = mix(surface_tint*backsample.rgb, reflected.rgb, ffresnel );
- vsurface += spec;
-
- FragColor = mix( vec4(vsurface,depthblend), vec4(1.0,1.0,1.0,0.8), fband );
+ vec4 vsurface = water_surf( halfview, surfnorm, depthvalue, beneath, above );
+ vsurface.a -= fdist;
+ FragColor = mix( vsurface, vec4(1.0,1.0,1.0,0.5), fband );
}