accommodate inspector change
[carveJwlIkooP6JGAAIwe30JlM.git] / shaders / blit.fs
1 out vec4 FragColor;
2 uniform sampler2D uTexMain;
3
4 in vec2 aUv;
5
6 float kPi = 3.14159265358979;
7
8 vec2 fisheye_distort(vec2 xy)
9 {
10 float aperture = 1350.0;
11 float apertureHalf = 0.5 * aperture * (kPi / 180.0);
12 float maxFactor = sin(apertureHalf);
13
14 vec2 uv;
15 float d = length(xy);
16 if(d < (2.0-maxFactor))
17 {
18 d = length(xy * maxFactor);
19 float z = sqrt(1.0 - d * d);
20 float r = atan(d, z) / kPi;
21 float phi = atan(xy.y, xy.x);
22
23 uv.x = r * cos(phi) + 0.5;
24 uv.y = r * sin(phi) + 0.5;
25 }
26 else
27 {
28 uv = 0.5*xy + 0.5;
29 }
30
31 return uv;
32 }
33
34
35 void main()
36 {
37 vec2 vwarp = 2.0*aUv - 1.0;
38 vwarp = fisheye_distort( vwarp );
39
40 FragColor = texture( uTexMain, aUv );
41 }