You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
24 lines
845 B
24 lines
845 B
// Adapted from Leafshade Interactive's outline shader |
|
// explained and shown in https://youtu.be/yh1Kdr37RmI. |
|
|
|
shader_type canvas_item; |
|
|
|
uniform vec4 line_color : source_color = vec4(1.0); |
|
uniform float line_thickness : hint_range(0.0, 10.0) = 2.0; |
|
|
|
void fragment() { |
|
vec2 size = TEXTURE_PIXEL_SIZE * line_thickness; |
|
|
|
float outline = |
|
texture(TEXTURE, UV + vec2( size.x, 0)).a + |
|
texture(TEXTURE, UV + vec2(-size.x, 0)).a + |
|
texture(TEXTURE, UV + vec2(0, size.y)).a + |
|
texture(TEXTURE, UV + vec2(0, -size.y)).a + |
|
texture(TEXTURE, UV + vec2( size.x, size.y)).a + |
|
texture(TEXTURE, UV + vec2(-size.x, size.y)).a + |
|
texture(TEXTURE, UV + vec2(-size.x, -size.y)).a + |
|
texture(TEXTURE, UV + vec2( size.x, -size.y)).a; |
|
|
|
float alpha = min(outline, 1.0) - texture(TEXTURE, UV).a; |
|
COLOR = vec4(line_color.rgb, line_color.a * alpha); |
|
}
|
|
|