-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpixel_outline_shader
More file actions
31 lines (25 loc) · 981 Bytes
/
pixel_outline_shader
File metadata and controls
31 lines (25 loc) · 981 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
shader_type canvas_item;
uniform bool has_outline = true;
uniform vec4 outline_color:source_color;
uniform float outline_size = 1;
varying vec4 modulate;
void vertex() {
modulate = COLOR;
}
void fragment() {
vec4 base_color = COLOR;
if (has_outline) {
float size_x = 1.0/float(textureSize(TEXTURE, 0).x);
float size_y = 1.0/float(textureSize(TEXTURE, 0).y);
vec4 sprite_color = texture(TEXTURE, UV);
float alpha = -4.0 * sprite_color.a;
alpha += textureLod(TEXTURE, UV + vec2(size_x * outline_size, 0), 0).a;
alpha += textureLod(TEXTURE, UV + vec2(-size_x * outline_size, 0), 0).a;
alpha += textureLod(TEXTURE, UV + vec2(0, -size_y * outline_size), 0).a;
alpha += textureLod(TEXTURE, UV + vec2(0, size_y * outline_size), 0).a;
sprite_color = mix(sprite_color, outline_color, clamp(alpha, 0.0, 1.0));
sprite_color = vec4(sprite_color.rgb, clamp(abs(alpha) + sprite_color.a, 0.0, 1.0));
base_color = sprite_color;
}
COLOR = base_color * modulate;
}