3 uniform sampler2D uTexGarbage;
4 uniform sampler2D uTexGradients;
13 float water_depth( vec3 pos, vec3 dir, vec4 plane )
15 float d = dot( plane.xyz, dir );
16 float t = dot((plane.xyz*plane.w - pos),plane.xyz) / d;
22 vec4 wgarbage = texture( uTexGarbage, aCo.xz * 0.015 );
24 // Creating normal patches
25 vec3 modnorm = (wgarbage.rgb-0.4) * 1.4;
26 vec3 qnorm = normalize(floor(aNorm*4.0+modnorm) * 0.25);
27 vec2 dir = normalize(qnorm.xz);
28 vec2 uvdiffuse = aCo.xz * 0.02;
29 uvdiffuse = mat2(dir.y, dir.x, -dir.x, dir.y) * uvdiffuse;
32 vec4 rgarbage = texture( uTexGarbage, uvdiffuse );
35 float amtgrass = step(qnorm.y,0.6);
36 float amtsand = min(max((aCo.y - 10.0) * -0.08,0.0)*qnorm.y,1.0);
37 vec2 uvgradients = vec2( rgarbage.a, -amtgrass*0.125 ) + aUv;
38 vec3 diffuse = texture( uTexGradients, uvgradients ).rgb;
39 diffuse = mix( diffuse, vec3(1.0,0.9,0.7), amtsand );
42 vec3 lightdir = vec3(0.95,0.0,-0.3);
43 vec3 shadow = pow(vec3(0.014,0.034,0.084),vec3(1.0/3.2));
44 float light1 = dot( lightdir, mix(qnorm,aNorm,amtsand) )*0.5+0.5;
45 diffuse = diffuse * (light1*vec3(1.0,0.96,0.9)*1.2 + shadow*(1.0-light1));
48 vec3 halfview = normalize( uCamera - aCo );
49 vec3 specdir = reflect( -lightdir, qnorm );
50 float spec = pow(max(dot(halfview,specdir),0.0),10.0) * 0.2*rgarbage.r;
51 diffuse += spec * vec3(1.0,0.8,0.8);
53 FragColor = vec4(diffuse, water_depth(aCo,halfview,uPlane));