SHARE
TWEET

Shader Outline

a guest Feb 17th, 2020 68 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. shader_type canvas_item;
  2. uniform float outline_width = 2.0;
  3. uniform vec4 outline_color: hint_color;
  4.  
  5. void fragment(){
  6.     vec4 col = texture(TEXTURE, UV);
  7.     vec2 ps = TEXTURE_PIXEL_SIZE * outline_width;
  8.     float a;
  9.     float maxa = col.a;
  10.     float mina = col.a;
  11.  
  12.  
  13.     for(float x = -1.0; x <= 1.0; x+=0.05) {
  14.         float y = 1.0 - (x*x);
  15.         if(vec2(x,y) == vec2(0.0)) {
  16.             continue; // ignore the center of kernel
  17.         }
  18.  
  19.         a = texture(TEXTURE, UV + vec2(x,y)*ps).a;
  20.         maxa = max(a, maxa);
  21.         mina = min(a, mina);
  22.     }
  23.  
  24.     for(float x = -1.0; x <= 1.0; x+=0.05) {
  25.         float y = -1.0 + (x*x);
  26.         if(vec2(x,y) == vec2(0.0)) {
  27.             continue; // ignore the center of kernel
  28.         }
  29.  
  30.         a = texture(TEXTURE, UV + vec2(x,y)*ps).a;
  31.         maxa = max(a, maxa);
  32.         mina = min(a, mina);
  33.     }
  34.  
  35.  
  36.     // Fill transparent pixels only, don't overlap texture
  37.     if(col.a < 0.5) {
  38.         COLOR = mix(col, outline_color, maxa-mina);
  39.     } else {
  40.         COLOR = col;
  41.     }
  42. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top