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