Skip to content

Commit 44f72a9

Browse files
Fix CI problems
1 parent 1b1af05 commit 44f72a9

File tree

3 files changed

+76
-42
lines changed

3 files changed

+76
-42
lines changed

crates/bevy_ui_render/src/gradient.rs

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -656,27 +656,35 @@ struct UiGradientVertex {
656656

657657
fn convert_color_to_space(color: LinearRgba, space: InterpolationColorSpace) -> [f32; 4] {
658658
match space {
659-
InterpolationColorSpace::OkLab => {
659+
InterpolationColorSpace::Oklaba => {
660660
let oklaba: Oklaba = color.into();
661661
[oklaba.lightness, oklaba.a, oklaba.b, oklaba.alpha]
662662
}
663-
InterpolationColorSpace::OkLch | InterpolationColorSpace::OkLchLong => {
663+
InterpolationColorSpace::Oklcha | InterpolationColorSpace::OkLchaLong => {
664664
let oklcha: Oklcha = color.into();
665-
[oklcha.lightness, oklcha.chroma, oklcha.hue.to_radians(), oklcha.alpha]
665+
[
666+
oklcha.lightness,
667+
oklcha.chroma,
668+
oklcha.hue.to_radians(),
669+
oklcha.alpha,
670+
]
666671
}
667-
InterpolationColorSpace::Srgb => {
672+
InterpolationColorSpace::Srgba => {
668673
let srgba: Srgba = color.into();
669674
[srgba.red, srgba.green, srgba.blue, srgba.alpha]
670675
}
671-
InterpolationColorSpace::LinearRgb => {
672-
color.to_f32_array()
673-
}
674-
InterpolationColorSpace::Hsl | InterpolationColorSpace::HslLong => {
676+
InterpolationColorSpace::LinearRgba => color.to_f32_array(),
677+
InterpolationColorSpace::Hsla | InterpolationColorSpace::HslaLong => {
675678
let hsla: Hsla = color.into();
676679
// Normalize hue to 0..1 range for shader
677-
[hsla.hue / 360.0, hsla.saturation, hsla.lightness, hsla.alpha]
680+
[
681+
hsla.hue / 360.0,
682+
hsla.saturation,
683+
hsla.lightness,
684+
hsla.alpha,
685+
]
678686
}
679-
InterpolationColorSpace::Hsv | InterpolationColorSpace::HsvLong => {
687+
InterpolationColorSpace::Hsva | InterpolationColorSpace::HsvaLong => {
680688
let hsva: Hsva = color.into();
681689
// Normalize hue to 0..1 range for shader
682690
[hsva.hue / 360.0, hsva.saturation, hsva.value, hsva.alpha]
@@ -834,7 +842,8 @@ pub fn prepare_gradient(
834842
continue;
835843
}
836844
}
837-
let start_color = convert_color_to_space(start_stop.0, gradient.color_space);
845+
let start_color =
846+
convert_color_to_space(start_stop.0, gradient.color_space);
838847
let end_color = convert_color_to_space(end_stop.0, gradient.color_space);
839848
let mut stop_flags = flags;
840849
if 0. < start_stop.1

examples/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -510,6 +510,7 @@ Example | Description
510510
[Many Foxes](../examples/stress_tests/many_foxes.rs) | Loads an animated fox model and spawns lots of them. Good for testing skinned mesh performance. Takes an unsigned integer argument for the number of foxes to spawn. Defaults to 1000
511511
[Many Gizmos](../examples/stress_tests/many_gizmos.rs) | Test rendering of many gizmos
512512
[Many Glyphs](../examples/stress_tests/many_glyphs.rs) | Simple benchmark to test text rendering.
513+
[Many Gradients](../examples/stress_tests/many_gradients.rs) | Stress test for gradient rendering performance
513514
[Many Lights](../examples/stress_tests/many_lights.rs) | Simple benchmark to test rendering many point lights. Run with `WGPU_SETTINGS_PRIO=webgl2` to restrict to uniform buffers and max 256 lights
514515
[Many Sprites](../examples/stress_tests/many_sprites.rs) | Displays many sprites in a grid arrangement! Used for performance testing. Use `--colored` to enable color tinted sprites.
515516
[Many Text2d](../examples/stress_tests/many_text2d.rs) | Displays many Text2d! Used for performance testing.

examples/stress_tests/many_gradients.rs

Lines changed: 55 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//! Stress test demonstrating gradient performance improvements.
2-
//!
2+
//!
33
//! This example creates many UI nodes with gradients to measure the performance
44
//! impact of pre-converting colors to the target color space on the CPU.
55
@@ -8,7 +8,10 @@ use bevy::{
88
color::palettes::css::*,
99
diagnostic::{FrameTimeDiagnosticsPlugin, LogDiagnosticsPlugin},
1010
prelude::*,
11-
ui::{BackgroundGradient, LinearGradient, ColorStop, Gradient, RepeatedGridTrack, Display, InterpolationColorSpace},
11+
ui::{
12+
BackgroundGradient, ColorStop, Display, Gradient, InterpolationColorSpace, LinearGradient,
13+
RepeatedGridTrack,
14+
},
1215
window::{PresentMode, WindowResolution},
1316
};
1417

@@ -26,7 +29,7 @@ struct Args {
2629
animate: bool,
2730

2831
/// use sRGB interpolation
29-
#[argh(switch)]
32+
#[argh(switch)]
3033
srgb: bool,
3134

3235
/// use HSL interpolation
@@ -37,15 +40,18 @@ struct Args {
3740
fn main() {
3841
let args: Args = argh::from_env();
3942
let total_gradients = args.gradient_count;
40-
43+
4144
println!("Gradient stress test with {} gradients", total_gradients);
42-
println!("Color space: {}", if args.srgb {
43-
"sRGB"
44-
} else if args.hsl {
45-
"HSL"
46-
} else {
47-
"OkLab (default)"
48-
});
45+
println!(
46+
"Color space: {}",
47+
if args.srgb {
48+
"sRGB"
49+
} else if args.hsl {
50+
"HSL"
51+
} else {
52+
"OkLab (default)"
53+
}
54+
);
4955

5056
App::new()
5157
.add_plugins((
@@ -85,17 +91,20 @@ fn setup(mut commands: Commands, args: Res<Args>) {
8591
.with_children(|parent| {
8692
for i in 0..args.gradient_count {
8793
let angle = (i as f32 * 10.0) % 360.0;
88-
89-
let mut gradient = LinearGradient::new(angle, vec![
90-
ColorStop::new(RED, Val::Percent(0.0)),
91-
ColorStop::new(BLUE, Val::Percent(100.0)),
92-
ColorStop::new(GREEN, Val::Percent(20.0)),
93-
ColorStop::new(YELLOW, Val::Percent(40.0)),
94-
ColorStop::new(ORANGE, Val::Percent(60.0)),
95-
ColorStop::new(LIME, Val::Percent(80.0)),
96-
ColorStop::new(DARK_CYAN, Val::Percent(90.0)),
97-
]);
98-
94+
95+
let mut gradient = LinearGradient::new(
96+
angle,
97+
vec![
98+
ColorStop::new(RED, Val::Percent(0.0)),
99+
ColorStop::new(BLUE, Val::Percent(100.0)),
100+
ColorStop::new(GREEN, Val::Percent(20.0)),
101+
ColorStop::new(YELLOW, Val::Percent(40.0)),
102+
ColorStop::new(ORANGE, Val::Percent(60.0)),
103+
ColorStop::new(LIME, Val::Percent(80.0)),
104+
ColorStop::new(DARK_CYAN, Val::Percent(90.0)),
105+
],
106+
);
107+
99108
gradient.color_space = if args.srgb {
100109
InterpolationColorSpace::Srgb
101110
} else if args.hsl {
@@ -132,24 +141,39 @@ fn animate_gradients(
132141
}
133142

134143
let t = time.elapsed_secs();
135-
144+
136145
for (mut bg_gradient, node) in &mut gradients {
137146
let offset = node.index as f32 * 0.01;
138147
let hue_shift = (t + offset).sin() * 0.5 + 0.5;
139-
148+
140149
if let Some(Gradient::Linear(gradient)) = bg_gradient.0.get_mut(0) {
141150
let color1 = Color::hsl(hue_shift * 360.0, 1.0, 0.5);
142151
let color2 = Color::hsl((hue_shift + 0.3) * 360.0 % 360.0, 1.0, 0.5);
143-
152+
144153
gradient.stops = vec![
145154
ColorStop::new(color1, Val::Percent(0.0)),
146155
ColorStop::new(color2, Val::Percent(100.0)),
147-
ColorStop::new(Color::hsl((hue_shift + 0.1) * 360.0 % 360.0, 1.0, 0.5), Val::Percent(20.0)),
148-
ColorStop::new(Color::hsl((hue_shift + 0.15) * 360.0 % 360.0, 1.0, 0.5), Val::Percent(40.0)),
149-
ColorStop::new(Color::hsl((hue_shift + 0.2) * 360.0 % 360.0, 1.0, 0.5), Val::Percent(60.0)),
150-
ColorStop::new(Color::hsl((hue_shift + 0.25) * 360.0 % 360.0, 1.0, 0.5), Val::Percent(80.0)),
151-
ColorStop::new(Color::hsl((hue_shift + 0.28) * 360.0 % 360.0, 1.0, 0.5), Val::Percent(90.0)),
156+
ColorStop::new(
157+
Color::hsl((hue_shift + 0.1) * 360.0 % 360.0, 1.0, 0.5),
158+
Val::Percent(20.0),
159+
),
160+
ColorStop::new(
161+
Color::hsl((hue_shift + 0.15) * 360.0 % 360.0, 1.0, 0.5),
162+
Val::Percent(40.0),
163+
),
164+
ColorStop::new(
165+
Color::hsl((hue_shift + 0.2) * 360.0 % 360.0, 1.0, 0.5),
166+
Val::Percent(60.0),
167+
),
168+
ColorStop::new(
169+
Color::hsl((hue_shift + 0.25) * 360.0 % 360.0, 1.0, 0.5),
170+
Val::Percent(80.0),
171+
),
172+
ColorStop::new(
173+
Color::hsl((hue_shift + 0.28) * 360.0 % 360.0, 1.0, 0.5),
174+
Val::Percent(90.0),
175+
),
152176
];
153177
}
154178
}
155-
}
179+
}

0 commit comments

Comments
 (0)