outline.gdshader 716 B

123456789101112131415161718192021222324252627282930
  1. shader_type canvas_item;
  2. uniform float outline_width = 2.0;
  3. uniform vec4 outline_color : source_color;
  4. void fragment() {
  5. vec4 col = texture(TEXTURE, UV);
  6. vec2 ps = TEXTURE_PIXEL_SIZE;
  7. float a;
  8. float maxa = col.a;
  9. float mina = col.a;
  10. a = texture(TEXTURE, UV + vec2(0.0, -outline_width) * ps).a;
  11. maxa = max(a, maxa);
  12. mina = min(a, mina);
  13. a = texture(TEXTURE, UV + vec2(0.0, outline_width) * ps).a;
  14. maxa = max(a, maxa);
  15. mina = min(a, mina);
  16. a = texture(TEXTURE, UV + vec2(-outline_width, 0.0) * ps).a;
  17. maxa = max(a, maxa);
  18. mina = min(a, mina);
  19. a = texture(TEXTURE, UV + vec2(outline_width, 0.0) * ps).a;
  20. maxa = max(a, maxa);
  21. mina = min(a, mina);
  22. COLOR = mix(col, outline_color, maxa - mina);
  23. }