Created
March 3, 2016 20:55
-
-
Save jrsa/faca93d67a3b61804303 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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