DonkeyKong64 grind crash
[carveJwlIkooP6JGAAIwe30JlM.git] / shaders / scene_override.fs
1 uniform sampler2D uTexGarbage;
2 uniform sampler2D uTexMain;
3 uniform vec3 uCamera;
4 uniform vec4 uPlane;
5
6 uniform vec4 uPlayerPos; /* w: distance to uSpawnPos */
7 uniform vec4 uSpawnPos; /* w: inverse distance to uPlayerPos */
8 uniform bool uAlphatest;
9
10 #include "common_scene.glsl"
11 #include "motion_vectors_fs.glsl"
12
13 vec2 smin( float a, float b, float k ){
14 float h = max( k-abs(a-b), 0.0 )/k;
15 float m = h*h*0.5;
16 float s = m*k*(1.0/2.0);
17
18 if( a < b )
19 return vec2(a-s,m);
20 else
21 return vec2(b-s,1.0-m);
22 }
23
24 void main(){
25 vec2 ssuv = gl_FragCoord.xy;
26 vec3 vDither = vec3( dot( vec2( 171.0, 231.0 ), ssuv) );
27 float dither = fract( vDither.g / 71.0 ) - 0.5;
28
29 if( (aWorldCo.y*0.1 + dither) > ((uPlayerPos.y+40.0)*0.1) )
30 discard;
31
32 compute_motion_vectors();
33
34 vec3 vfrag = vec3(0.5,0.5,0.5);
35 vec3 qnorm = aNorm.xyz;
36
37 if( uAlphatest ){
38 vec4 vSample = texture( uTexMain, aUv );
39 if( vSample.a < 0.5 )
40 discard;
41 }
42 else{
43 if( !gl_FrontFacing ){
44 qnorm *= -1.0;
45 }
46 }
47
48 vfrag = scene_compute_lighting( vfrag, qnorm, aWorldCo );
49
50 // dots
51 float d0 = distance( aWorldCo, uPlayerPos.xyz )*2.0;
52 float d1 = distance( aWorldCo, uSpawnPos.xyz );
53
54 vec2 dm = smin( d0, d1, 10.0 );
55 float dd = fract(dm.x*0.2-g_realtime*0.5) *
56 max(0.0,1.0-dm.x*0.04) *
57 max(0.0,qnorm.y);
58 vec3 emit = mix(vec3(1.0,0.0,0.0),vec3(0.0,1.0,0.0),dm.y)*dd;
59
60 // line
61 vec3 v0 = (uSpawnPos.xyz-uPlayerPos.xyz)*uSpawnPos.w;
62 float t = clamp( dot(aWorldCo-uPlayerPos.xyz,v0), 0.0, uPlayerPos.w );
63 vec3 p0 = uPlayerPos.xyz + v0*t;
64 float d3 = distance(p0,aWorldCo);
65 emit += vec3(fract(t*0.2-g_realtime+d3*0.2)*max(0.0,1.0-d3*0.2));
66
67 oColour = vec4( vfrag+emit, 1.0 );
68 }