routes
[carveJwlIkooP6JGAAIwe30JlM.git] / shaders / route.fs
diff --git a/shaders/route.fs b/shaders/route.fs
new file mode 100644 (file)
index 0000000..dfaa7f9
--- /dev/null
@@ -0,0 +1,56 @@
+out vec4 FragColor;
+
+uniform sampler2D uTexGarbage;
+uniform sampler2D uTexGradients;
+uniform vec3 uCamera;
+uniform vec4 uColour;
+
+in vec4 aColour;
+in vec2 aUv;
+in vec3 aNorm;
+in vec3 aCo;
+in vec3 aWorldCo;
+
+#include "common_world.glsl"
+
+void main()
+{
+   vec3 vfrag = vec3(0.5,0.5,0.5);
+
+   // ws modulation
+   vec4 wgarbage = texture( uTexGarbage, aCo.xz * 0.015 );
+
+   // Creating normal patches
+   vec3 modnorm = (wgarbage.rgb-0.4) * 1.4;
+   vec3 qnorm = normalize(floor(aNorm*4.0+modnorm)*0.25) + vec3(0.001,0.0,0.0);
+
+   vec3 tangent0 = normalize(cross(qnorm,vec3(0.0,1.0,0.0)));
+   vec3 tangent1 = cross(qnorm,tangent0);
+   vec2 uvdiffuse = vec2( dot(tangent0,aCo), dot(tangent1,aCo) ) * 0.035;
+   
+   // Patch local noise
+   vec4 rgarbage = texture( uTexGarbage, uvdiffuse );
+
+   vfrag = pow(uColour.rgb,vec3(1.0/2.2));
+   vfrag -= rgarbage.a*0.1;
+
+   if( wgarbage.g < 0.3 )
+      discard;
+
+   if( g_light_preview == 1 )
+   {
+      vfrag = vec3(0.5);
+   }
+
+   // Lighting
+   vec3 halfview = uCamera - aWorldCo;
+   float fdist = length( halfview );
+   halfview /= fdist;
+
+   vfrag = do_light_diffuse( vfrag, qnorm );
+   vfrag = do_light_spec( vfrag, qnorm, halfview, 0.1 );
+   vfrag = do_light_shadowing( vfrag );
+   vfrag = apply_fog( vfrag, fdist );
+
+   FragColor = vec4(vfrag, 1.0 );
+}