Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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