Created
May 4, 2020 14:56
-
-
Save jimmyjonezz/d24af2b6201418d12abf829bf14b94a8 to your computer and use it in GitHub Desktop.
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
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