add outline shader

This commit is contained in:
yuki 2025-11-24 17:36:02 -03:00
parent 73c65415f1
commit fd43faf658
2 changed files with 32 additions and 0 deletions

31
shaders/outline.gdshader Normal file
View file

@ -0,0 +1,31 @@
shader_type canvas_item;
uniform vec4 clr : source_color = vec4(0.0, 0.0, 0.0, 1.0);
uniform int type : hint_range(0, 2) = 2;
uniform float thickness = 1.0;
const vec2[8] DIRECTIONS = {
vec2(1.0, 0.0),
vec2(0.0, 1.0),
vec2(-1.0, 0.0),
vec2(0.0, -1.0),
vec2(1.0, 1.0),
vec2(-1.0, 1.0),
vec2(-1.0, -1.0),
vec2(1.0, -1.0)
};
float gtz(float input) { return max(0, sign(input)); }
// returns 1 if input > 0, else 0
float check(sampler2D tex, vec2 from, vec2 size) {
float result = 0.0;
for (int i = 0; i < 4 * type; i++) {
result += texture(tex, from + DIRECTIONS[i] * size * thickness).a;
}
return gtz(result);
}
void fragment() {
COLOR = mix( COLOR, clr, check(TEXTURE, UV, TEXTURE_PIXEL_SIZE) * (1.0 - gtz(COLOR.a)) );
}

View file

@ -0,0 +1 @@
uid://tydujgmoudjd