cleanup+walgrid init
[carveJwlIkooP6JGAAIwe30JlM.git] / shaders / terrain.fs
index 04751e9ec45ae40c4e3f1c76573d22f5f5ba514d..fbfa276767f2f7a4f9e6de2dfe9584e27376edf9 100644 (file)
@@ -1,6 +1,38 @@
-#include "common.glsl"
+out vec4 FragColor;
+
+uniform sampler2D uTexGarbage;
+uniform sampler2D uTexGradients;
+uniform vec3 uCamera;
+
+in vec4 aColour;
+in vec2 aUv;
+in vec3 aNorm;
+in vec3 aCo;
 
 void main()
 {
+   vec4 wgarbage = texture( uTexGarbage, aCo.xz * 0.015 );
+   vec3 modnorm = (wgarbage.rgb-0.4) * 1.4;
+   vec3 qnorm = floor(aNorm*4.0+modnorm) * 0.25;
+
+   vec2 dir = normalize(qnorm.xz);
+   vec2 uvdiffuse = aCo.xz * 0.02;
+   uvdiffuse = mat2(dir.y, dir.x, -dir.x, dir.y) * uvdiffuse;
 
+   vec4 rgarbage = texture( uTexGarbage, uvdiffuse );
+   float amtgrass = step(qnorm.y,0.6);
+   vec2 uvgradients = vec2( rgarbage.a, -amtgrass*0.125 ) + aUv;
+   vec3 diffuse = texture( uTexGradients, uvgradients ).rgb;
+   
+   vec3 lightdir = vec3(0.95,0.0,-0.3);
+   vec3 shadow = pow(vec3(0.014,0.034,0.084),vec3(1.0/3.2));
+   float light1 = 1.0-(dot( lightdir, qnorm )*0.5+0.5);
+   
+   qnorm = floor(aNorm*8.0)*0.125;
+   vec3 viewdelta = normalize( uCamera - aCo );
+   vec3 specdir = reflect( -lightdir, qnorm );
+   float spec = pow(max(dot(viewdelta,specdir),0.0),10.0) * 0.2*rgarbage.r;
+   
+   diffuse = diffuse*(1.0-light1)+diffuse*shadow*light1;
+   FragColor = vec4(diffuse+spec, 1.0);
 }