Skip to content

Instantly share code, notes, and snippets.

@henriquelalves
Last active August 14, 2021 09:45
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save henriquelalves/989fdd72e10c90091188 to your computer and use it in GitHub Desktop.
Save henriquelalves/989fdd72e10c90091188 to your computer and use it in GitHub Desktop.
Godot Shader for FishEye 2D effect
// 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