Qugurun

Shader grid transparent

Sep 22nd, 2021
722
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. shader_type canvas_item;
  2. render_mode unshaded;
  3.  
  4. uniform float size = 10.0;
  5. uniform float alpha = 1.0;
  6. uniform vec4 color1 : hint_color = vec4(0.8431372549019608, 0.8431372549019608, 0.8431372549019608, 1.0);
  7. uniform vec4 color2 : hint_color = vec4(1.0);
  8. uniform vec2 offset = vec2(0.0);
  9. uniform vec2 scale = vec2(0.0);
  10. uniform vec2 rect_size = vec2(0.0);
  11. uniform bool follow_movement = false;
  12. uniform bool follow_scale = false;
  13.  
  14. void fragment() {
  15.     vec2 ref_pos = FRAGCOORD.xy;
  16.     if (follow_scale) {
  17.         if (!follow_movement)
  18.             ref_pos /= scale;
  19.         else
  20.             ref_pos = UV * rect_size;
  21.     }
  22.     else if (follow_movement)
  23.         ref_pos -= mod(offset, size * 2.0);
  24.    
  25.     vec2 pos = mod(ref_pos, size * 2.0);
  26.     bool c1 = any(lessThan(pos, vec2(size)));
  27.     bool c2 = any(greaterThanEqual(pos, vec2(size)));
  28.     float c = c1 && c2 ? 1.0: 0.0;
  29.     COLOR = mix(color1, color2, c);
  30.     COLOR.a = alpha;
  31. }
  32.  
RAW Paste Data