graphics changes
[carveJwlIkooP6JGAAIwe30JlM.git] / shaders / scene_water.fs
index 645569900d14dd1ab6fb6d016584730f196c470f..d4bee82d8eb609a3354a72ff1748d217a1aae889 100644 (file)
@@ -12,17 +12,12 @@ 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 "light_clearskies_stddef.glsl"
 #include "common_scene.glsl"
 #include "motion_vectors_fs.glsl"
 
 vec4 water_surf( vec3 halfview, vec3 vnorm, float depthvalue, 
-                 vec4 beneath, vec4 above )
+                 vec4 beneath, vec4 above, vec4 dudva )
 {
    vec3 surface_tint = mix(uShoreColour, uOceanColour, depthvalue);
 
@@ -33,13 +28,17 @@ vec4 water_surf( vec3 halfview, vec3 vnorm, float depthvalue,
    float spec = pow(max(dot(halfview,specdir),0.0),20.0)*0.3;
    
    // Depth 
-   float depthblend = pow( beneath.a,0.8 );
+   float depthblend = pow( beneath.r, 0.8 );
 
-   // Composite
-   vec3 vsurface = mix(surface_tint, above.rgb, ffresnel );
-   //vsurface += spec;
+   // 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);
 
-   return vec4( vsurface,depthblend );
+   vec4 surf = mix( vec4(surface_tint,depthblend), 
+                    vec4(1.0,1.0,1.0,0.5), fband );
+   surf.rgb = scene_compute_lighting( surf.rgb, aNorm.xyz, aWorldCo );
+   surf.rgb = mix(surf.rgb, above.rgb, ffresnel );
+   return surf;
 }
 
 void main()
@@ -50,7 +49,7 @@ void main()
    vec2 ssuv = gl_FragCoord.xy*uInvRes;
    
    // Surface colour composite
-   float depthvalue = clamp( -world_depth_sample( aCo )*(1.0/25.0), 0.0, 1.0 );
+   float depthvalue = clamp( -world_water_depth(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 );
@@ -60,10 +59,6 @@ void main()
    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 );
 
@@ -75,7 +70,8 @@ void main()
    float fdist = pow(length( aCo.xz-uCamera.xz ) * 0.00047, 2.6);
 
    // Composite
-   vec4 vsurface = water_surf( halfview, surfnorm, depthvalue, beneath, above );
+   vec4 vsurface = water_surf( halfview, surfnorm, depthvalue, beneath, above, dudva );
    vsurface.a -= fdist;
-   oColour = mix( vsurface, vec4(1.0,1.0,1.0,0.5), fband );
+
+   oColour = vsurface;
 }