From 2f6d8663d0fc45644758f71d74110e599b0cd5a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Mockers?= Date: Thu, 21 Mar 2024 20:17:13 +0100 Subject: [PATCH] rounded border: remove dead code in shader (#12602) # Objective - #12500 added dead code to the ui shader ## Solution - Remove it --- crates/bevy_ui/src/render/ui.wgsl | 141 ------------------------------ 1 file changed, 141 deletions(-) diff --git a/crates/bevy_ui/src/render/ui.wgsl b/crates/bevy_ui/src/render/ui.wgsl index bb312713c5c03..245f75eda6340 100644 --- a/crates/bevy_ui/src/render/ui.wgsl +++ b/crates/bevy_ui/src/render/ui.wgsl @@ -62,10 +62,6 @@ fn vertex( @group(1) @binding(0) var sprite_texture: texture_2d; @group(1) @binding(1) var sprite_sampler: sampler; -fn sigmoid(t: f32) -> f32 { - return 1.0 / (1.0 + exp(-t)); -} - // The returned value is the shortest distance from the given point to the boundary of the rounded // box. // @@ -124,143 +120,6 @@ fn sd_inset_rounded_box(point: vec2, size: vec2, radius: vec4, in return sd_rounded_box(inner_point, inner_size, r); } -#ifdef CLAMP_INNER_CURVES -fn sd_inset_rounded_box(point: vec2, size: vec2, radius: vec4, inset: vec4) -> f32 { - let inner_size = size - inset.xy - inset.zw; - let inner_center = inset.xy + 0.5 * inner_size - 0.5 * size; - let inner_point = point - inner_center; - - var r = radius; - - if 0. < min(inset.x, inset.y) || inset.x + inset.y <= 0. { - // Top left corner. - r.x = r.x - max(inset.x, inset.y); - } else { - r.x = 0.; - } - - if 0. < min(inset.z, inset.y) || inset.z + inset.y <= 0. { - // Top right corner. - r.y = r.y - max(inset.z, inset.y); - } else { - r.y = 0.; - } - - if 0. < min(inset.z, inset.w) || inset.z + inset.w <= 0. { - // Bottom right corner. - r.z = r.z - max(inset.z, inset.w); - } else { - r.z = 0.; - } - - if 0. < min(inset.x, inset.w) || inset.x + inset.w <= 0. { - // Bottom left corner. - r.w = r.w - max(inset.x, inset.w); - } else { - r.w = 0.; - } - - let half_size = inner_size * 0.5; - let min = min(half_size.x, half_size.y); - - r = min(max(r, vec4(0.0)), vec4(min)); - - return sd_rounded_box(inner_point, inner_size, r); -} -#endif - -const RED: vec4 = vec4(1., 0., 0., 1.); -const GREEN: vec4 = vec4(0., 1., 0., 1.); -const BLUE: vec4 = vec4(0., 0., 1., 1.); -const WHITE = vec4(1., 1., 1., 1.); -const BLACK = vec4(0., 0., 0., 1.); - -// Draw the border in white, rest of the rect black. -fn draw_border(in: VertexOutput) -> vec4 { - // Distance from external border. Positive values outside. - let external_distance = sd_rounded_box(in.point, in.size, in.radius); - - // Distance from internal border. Positive values inside. - let internal_distance = sd_inset_rounded_box(in.point, in.size, in.radius, in.border); - - // Distance from border, positive values inside border. - let border = max(-internal_distance, external_distance); - - if border < 0.0 { - return WHITE; - } else { - return BLACK; - } -} - -// Draw just the interior in white, rest of the rect black. -fn draw_interior(in: VertexOutput) -> vec4 { - // Distance from external border. Positive values outside. - let external_distance = sd_rounded_box(in.point, in.size, in.radius); - - if external_distance < 0.0 { - return WHITE; - } else { - return BLACK; - } -} - -// Draw all the geometry. -fn draw_test(in: VertexOutput) -> vec4 { - // Distance from external border. Negative inside - let external_distance = sd_rounded_box(in.point, in.size, in.radius); - - // Distance from internal border. - let internal_distance = sd_inset_rounded_box(in.point, in.size, in.radius, in.border); - - // Distance from border. - let border = max(-internal_distance, external_distance); - - // Draw the area outside the border in green. - if 0.0 < external_distance { - return GREEN; - } - - // Draw the area inside the border in white. - if border < 0.0 { - return WHITE; - } - - // Draw the interior in blue. - if internal_distance < 0.0 { - return BLUE; - } - - // Fill anything else with red (the presence of any red is a bug). - return RED; -} - -fn draw_no_aa(in: VertexOutput) -> vec4 { - let texture_color = textureSample(sprite_texture, sprite_sampler, in.uv); - let color = select(in.color, in.color * texture_color, enabled(in.flags, TEXTURED)); - - // Negative value => point inside external border. - let external_distance = sd_rounded_box(in.point, in.size, in.radius); - // Negative value => point inside internal border. - let internal_distance = sd_inset_rounded_box(in.point, in.size, in.radius, in.border); - // Negative value => point inside border. - let border = max(external_distance, -internal_distance); - - if enabled(in.flags, BORDER) { - if border < 0.0 { - return color; - } else { - return vec4(0.0); - } - } - - if external_distance < 0.0 { - return color; - } - - return vec4(0.0); -} - fn draw(in: VertexOutput) -> vec4 { let texture_color = textureSample(sprite_texture, sprite_sampler, in.uv);