Advertisement
Guest User

Untitled

a guest
Mar 26th, 2024
193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Converted from https://www.shadertoy.com/view/td2GzW
  2. shader_type canvas_item;
  3. uniform sampler2D SCREEN_TEXTURE : hint_screen_texture, filter_linear_mipmap;
  4.  
  5. // Anti fish eye (negative amount) / fish eye (positive)
  6. uniform float effect_amount : hint_range(-2.5, 2.5) = 1.0;
  7.  
  8. void fragment() {
  9.     // glsl -> godot shader
  10.     vec2 iResolution = 1.0 / SCREEN_PIXEL_SIZE;
  11.     vec4 fragCoord = FRAGCOORD;
  12.  
  13.     //normalized coords
  14.     vec2 p = fragCoord.xy / iResolution.x;
  15.  
  16.     //screen proroption
  17.     float prop = iResolution.x / iResolution.y;
  18.  
  19.     //center coords
  20.     vec2 m = vec2(0.5, 0.5 / prop);
  21.  
  22.     //vector from center to current fragment
  23.     vec2 d = p - m;
  24.  
  25.     // distance of pixel from center
  26.     float r = sqrt(dot(d, d));
  27.  
  28.     float power = effect_amount;
  29.  
  30.     //radius of 1:1 effect
  31.     float bind;
  32.    
  33.     //stick to borders
  34.     if (power > 0.0)
  35.         bind = sqrt(dot(m, m));
  36.     else {
  37.         if (prop < 1.0)
  38.             bind = m.x;
  39.         else
  40.             bind = m.y;
  41.     }
  42.  
  43.     vec2 uv;
  44.     //fisheye
  45.     if (power > 0.0)
  46.         uv = m + normalize(d) * tan(r * power) * bind / tan( bind * power);
  47.     //antifisheye
  48.     else if (power < 0.0)
  49.         uv = m + normalize(d) * atan(r * -power * 10.0) * bind / atan(-power * bind * 10.0);
  50.     //no effect for power = 1.0
  51.     else
  52.         uv = p;
  53.     uv.y *= prop;
  54.  
  55.     vec3 col = texture(SCREEN_TEXTURE, uv).rgb;
  56.    
  57.     COLOR = vec4(col, 1.0);
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement