View shader on Shadertoy - Published on 2019-10-22
The inverse of a Barrel Distortion.
I couldn't find this function online, so I derived it myself. A surprisingly complex formula ;-).
uv -= .5;
float b = distortion;
float l = length(uv);
float x0 = pow(9.*b*b*l + sqrt(3.) * sqrt(27.*b*b*b*b*l*l + 4.*b*b*b), 1./3.);
float x = x0 / (pow(2., 1./3.) * pow(3., 2./3.) * b) - pow(2./3., 1./3.) / x0;
return uv * (x / l) + .5;
Source: Image.glsl
- iChannel0: texture (mipmap, repeat, vflipped)
- Inverse Barrel Distortion on Shadertoy
- An overview of all my shaders
- My public profile on Shadertoy