fix da bugs
[carveJwlIkooP6JGAAIwe30JlM.git] / shaders / scene_water_fast.fs
diff --git a/shaders/scene_water_fast.fs b/shaders/scene_water_fast.fs
new file mode 100644 (file)
index 0000000..81a4b02
--- /dev/null
@@ -0,0 +1,63 @@
+uniform sampler2D uTexDudv;
+
+uniform float uTime;
+uniform vec3 uCamera;
+uniform float uSurfaceY;
+uniform vec3 uBoard0;
+uniform vec3 uBoard1;
+
+uniform vec3 uShoreColour;
+uniform vec3 uOceanColour;
+
+in vec2 aUv;
+in vec4 aNorm;
+in vec3 aCo;
+in vec3 aWorldCo;
+flat in ivec4 aLights;
+
+#include "common_scene.glsl"
+#include "motion_vectors_fs.glsl"
+
+vec4 water_surf( vec3 halfview, vec3 vnorm, float depthvalue )
+{
+   vec3 surface_tint = mix(uShoreColour, uOceanColour, depthvalue);
+
+   float ffresnel = pow(1.0-dot( vnorm, halfview ),5.0);
+
+   vec3 lightdir = vec3(0.95,0.0,-0.3);
+   vec3 specdir = reflect( -lightdir, vnorm );
+   float spec = pow(max(dot(halfview,specdir),0.0),20.0)*0.3;
+   
+   return vec4( surface_tint + spec, max(min(depthvalue*4.0, 1.0),0.0) );
+}
+
+void main()
+{
+   compute_motion_vectors();
+
+   // Surface colour composite
+   float depthvalue = clamp( -world_depth_sample( aCo )*(1.0/25.0), 0.0, 1.0 );
+
+   vec2 world_coord = aCo.xz * 0.008;
+   vec4 time_offsets = vec4( uTime ) * vec4( 0.008, 0.006, 0.003, 0.03 );
+   vec4 dudva = texture( uTexDudv, world_coord + time_offsets.xy )-0.5;
+   vec4 dudvb = texture( uTexDudv, world_coord *7.0 - time_offsets.zw )-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.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 halfview = -normalize( aCo-uCamera );
+
+   // Fog
+   float fdist = pow(length( aCo.xz-uCamera.xz ) * 0.00047, 2.6);
+
+   // Composite
+   vec4 vsurface = water_surf( halfview, surfnorm, depthvalue );
+   vsurface.a -= fdist;
+   oColour = mix( vsurface, vec4(1.0,1.0,1.0,0.5), fband );
+}