in vec2 aUv;
+float kPi = 3.14159265358979;
+
+vec2 fisheye_distort(vec2 xy)
+{
+ float aperture = 1350.0;
+ float apertureHalf = 0.5 * aperture * (kPi / 180.0);
+ float maxFactor = sin(apertureHalf);
+
+ vec2 uv;
+ float d = length(xy);
+ if(d < (2.0-maxFactor))
+ {
+ d = length(xy * maxFactor);
+ float z = sqrt(1.0 - d * d);
+ float r = atan(d, z) / kPi;
+ float phi = atan(xy.y, xy.x);
+
+ uv.x = r * cos(phi) + 0.5;
+ uv.y = r * sin(phi) + 0.5;
+ }
+ else
+ {
+ uv = 0.5*xy + 0.5;
+ }
+
+ return uv;
+}
+
+
void main()
{
+ vec2 vwarp = 2.0*aUv - 1.0;
+ vwarp = fisheye_distort( vwarp );
+
FragColor = texture( uTexMain, aUv );
}