Skip to content

Commit 5cb6089

Browse files
ManevilleFinodentry
authored andcommitted
Added colors to sprite stress test (bevyengine#5317)
# Objective Allow better performance testing for bevyengine#5247 ## Solution I added color tints to the `many_sprites` example stress test.
1 parent 3c05b7f commit 5cb6089

File tree

3 files changed

+20
-5
lines changed

3 files changed

+20
-5
lines changed

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1232,7 +1232,7 @@ path = "examples/stress_tests/many_animated_sprites.rs"
12321232

12331233
[package.metadata.example.many_animated_sprites]
12341234
name = "Many Animated Sprites"
1235-
description = "Displays many animated sprites in a grid arragement with slight offsets to their animation timers. Used for performance testing."
1235+
description = "Displays many animated sprites in a grid arrangement with slight offsets to their animation timers. Used for performance testing."
12361236
category = "Stress Tests"
12371237
wasm = true
12381238

@@ -1272,7 +1272,7 @@ path = "examples/stress_tests/many_sprites.rs"
12721272

12731273
[package.metadata.example.many_sprites]
12741274
name = "Many Sprites"
1275-
description = "Displays many sprites in a grid arragement! Used for performance testing"
1275+
description = "Displays many sprites in a grid arrangement! Used for performance testing. Use `--colored` to enable color tinted sprites."
12761276
category = "Stress Tests"
12771277
wasm = true
12781278

examples/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -277,11 +277,11 @@ cargo run --release --example <example name>
277277
Example | Description
278278
--- | ---
279279
[Bevymark](../examples/stress_tests/bevymark.rs) | A heavy sprite rendering workload to benchmark your system with Bevy
280-
[Many Animated Sprites](../examples/stress_tests/many_animated_sprites.rs) | Displays many animated sprites in a grid arragement with slight offsets to their animation timers. Used for performance testing.
280+
[Many Animated Sprites](../examples/stress_tests/many_animated_sprites.rs) | Displays many animated sprites in a grid arrangement with slight offsets to their animation timers. Used for performance testing.
281281
[Many Cubes](../examples/stress_tests/many_cubes.rs) | Simple benchmark to test per-entity draw overhead. Run with the `sphere` argument to test frustum culling
282282
[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
283283
[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
284-
[Many Sprites](../examples/stress_tests/many_sprites.rs) | Displays many sprites in a grid arragement! Used for performance testing
284+
[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.
285285
[Transform Hierarchy](../examples/stress_tests/transform_hierarchy.rs) | Various test cases for hierarchy and transform propagation performance
286286

287287
## Tools

examples/stress_tests/many_sprites.rs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
//!
44
//! It sets up many sprites in different sizes and rotations, and at different scales in the world,
55
//! and moves the camera over them to see how well frustum culling works.
6+
//!
7+
//! Add the `--colored` arg to run with color tinted sprites. This will cause the sprites to be rendered
8+
//! in multiple batches, reducing performance but useful for testing.
69
710
use bevy::{
811
diagnostic::{FrameTimeDiagnosticsPlugin, LogDiagnosticsPlugin},
@@ -16,12 +19,19 @@ use rand::Rng;
1619

1720
const CAMERA_SPEED: f32 = 1000.0;
1821

22+
const COLORS: [Color; 3] = [Color::BLUE, Color::WHITE, Color::RED];
23+
24+
struct ColorTint(bool);
25+
1926
fn main() {
2027
App::new()
2128
.insert_resource(WindowDescriptor {
2229
present_mode: PresentMode::Immediate,
2330
..default()
2431
})
32+
.insert_resource(ColorTint(
33+
std::env::args().nth(1).unwrap_or_default() == "--colored",
34+
))
2535
// Since this is also used as a benchmark, we want it to display performance data.
2636
.add_plugin(LogDiagnosticsPlugin::default())
2737
.add_plugin(FrameTimeDiagnosticsPlugin::default())
@@ -32,7 +42,7 @@ fn main() {
3242
.run();
3343
}
3444

35-
fn setup(mut commands: Commands, assets: Res<AssetServer>) {
45+
fn setup(mut commands: Commands, assets: Res<AssetServer>, color_tint: Res<ColorTint>) {
3646
warn!(include_str!("warning_string.txt"));
3747

3848
let mut rng = rand::thread_rng();
@@ -69,6 +79,11 @@ fn setup(mut commands: Commands, assets: Res<AssetServer>) {
6979
},
7080
sprite: Sprite {
7181
custom_size: Some(tile_size),
82+
color: if color_tint.0 {
83+
COLORS[rng.gen_range(0..3)]
84+
} else {
85+
Color::WHITE
86+
},
7287
..default()
7388
},
7489
..default()

0 commit comments

Comments
 (0)