DonkeyKong64 grind crash
[carveJwlIkooP6JGAAIwe30JlM.git] / shaders / blitblur.fs
1 out vec4 FragColor;
2 uniform sampler2D uTexMain;
3 uniform sampler2D uTexMotion;
4 uniform float uBlurStrength;
5 uniform vec2 uOverrideDir;
6 uniform float uTime;
7 uniform float uGlitchStrength;
8 uniform vec2 uClampUv;
9
10 in vec2 aUv;
11
12 vec2 rand_hash22( vec2 p ){
13 vec3 p3 = fract(vec3(p.xyx) * 213.8976123);
14 p3 += dot(p3, p3.yzx+19.19);
15 return fract(vec2((p3.x + p3.y)*p3.z, (p3.x+p3.z)*p3.y));
16 }
17
18 const int NOISE_LOOP = 3;
19 vec3 digital_noise( uvec3 iuv ){
20 iuv *=uvec3(8,2524,7552);
21 for( int i=0; i<NOISE_LOOP; i++ )
22 iuv += (iuv.yzx<<2) ^ (iuv.yxz)+iuv.z;
23 return vec3(iuv)*(1.0/float(0xffffffffU));
24 }
25
26 void main(){
27 vec2 vuv = aUv;
28
29 //if( uGlitchStrength > 0.0 ){
30 // uvec3 p = uvec3( gl_FragCoord.xy, uint(uTime*30.0) );
31 // vec2 g = digital_noise(p).xy;
32 // vuv = aUv + g.xy*uGlitchStrength - uGlitchStrength*0.5;
33 //}
34
35 vec2 vrand = rand_hash22( vuv ) * 2.0 - vec2(1.0);
36 vec2 vrand1 = rand_hash22( vrand ) * 2.0 - vec2(1.0);
37
38 vec2 vdir = texture( uTexMotion, vuv ).xy * uBlurStrength + uOverrideDir;
39
40 vec4 vcolour0 = texture( uTexMain, min(vuv + vdir*vrand.x,uClampUv) );
41 vec4 vcolour1 = texture( uTexMain, min(vuv + vdir*vrand.y,uClampUv) );
42 vec4 vcolour2 = texture( uTexMain, min(vuv + vdir*vrand1.x,uClampUv) );
43 vec4 vcolour3 = texture( uTexMain, min(vuv + vdir*vrand1.y,uClampUv) );
44
45 FragColor = ( vcolour0 + vcolour1 + vcolour2 + vcolour3 ) * 0.25;
46 }