DonkeyKong64 grind crash
[carveJwlIkooP6JGAAIwe30JlM.git] / shaders / blitblur.h
1 #ifndef SHADER_blitblur_H
2 #define SHADER_blitblur_H
3 static void shader_blitblur_link(void);
4 static void shader_blitblur_register(void);
5 static struct vg_shader _shader_blitblur = {
6 .name = "blitblur",
7 .link = shader_blitblur_link,
8 .vs =
9 {
10 .orig_file = "shaders/blit.vs",
11 .static_src =
12 "layout (location=0) in vec2 a_co;\n"
13 "out vec2 aUv;\n"
14 "\n"
15 "uniform vec2 uInverseRatio;\n"
16 "\n"
17 "void main()\n"
18 "{\n"
19 " gl_Position = vec4(a_co*2.0-1.0,0.0,1.0);\n"
20 " aUv = a_co * uInverseRatio;\n"
21 "}\n"
22 ""},
23 .fs =
24 {
25 .orig_file = "shaders/blitblur.fs",
26 .static_src =
27 "out vec4 FragColor;\n"
28 "uniform sampler2D uTexMain;\n"
29 "uniform sampler2D uTexMotion;\n"
30 "uniform float uBlurStrength;\n"
31 "uniform vec2 uOverrideDir;\n"
32 "uniform float uTime;\n"
33 "uniform float uGlitchStrength;\n"
34 "uniform vec2 uClampUv;\n"
35 "\n"
36 "in vec2 aUv;\n"
37 "\n"
38 "vec2 rand_hash22( vec2 p ){\n"
39 " vec3 p3 = fract(vec3(p.xyx) * 213.8976123);\n"
40 " p3 += dot(p3, p3.yzx+19.19);\n"
41 " return fract(vec2((p3.x + p3.y)*p3.z, (p3.x+p3.z)*p3.y));\n"
42 "}\n"
43 "\n"
44 "const int NOISE_LOOP = 3;\n"
45 "vec3 digital_noise( uvec3 iuv ){\n"
46 " iuv *=uvec3(8,2524,7552);\n"
47 " for( int i=0; i<NOISE_LOOP; i++ )\n"
48 " iuv += (iuv.yzx<<2) ^ (iuv.yxz)+iuv.z;\n"
49 " return vec3(iuv)*(1.0/float(0xffffffffU));\n"
50 "}\n"
51 "\n"
52 "void main(){\n"
53 " vec2 vuv = aUv; \n"
54 "\n"
55 " //if( uGlitchStrength > 0.0 ){\n"
56 " // uvec3 p = uvec3( gl_FragCoord.xy, uint(uTime*30.0) );\n"
57 " // vec2 g = digital_noise(p).xy;\n"
58 " // vuv = aUv + g.xy*uGlitchStrength - uGlitchStrength*0.5;\n"
59 " //}\n"
60 "\n"
61 " vec2 vrand = rand_hash22( vuv ) * 2.0 - vec2(1.0);\n"
62 " vec2 vrand1 = rand_hash22( vrand ) * 2.0 - vec2(1.0);\n"
63 " \n"
64 " vec2 vdir = texture( uTexMotion, vuv ).xy * uBlurStrength + uOverrideDir;\n"
65 "\n"
66 " vec4 vcolour0 = texture( uTexMain, min(vuv + vdir*vrand.x,uClampUv) );\n"
67 " vec4 vcolour1 = texture( uTexMain, min(vuv + vdir*vrand.y,uClampUv) );\n"
68 " vec4 vcolour2 = texture( uTexMain, min(vuv + vdir*vrand1.x,uClampUv) );\n"
69 " vec4 vcolour3 = texture( uTexMain, min(vuv + vdir*vrand1.y,uClampUv) );\n"
70 "\n"
71 " FragColor = ( vcolour0 + vcolour1 + vcolour2 + vcolour3 ) * 0.25;\n"
72 "}\n"
73 ""},
74 };
75
76 static GLuint _uniform_blitblur_uInverseRatio;
77 static GLuint _uniform_blitblur_uTexMain;
78 static GLuint _uniform_blitblur_uTexMotion;
79 static GLuint _uniform_blitblur_uBlurStrength;
80 static GLuint _uniform_blitblur_uOverrideDir;
81 static GLuint _uniform_blitblur_uTime;
82 static GLuint _uniform_blitblur_uGlitchStrength;
83 static GLuint _uniform_blitblur_uClampUv;
84 static void shader_blitblur_uInverseRatio(v2f v){
85 glUniform2fv(_uniform_blitblur_uInverseRatio,1,v);
86 }
87 static void shader_blitblur_uTexMain(int i){
88 glUniform1i(_uniform_blitblur_uTexMain,i);
89 }
90 static void shader_blitblur_uTexMotion(int i){
91 glUniform1i(_uniform_blitblur_uTexMotion,i);
92 }
93 static void shader_blitblur_uBlurStrength(float f){
94 glUniform1f(_uniform_blitblur_uBlurStrength,f);
95 }
96 static void shader_blitblur_uOverrideDir(v2f v){
97 glUniform2fv(_uniform_blitblur_uOverrideDir,1,v);
98 }
99 static void shader_blitblur_uTime(float f){
100 glUniform1f(_uniform_blitblur_uTime,f);
101 }
102 static void shader_blitblur_uGlitchStrength(float f){
103 glUniform1f(_uniform_blitblur_uGlitchStrength,f);
104 }
105 static void shader_blitblur_uClampUv(v2f v){
106 glUniform2fv(_uniform_blitblur_uClampUv,1,v);
107 }
108 static void shader_blitblur_register(void){
109 vg_shader_register( &_shader_blitblur );
110 }
111 static void shader_blitblur_use(void){ glUseProgram(_shader_blitblur.id); }
112 static void shader_blitblur_link(void){
113 _uniform_blitblur_uInverseRatio = glGetUniformLocation( _shader_blitblur.id, "uInverseRatio" );
114 _uniform_blitblur_uTexMain = glGetUniformLocation( _shader_blitblur.id, "uTexMain" );
115 _uniform_blitblur_uTexMotion = glGetUniformLocation( _shader_blitblur.id, "uTexMotion" );
116 _uniform_blitblur_uBlurStrength = glGetUniformLocation( _shader_blitblur.id, "uBlurStrength" );
117 _uniform_blitblur_uOverrideDir = glGetUniformLocation( _shader_blitblur.id, "uOverrideDir" );
118 _uniform_blitblur_uTime = glGetUniformLocation( _shader_blitblur.id, "uTime" );
119 _uniform_blitblur_uGlitchStrength = glGetUniformLocation( _shader_blitblur.id, "uGlitchStrength" );
120 _uniform_blitblur_uClampUv = glGetUniformLocation( _shader_blitblur.id, "uClampUv" );
121 }
122 #endif /* SHADER_blitblur_H */