-
-
Save MrEliptik/c082884d259fe7ea46ce0eb4d6678579 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
shader_type canvas_item; | |
// Based on http://www.geeks3d.com/20140213/glsl-shader-library-fish-eye-and-dome-and-barrel-distortion-post-processing-filters/2/ | |
const 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)); | |
} | |
void fragment(){ | |
vec2 xy = vec2(2, 2) * UV; | |
xy.x = xy.x-1.0; | |
xy.y = xy.y-1.0; | |
float d = length(xy); | |
if(d < 1.5){ | |
xy = distort(xy); | |
} | |
else{ | |
xy = UV; | |
} | |
COLOR = texture(SCREEN_TEXTURE, xy); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment