Last active
August 14, 2021 09:45
-
-
Save henriquelalves/989fdd72e10c90091188 to your computer and use it in GitHub Desktop.
Godot Shader for FishEye 2D effect
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
// Based on http://www.geeks3d.com/20140213/glsl-shader-library-fish-eye-and-dome-and-barrel-distortion-post-processing-filters/2/ | |
float PI = 3.1415926535; | |
uniform float BarrelPower; | |
vec2 distort(vec2 p) { | |
if(p.x > 0.0){ | |
float angle = p.y / p.x; | |
float theta = atan(angle); | |
float radius = length(p); | |
radius = pow(radius, BarrelPower); | |
p.x = radius * cos(theta); | |
p.y = radius * sin(theta); | |
} else { | |
float angle = p.y / p.x; | |
float theta = atan(angle); | |
float radius = length(p); | |
radius = pow(radius, BarrelPower); | |
p.y = radius * sin(-theta); | |
p.x = radius * cos(theta); | |
p.x = - p.x; | |
} | |
return 0.5 * (p + vec2(1.0,1.0)); | |
} | |
vec2 xy = 2* UV; | |
xy.x = xy.x-1; | |
xy.y = xy.y-1; | |
float d = length(xy); | |
if(d < 1.5){ | |
xy = distort(xy); | |
} | |
else{ | |
xy = UV; | |
} | |
COLOR = tex(TEXTURE, xy); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment