DonkeyKong64 grind crash
[carveJwlIkooP6JGAAIwe30JlM.git] / shaders / scene_route.fs
1 uniform sampler2D uTexGarbage;
2 uniform sampler2D uTexGradients;
3 uniform vec3 uCamera;
4 uniform vec4 uColour;
5
6 #include "common_scene.glsl"
7 #include "motion_vectors_fs.glsl"
8
9 float filtered_stripe( in float p, in float ddx, in float ddy )
10 {
11 float w = max(abs(ddx), abs(ddy)) + 0.02;
12 float i = (abs(fract((p-0.5*w)/2.0)-0.5)-abs(fract((p+0.5*w)/2.0)-0.5))/w;
13 return 0.5 - i;
14 }
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 = texture( uTexGarbage, aCo.xz * 0.015 );
24
25 // Creating normal patches
26 vec3 modnorm = (wgarbage.rgb-0.4) * 1.4;
27 vec3 qnorm = normalize(floor(aNorm.xyz*4.0+modnorm)*0.25);
28 qnorm += vec3(0.001,0.0,0.0);
29
30 vec3 tangent0 = normalize(cross(qnorm,vec3(0.0,1.0,0.0)));
31 vec3 tangent1 = cross(qnorm,tangent0);
32 vec2 uvdiffuse = vec2( dot(tangent0,aCo), dot(tangent1,aCo) ) * 0.035;
33
34 // Patch local noise
35 vec4 rgarbage = texture( uTexGarbage, uvdiffuse );
36
37 vfrag = pow(uColour.rgb,vec3(1.0/2.2));
38 vfrag -= rgarbage.a*0.1;
39
40 if( wgarbage.g < 0.1 )
41 discard;
42
43 float movep = (aUv.x + abs(aUv.y-0.5)*0.4 - g_realtime)*2.0;
44 float stripe = filtered_stripe( movep, dFdx(movep), dFdy(movep) );
45 vfrag *= 0.9+stripe*uColour.a;
46
47 if( g_light_preview == 1 )
48 {
49 vfrag = vec3(0.5);
50 }
51
52 // Lighting
53 oColour = vec4( scene_compute_lighting( vfrag, qnorm, aWorldCo ), 1.0 );
54 }