X-Git-Url: https://harrygodden.com/git/?a=blobdiff_plain;f=shaders%2Fwater.fs;h=077a8e68848e0916fa31ca7a8dcb26dba2dfcba6;hb=dfee9022b3513fddec36f7ea70867ee5961a44da;hp=da92d134e8e3bda2c3098b32a88bf3c154190f6e;hpb=afa80c76d03f5e983092e9d7be33a9102a7ab25e;p=carveJwlIkooP6JGAAIwe30JlM.git diff --git a/shaders/water.fs b/shaders/water.fs index da92d13..077a8e6 100644 --- a/shaders/water.fs +++ b/shaders/water.fs @@ -3,32 +3,57 @@ out vec4 FragColor; uniform sampler2D uTexMain; uniform sampler2D uTexDudv; uniform sampler2D uTexDepth; +uniform sampler2D uTexBack; + uniform vec2 uInvRes; uniform float uTime; +uniform vec3 uCamera; +uniform float uSurfaceY; + in vec4 aUv; in vec3 aCo; +in float aDepth; void main() { + // Reflected and warped texture vec2 ssuv = gl_FragCoord.xy*uInvRes; - vec4 dudva = texture( uTexDudv, aUv.xy + vec2(uTime*0.04f,uTime*0.03f) ); - vec4 dudvb = texture( uTexDudv, aUv.xy - vec2(uTime*0.1,uTime*0.054) ); - vec2 distortamt = (dudva.rg-0.5) * (dudvb.ba-0.5) * 2.0; + 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; - float opacity = smoothstep( 0.0, 0.1, depthvalue ); - vec3 colour_shore = vec3( 0.96, 0.98, 0.9 ); - vec3 colour_ocean = vec3( 0.61, 0.84, 0.9 ); - vec3 surface_tint = mix( colour_shore, colour_ocean, depthvalue ); + 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; + + // 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); - vec3 comp_surf = mix(pow(surface_tint,vec3(6.0))*0.6,reflected.rgb, 0.7); + // Lighting + vec3 surfnorm = vec3(distortamt.x,1.0,distortamt.y); - float band = fract( aCo.z*0.1+uTime*0.1-depthvalue*10.0 ); - band = step( band + dudvb.g*0.8, 0.5 ) * max((1.0-depthvalue*4.0),0.0); + vec3 halfview = -normalize( aCo-uCamera ); + float ffresnel = pow(1.0-dot( surfnorm, halfview ),5.0); - FragColor = vec4(comp_surf + band*0.2,opacity+band*0.2); + 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); + + // 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 ); }