bevy/examples/stress_tests
Tyler Critchlow 3fc49f00c1
Preconvert colors before sending to shader (#20074)
# Objective

- Fixes #20008 - Preconvert colors before sending them to the UI
gradients shader for better performance

  ## Solution

- Modified `prepare_gradient` in `gradient.rs` to convert colors from
`LinearRgba` to `Srgba` on the CPU before sending to the GPU
- Updated the gradient shader to remove per-pixel color space
conversions since colors are now pre-converted
  - Added documentation to clarify that vertex colors are in sRGB space

This optimization reduces the number of power operations per pixel from
3 to 1:
- **Before**: Convert start color to sRGB, convert end color to sRGB,
mix, convert back to linear (3 pow operations per pixel)
- **After**: Colors pre-converted on CPU, mix in sRGB space, convert
back to linear (1 pow operation per pixel)

  ## Testing

- Verified that the UI gradient examples (`cargo run --example
gradients`) compile and render correctly
- The visual output should remain identical while performance improves,
especially for large gradient areas
- Changes maintain the same color interpolation behavior (mixing in sRGB
space)

  To test:
1. Run `cargo run --example gradients` or `cargo run --example
stacked_gradients`
  2. Verify gradients render correctly

---------

Co-authored-by: ickshonpe <david.curthoys@googlemail.com>
2025-07-16 16:06:45 +00:00
..
bevymark.rs Make Query::single (and friends) return a Result (#18082) 2025-03-02 19:51:56 +00:00
many_animated_sprites.rs Upgrade to Rust Edition 2024 (#17967) 2025-02-24 03:54:47 +00:00
many_buttons.rs many-cameras option for many_buttons (#17935) 2025-03-10 21:23:31 +00:00
many_cameras_lights.rs Copy stress test settings for many_camera_lights (#19512) 2025-06-10 01:12:55 +00:00
many_components.rs Upgrade to Rust 1.88 (#19825) 2025-06-26 19:38:19 +00:00
many_cubes.rs Add UVec to_extents helper method (#19807) 2025-06-26 20:53:49 +00:00
many_foxes.rs Allow users to customize history length in FrameTimeDiagnosticsPlugin (#17259) 2025-01-12 18:18:14 +00:00
many_gizmos.rs Allow users to customize history length in FrameTimeDiagnosticsPlugin (#17259) 2025-01-12 18:18:14 +00:00
many_glyphs.rs Rename JustifyText to Justify (#19522) 2025-06-09 19:59:48 +00:00
many_gradients.rs Preconvert colors before sending to shader (#20074) 2025-07-16 16:06:45 +00:00
many_lights.rs Adopt consistent FooSystems naming convention for system sets (#18900) 2025-05-06 15:18:03 +00:00
many_materials.rs Add many_materials stress test (#17346) 2025-01-24 05:46:23 +00:00
many_sprites.rs Upgrade to Rust Edition 2024 (#17967) 2025-02-24 03:54:47 +00:00
many_text2d.rs Rename JustifyText to Justify (#19522) 2025-06-09 19:59:48 +00:00
README.md Add a stress test profile (#6901) 2022-12-20 15:59:41 +00:00
text_pipeline.rs Rename JustifyText to Justify (#19522) 2025-06-09 19:59:48 +00:00
transform_hierarchy.rs Upgrade to Rust Edition 2024 (#17967) 2025-02-24 03:54:47 +00:00
warning_string.txt

Stress tests

These examples are used to stress test Bevy's performance in various ways. These should be run with the "stress-test" profile to accurately represent performance in production, otherwise they will run in cargo's default "dev" profile which is very slow.

Example Command

cargo run --profile stress-test --example <EXAMPLE>