Alpha-blend borders with backgrounds in quad SDF

Co-Authored-By: Max Brunsfeld <max@zed.dev>
This commit is contained in:
Antonio Scandurra 2022-01-26 19:16:26 +01:00
parent 02baaa3529
commit 51c34ebcc2
3 changed files with 12 additions and 6 deletions

View file

@ -66,13 +66,19 @@ float4 quad_sdf(QuadFragmentInput input) {
border_width = vertical_border;
}
float4 color = input.background_color * float4(1., 1., 1., saturate(0.5 - distance));
if (border_width != 0.) {
float4 color;
if (border_width == 0.) {
color = input.background_color;
} else {
float inset_distance = distance + border_width;
color = mix(input.border_color, color, saturate(0.5 - inset_distance));
float4 border_color = float4(
mix(input.background_color.rgb, input.border_color.rgb, input.border_color.a),
saturate(input.background_color.a + input.border_color.a)
);
color = mix(border_color, input.background_color, saturate(0.5 - inset_distance));
}
return color;
return color * float4(1., 1., 1., saturate(0.5 - distance));
}
vertex QuadFragmentInput quad_vertex(

View file

@ -7,7 +7,7 @@ extends = "_base"
[border]
0 = "#000000B2"
1 = "#FFFFFF16"
1 = "#FFFFFF4A"
[text]
0 = { extends = "$text.base", color = "#ffffff" }

View file

@ -7,7 +7,7 @@ extends = "_base"
[border]
0 = "#1B222B"
1 = "#FFFFFF16"
1 = "#FFFFFF4A"
[text]
0 = { extends = "$text.base", color = "#FFFFFF" }