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