bevy/crates/bevy_ui_render
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
..
src Preconvert colors before sending to shader (#20074) 2025-07-16 16:06:45 +00:00
Cargo.toml remove unused dependencies (#19998) 2025-07-07 20:10:33 +00:00
LICENSE-APACHE bevy_ui_render crate (#18703) 2025-07-03 23:36:35 +00:00
LICENSE-MIT bevy_ui_render crate (#18703) 2025-07-03 23:36:35 +00:00
README.md bevy_ui_render crate (#18703) 2025-07-03 23:36:35 +00:00

Bevy Render UI

License Crates.io Downloads Docs Discord