mirror of
https://github.com/bevyengine/bevy
synced 2024-11-26 06:30:19 +00:00
rounded border: remove dead code in shader (#12602)
# Objective - #12500 added dead code to the ui shader ## Solution - Remove it
This commit is contained in:
parent
93c17d105a
commit
2f6d8663d0
1 changed files with 0 additions and 141 deletions
|
@ -62,10 +62,6 @@ fn vertex(
|
|||
@group(1) @binding(0) var sprite_texture: texture_2d<f32>;
|
||||
@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<f32>, size: vec2<f32>, radius: vec4<f32>, in
|
|||
return sd_rounded_box(inner_point, inner_size, r);
|
||||
}
|
||||
|
||||
#ifdef CLAMP_INNER_CURVES
|
||||
fn sd_inset_rounded_box(point: vec2<f32>, size: vec2<f32>, radius: vec4<f32>, inset: vec4<f32>) -> 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<f32>(0.0)), vec4<f32>(min));
|
||||
|
||||
return sd_rounded_box(inner_point, inner_size, r);
|
||||
}
|
||||
#endif
|
||||
|
||||
const RED: vec4<f32> = vec4<f32>(1., 0., 0., 1.);
|
||||
const GREEN: vec4<f32> = vec4<f32>(0., 1., 0., 1.);
|
||||
const BLUE: vec4<f32> = vec4<f32>(0., 0., 1., 1.);
|
||||
const WHITE = vec4<f32>(1., 1., 1., 1.);
|
||||
const BLACK = vec4<f32>(0., 0., 0., 1.);
|
||||
|
||||
// Draw the border in white, rest of the rect black.
|
||||
fn draw_border(in: VertexOutput) -> vec4<f32> {
|
||||
// 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<f32> {
|
||||
// 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<f32> {
|
||||
// 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<f32> {
|
||||
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<f32> {
|
||||
let texture_color = textureSample(sprite_texture, sprite_sampler, in.uv);
|
||||
|
||||
|
|
Loading…
Reference in a new issue