Fix UI border artifacts caused by incorrect blending (#12725)

Fixes https://github.com/bevyengine/bevy/issues/12702.

Co-authored-by: François Mockers <mockersf@gmail.com>
This commit is contained in:
floppyhammer 2024-05-16 02:50:30 +08:00 committed by GitHub
parent debcf3fb1d
commit 8da4fcb616
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -159,12 +159,15 @@ fn draw(in: VertexOutput) -> vec4<f32> {
// is present, otherwise an outline about the external boundary would be drawn even without // is present, otherwise an outline about the external boundary would be drawn even without
// a border. // a border.
let t = 1. - select(step(0.0, border_distance), smoothstep(0.0, fborder, border_distance), external_distance < internal_distance); let t = 1. - select(step(0.0, border_distance), smoothstep(0.0, fborder, border_distance), external_distance < internal_distance);
return color.rgba * t;
// Blend mode ALPHA_BLENDING is used for UI elements, so we don't premultiply alpha here.
return vec4(color.rgb, color.a * t);
} }
// The item is a rectangle, draw normally with anti-aliasing at the edges. // The item is a rectangle, draw normally with anti-aliasing at the edges.
let t = 1. - smoothstep(0.0, fexternal, external_distance); let t = 1. - smoothstep(0.0, fexternal, external_distance);
return color.rgba * t;
return vec4(color.rgb, color.a * t);
} }
@fragment @fragment