Created
November 29, 2019 19:20
-
-
Save jimmyjonezz/58f0a8a3254cabab5a592582b65980f4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
shader_type canvas_item; | |
uniform sampler2D palette_tex; //Palette to reference, this should be a 1-pixel tall texture containing your palette info | |
uniform vec4 outline_col : hint_color; //Outline color | |
void fragment() { | |
//Get red value and sample palette based on it | |
float pal_sample = texture(TEXTURE,UV).r; | |
vec4 col = texture(palette_tex,vec2(pal_sample,0)); | |
//Get alpha val of adjacent pixels | |
vec2 p = TEXTURE_PIXEL_SIZE; | |
float a = texture(TEXTURE,UV+vec2(p.x,0)).a; | |
a += texture(TEXTURE,UV+vec2(-p.x,0)).a; | |
a += texture(TEXTURE,UV+vec2(0,p.y)).a; | |
a += texture(TEXTURE,UV+vec2(0,-p.y)).a; | |
//Using found alpha value, determine the opacity of the outline | |
a = step(a,.5);//Clamp the a value | |
col.rgb = mix(outline_col.xyz, col.rgb, col.a); | |
col.a = step(a, col.a); | |
//Get palette color | |
COLOR = col; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment