graphics changes
[carveJwlIkooP6JGAAIwe30JlM.git] / shaders / scene_water.fs
1 uniform sampler2D uTexMain;
2 uniform sampler2D uTexDudv;
3 uniform sampler2D uTexBack;
4
5 uniform vec2 uInvRes;
6 uniform float uTime;
7 uniform vec3 uCamera;
8 uniform float uSurfaceY;
9 uniform vec3 uBoard0;
10 uniform vec3 uBoard1;
11
12 uniform vec3 uShoreColour;
13 uniform vec3 uOceanColour;
14
15 #include "light_clearskies_stddef.glsl"
16 #include "common_scene.glsl"
17 #include "motion_vectors_fs.glsl"
18
19 vec4 water_surf( vec3 halfview, vec3 vnorm, float depthvalue,
20 vec4 beneath, vec4 above, vec4 dudva )
21 {
22 vec3 surface_tint = mix(uShoreColour, uOceanColour, depthvalue);
23
24 float ffresnel = pow(1.0-dot( vnorm, halfview ),5.0);
25
26 vec3 lightdir = vec3(0.95,0.0,-0.3);
27 vec3 specdir = reflect( -lightdir, vnorm );
28 float spec = pow(max(dot(halfview,specdir),0.0),20.0)*0.3;
29
30 // Depth
31 float depthblend = pow( beneath.r, 0.8 );
32
33 // Foam
34 float fband = fract( aCo.z*0.02+uTime*0.1+depthvalue*10.0 );
35 fband = step( fband+dudva.a*0.8, 0.3 ) * max((1.0-depthvalue*4.0),0.0);
36
37 vec4 surf = mix( vec4(surface_tint,depthblend),
38 vec4(1.0,1.0,1.0,0.5), fband );
39 surf.rgb = scene_compute_lighting( surf.rgb, aNorm.xyz, aWorldCo );
40 surf.rgb = mix(surf.rgb, above.rgb, ffresnel );
41 return surf;
42 }
43
44 void main()
45 {
46 compute_motion_vectors();
47
48 // Create texture coords
49 vec2 ssuv = gl_FragCoord.xy*uInvRes;
50
51 // Surface colour composite
52 float depthvalue = clamp( -world_water_depth(aCo)*(1.0/25.0), 0.0,1.0 );
53
54 vec2 world_coord = aCo.xz * 0.008;
55 vec4 time_offsets = vec4( uTime ) * vec4( 0.008, 0.006, 0.003, 0.03 );
56 vec4 dudva = texture( uTexDudv, world_coord + time_offsets.xy )-0.5;
57 vec4 dudvb = texture( uTexDudv, world_coord *7.0 - time_offsets.zw )-0.5;
58
59 vec3 surfnorm = dudva.rgb + dudvb.rgb;
60 surfnorm = normalize(vec3(0.0,1.0,0.0) + dudva.xyz*0.4 + dudvb.xyz*0.1);
61
62 // Lighting
63 vec3 halfview = -normalize( aCo-uCamera );
64
65 // Sample textures
66 vec4 above = texture( uTexMain, ssuv+ surfnorm.xz*0.2 );
67 vec4 beneath = texture( uTexBack, ssuv );
68
69 // Fog
70 float fdist = pow(length( aCo.xz-uCamera.xz ) * 0.00047, 2.6);
71
72 // Composite
73 vec4 vsurface = water_surf( halfview, surfnorm, depthvalue, beneath, above, dudva );
74 vsurface.a -= fdist;
75
76 oColour = vsurface;
77 }