From 8da4fcb6167ced2aaa89cb92c4420d3be7eb0591 Mon Sep 17 00:00:00 2001 From: floppyhammer Date: Thu, 16 May 2024 02:50:30 +0800 Subject: [PATCH] Fix UI border artifacts caused by incorrect blending (#12725) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes https://github.com/bevyengine/bevy/issues/12702. Co-authored-by: François Mockers --- crates/bevy_ui/src/render/ui.wgsl | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/crates/bevy_ui/src/render/ui.wgsl b/crates/bevy_ui/src/render/ui.wgsl index 02c81642c7..b23d89bdb6 100644 --- a/crates/bevy_ui/src/render/ui.wgsl +++ b/crates/bevy_ui/src/render/ui.wgsl @@ -159,12 +159,15 @@ fn draw(in: VertexOutput) -> vec4 { // is present, otherwise an outline about the external boundary would be drawn even without // a border. 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. let t = 1. - smoothstep(0.0, fexternal, external_distance); - return color.rgba * t; + + return vec4(color.rgb, color.a * t); } @fragment