Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // A simple (screen space) fisheye shader for Godot, based on: https://gist.github.com/aggregate1166877/a889083801d67917c26c12a98e7f57a7
- // It's calibrated to convert a square screen space into a sphere
- shader_type canvas_item;
- const float crop_amount = 0.9;
- vec2 distort(vec2 p)
- {
- float d = length(p);
- float z = sqrt(1.0 + d * d * -1.0);
- float r = atan(d, z) / 3.1415926535;
- float phi = atan(p.y, p.x);
- return vec2(r*cos(phi)+.5,r*sin(phi)+.5);
- }
- void fragment()
- {
- vec2 xy = (2.0 * SCREEN_UV);
- xy.x = xy.x - 1.0;
- xy.y = xy.y - 1.0;
- vec4 tex;
- float d = length(xy);
- if (d < 1.0) {
- xy = distort(xy);
- tex = texture(SCREEN_TEXTURE, xy);
- COLOR = tex;
- COLOR.a = 0.999;
- }
- // crop.
- if (d > crop_amount) {
- COLOR = vec4(0,0,0,1);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement