Advertisement
Sciman101

Godot 1-pixel outline shader

Jun 29th, 2019
800
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. shader_type canvas_item;
  2.  
  3. uniform vec4 outline_col : hint_color; //Outline color
  4.  
  5. void fragment() {
  6.     vec4 col = texture(TEXTURE,UV);
  7.    
  8.     //Get alpha val of adjacent pixels
  9.     vec2 p = TEXTURE_PIXEL_SIZE;
  10.     float a = texture(TEXTURE,UV+vec2(p.x,0)).a;
  11.     a += texture(TEXTURE,UV+vec2(-p.x,0)).a;
  12.     a += texture(TEXTURE,UV+vec2(0,p.y)).a;
  13.     a += texture(TEXTURE,UV+vec2(0,-p.y)).a;
  14.    
  15.     //Using found alpha value,
  16.     a = step(a,.5);//Clamp the a value
  17.     col.rgb = mix(outline_col.xyz, col.rgb, col.a);
  18.     col.a = step(a, col.a);
  19.    
  20.     //Get palette color
  21.     COLOR = col;
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement