Skip to content

Instantly share code, notes, and snippets.

@wilbefast
Created May 1, 2015 18:17
Show Gist options
  • Save wilbefast/95a7ed555ccebfa906d5 to your computer and use it in GitHub Desktop.
Save wilbefast/95a7ed555ccebfa906d5 to your computer and use it in GitHub Desktop.
Fish-eye Shader for Love 2D
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;
}
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