DonkeyKong64 grind crash
[carveJwlIkooP6JGAAIwe30JlM.git] / shaders / blit.h
1 #ifndef SHADER_blit_H
2 #define SHADER_blit_H
3 static void shader_blit_link(void);
4 static void shader_blit_register(void);
5 static struct vg_shader _shader_blit = {
6 .name = "blit",
7 .link = shader_blit_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/blit.fs",
26 .static_src =
27 "out vec4 FragColor;\n"
28 "uniform sampler2D uTexMain;\n"
29 "\n"
30 "in vec2 aUv;\n"
31 "\n"
32 "float kPi = 3.14159265358979;\n"
33 "\n"
34 "vec2 fisheye_distort(vec2 xy)\n"
35 "{\n"
36 " float aperture = 1350.0;\n"
37 " float apertureHalf = 0.5 * aperture * (kPi / 180.0);\n"
38 " float maxFactor = sin(apertureHalf);\n"
39 "\n"
40 " vec2 uv;\n"
41 " float d = length(xy);\n"
42 " if(d < (2.0-maxFactor))\n"
43 " {\n"
44 " d = length(xy * maxFactor);\n"
45 " float z = sqrt(1.0 - d * d);\n"
46 " float r = atan(d, z) / kPi;\n"
47 " float phi = atan(xy.y, xy.x);\n"
48 "\n"
49 " uv.x = r * cos(phi) + 0.5;\n"
50 " uv.y = r * sin(phi) + 0.5;\n"
51 " }\n"
52 " else\n"
53 " {\n"
54 " uv = 0.5*xy + 0.5;\n"
55 " }\n"
56 " \n"
57 " return uv;\n"
58 "}\n"
59 "\n"
60 "\n"
61 "void main()\n"
62 "{\n"
63 " vec2 vwarp = 2.0*aUv - 1.0;\n"
64 " vwarp = fisheye_distort( vwarp );\n"
65 "\n"
66 " FragColor = texture( uTexMain, aUv );\n"
67 "}\n"
68 ""},
69 };
70
71 static GLuint _uniform_blit_uInverseRatio;
72 static GLuint _uniform_blit_uTexMain;
73 static void shader_blit_uInverseRatio(v2f v){
74 glUniform2fv(_uniform_blit_uInverseRatio,1,v);
75 }
76 static void shader_blit_uTexMain(int i){
77 glUniform1i(_uniform_blit_uTexMain,i);
78 }
79 static void shader_blit_register(void){
80 vg_shader_register( &_shader_blit );
81 }
82 static void shader_blit_use(void){ glUseProgram(_shader_blit.id); }
83 static void shader_blit_link(void){
84 _uniform_blit_uInverseRatio = glGetUniformLocation( _shader_blit.id, "uInverseRatio" );
85 _uniform_blit_uTexMain = glGetUniformLocation( _shader_blit.id, "uTexMain" );
86 }
87 #endif /* SHADER_blit_H */