Created
May 1, 2015 18:17
-
-
Save wilbefast/95a7ed555ccebfa906d5 to your computer and use it in GitHub Desktop.
Fish-eye Shader for Love 2D
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
const float PI = 3.1415926535; | |
vec4 effect( vec4 color, Image texture, vec2 texture_coords, vec2 screen_coords) | |
{ | |
float aperture = 178.0; | |
float apertureHalf = 0.5 * aperture * (PI / 180.0); | |
float maxFactor = sin(apertureHalf); | |
vec2 uv; | |
vec2 xy = 2.0 * texture_coords.xy - 1.0; | |
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) / PI; | |
float phi = atan(xy.y, xy.x); | |
uv.x = r * cos(phi) + 0.5; | |
uv.y = r * sin(phi) + 0.5; | |
} | |
else | |
{ | |
uv = texture_coords.xy; | |
} | |
vec4 c = texture2D(texture, uv); | |
return c; | |
} |
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
vec4 position( mat4 transform_projection, vec4 vertex_position ) | |
{ | |
return transform_projection * vertex_position; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Based on http://www.geeks3d.com/20140213/glsl-shader-library-fish-eye-and-dome-and-barrel-distortion-post-processing-filters/