Skip to content

Instantly share code, notes, and snippets.

@jimmyjonezz
Created May 4, 2020 14:56
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 jimmyjonezz/d24af2b6201418d12abf829bf14b94a8 to your computer and use it in GitHub Desktop.
Save jimmyjonezz/d24af2b6201418d12abf829bf14b94a8 to your computer and use it in GitHub Desktop.
shader_type canvas_item;
uniform float PI = 3.1415926535;
uniform float aperture = 178.0;
void fragment(){
float apertureHalf = 0.5 * aperture * (PI / 180.0);
float maxFactor = sin(apertureHalf);
vec2 uv;
vec2 xy = 2.0 * UV.xy - vec2(1.0, 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 = SCREEN_UV.xy;
}
vec4 c = vec4(texture(SCREEN_TEXTURE, vec2(uv.x, 1.0 - uv.y)));
COLOR = c;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment