3 static void shader_blit_link(void);
4 static void shader_blit_register(void);
5 static struct vg_shader _shader_blit
= {
7 .link
= shader_blit_link
,
10 .orig_file
= "shaders/blit.vs",
12 "layout (location=0) in vec2 a_co;\n"
15 "uniform vec2 uInverseRatio;\n"
19 " gl_Position = vec4(a_co*2.0-1.0,0.0,1.0);\n"
20 " aUv = a_co * uInverseRatio;\n"
25 .orig_file
= "shaders/blit.fs",
27 "out vec4 FragColor;\n"
28 "uniform sampler2D uTexMain;\n"
32 "float kPi = 3.14159265358979;\n"
34 "vec2 fisheye_distort(vec2 xy)\n"
36 " float aperture = 1350.0;\n"
37 " float apertureHalf = 0.5 * aperture * (kPi / 180.0);\n"
38 " float maxFactor = sin(apertureHalf);\n"
41 " float d = length(xy);\n"
42 " if(d < (2.0-maxFactor))\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"
49 " uv.x = r * cos(phi) + 0.5;\n"
50 " uv.y = r * sin(phi) + 0.5;\n"
54 " uv = 0.5*xy + 0.5;\n"
63 " vec2 vwarp = 2.0*aUv - 1.0;\n"
64 " vwarp = fisheye_distort( vwarp );\n"
66 " FragColor = texture( uTexMain, aUv );\n"
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
);
76 static void shader_blit_uTexMain(int i
){
77 glUniform1i(_uniform_blit_uTexMain
,i
);
79 static void shader_blit_register(void){
80 vg_shader_register( &_shader_blit
);
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" );
87 #endif /* SHADER_blit_H */