Skip to content

Instantly share code, notes, and snippets.

@jrsa
Created March 3, 2016 20:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jrsa/faca93d67a3b61804303 to your computer and use it in GitHub Desktop.
Save jrsa/faca93d67a3b61804303 to your computer and use it in GitHub Desktop.
kernel vec4 fisheye(sampler img, float signcurvature, float lensradius)
{
// no constants/defines?
float EPSILON = 0.000011;
float otherConst = 1.4427;
float curvature = abs(signcurvature);
float extent = lensradius;
float optics = extent / log2(curvature * extent + 1.0) / otherConst;
vec2 normalizeTD = samplerCoord( img ) / samplerSize( img );
vec2 PP = normalizeTD - vec2(0.5,0.5);
float P0 = PP[0];
float P1 = PP[1];
float radius = sqrt(P0 * P0 + P1 * P1);
float cosangle = P0 / radius;
float sinangle = P1 / radius;
float rad1, rad2, newradius;
rad1 = (exp2((radius / optics) * otherConst) - 1.0) / curvature;
rad2 = optics * log2(1.0 + curvature * radius) / otherConst;
newradius = signcurvature > 0.0 ? rad1 : rad2;
vec2 FE = vec2(newradius * cosangle + 0.5,newradius * sinangle + 0.5);
FE = radius <= extent ? FE : normalizeTD;
FE = curvature < EPSILON ? normalizeTD : FE;
vec2 xformedCoord = FE * samplerSize( img );
return sample(img, xformedCoord);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment