routes
[carveJwlIkooP6JGAAIwe30JlM.git] / shaders / vblend.fs
1 out vec4 FragColor;
2
3 uniform sampler2D uTexGarbage;
4 uniform sampler2D uTexGradients;
5 uniform vec3 uCamera;
6
7 in vec4 aColour;
8 in vec2 aUv;
9 in vec3 aNorm;
10 in vec3 aCo;
11 in vec3 aWorldCo;
12
13 #include "common_world.glsl"
14
15 void main()
16 {
17 vec3 vfrag = vec3(0.5,0.5,0.5);
18
19 // ws modulation
20 vec4 wgarbage = vec4(0.5,0.5,0.5,1.0);//texture( uTexGarbage, aCo.xz * 0.160 );
21
22 // Creating normal patches
23 vec3 modnorm = (wgarbage.rgb-0.4) * 1.4;
24 vec3 qnorm = normalize(floor(aNorm*4.0+modnorm)*0.25) + vec3(0.001,0.0,0.0);
25
26 vec3 tangent0 = normalize(cross(qnorm,vec3(0.0,1.0,0.0)));
27 vec3 tangent1 = cross(qnorm,tangent0);
28 vec2 uvdiffuse = vec2( dot(tangent0,aCo), dot(tangent1,aCo) ) * 0.160;
29
30 // Patch local noise
31 vec4 rgarbage = texture( uTexGarbage, uvdiffuse );
32
33 // Colour blending
34 float fblendclip = step(0.380,aColour.r + (rgarbage.r-0.5)*-1.740)*0.320;
35 vec2 uvgradients = aUv + vec2( fblendclip, 0.0 );
36
37 vfrag = texture( uTexGradients, uvgradients ).rgb;
38 vfrag -= rgarbage.a*0.04;
39
40 if( g_light_preview == 1 )
41 {
42 vfrag = vec3(0.5);
43 }
44
45 // Lighting
46 vec3 halfview = uCamera - aWorldCo;
47 float fdist = length( halfview );
48 halfview /= fdist;
49
50 vfrag = do_light_diffuse( vfrag, qnorm );
51 vfrag = do_light_spec( vfrag, qnorm, halfview, 0.1 );
52 vfrag = do_light_shadowing( vfrag );
53 vfrag = apply_fog( vfrag, fdist );
54
55 FragColor = vec4(vfrag, 1.0 );
56 }