graphics changes
[carveJwlIkooP6JGAAIwe30JlM.git] / shaders / scene_water.fs
index 98875d06dab54885ca44b3e293b0d5947a976529..d4bee82d8eb609a3354a72ff1748d217a1aae889 100644 (file)
@@ -17,7 +17,7 @@ uniform vec3 uOceanColour;
 #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);
 
@@ -30,11 +30,15 @@ vec4 water_surf( vec3 halfview, vec3 vnorm, float depthvalue,
    // Depth 
    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()
@@ -55,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 );
 
@@ -70,8 +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.rgb = scene_compute_lighting( oColour.rgb, aNorm.xyz, aWorldCo );
+
+   oColour = vsurface;
 }