X-Git-Url: https://harrygodden.com/git/?a=blobdiff_plain;f=shaders%2Fblit.fs;h=634e84fa2908e992bb701d7dbb90135a66bae201;hb=be5e25dee2c54c2a22ca3bbb5bbe0eb6149343be;hp=b98d5e8832d6f124a5404209fd801296170b6b87;hpb=1f1d636056450dcd23cce55c0795ec6276272531;p=carveJwlIkooP6JGAAIwe30JlM.git diff --git a/shaders/blit.fs b/shaders/blit.fs index b98d5e8..634e84f 100644 --- a/shaders/blit.fs +++ b/shaders/blit.fs @@ -3,7 +3,39 @@ uniform sampler2D uTexMain; 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 ); }