Skip to content

Instantly share code, notes, and snippets.

@Razzlegames
Created February 11, 2016 05:42
Show Gist options
  • Save Razzlegames/0a126108abb7826f4421 to your computer and use it in GitHub Desktop.
Save Razzlegames/0a126108abb7826f4421 to your computer and use it in GitHub Desktop.
float PI = 3.1415926535;
uniform float aperture = 178.0;
float apertureHalf = 0.5 * aperture * (PI / 180.0);
float maxFactor = sin(apertureHalf);
vec2 uv;
vec2 xy;
xy.x = 2.0 * SCREEN_UV.x - 1.0;
xy.y = 2.0 * SCREEN_UV.y - 1.0;
float d = length(xy);
if (d < (2.0-maxFactor))
{
d = length(xy * maxFactor);
float z = sqrt(1.0 - d * d);
float r = atan2(d,z) / PI;
float phi = atan2(xy.y, xy.x);
uv.x = r * cos(phi) + 0.5;
uv.y = r * sin(phi) + 0.5;
}
else
{
uv = SCREEN_UV;
}
COLOR.rgb = texscreen(uv);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment