Skip to content

Commit 3af6179

Browse files
committed
Only compute sprite color once per quad (#7498)
# Objective This change substantially increased performance when drawing thousands of colored sprites. ## Solution The same color is used for each vertex in the quad sprites are drawn too, but the color is converted to a linear color each time. This computation only needs to be done once. The `as_linear_rgba_f32()` call was showing up in profiling the `basic` example in my [particle system library](https://github.com/abnormalbrain/bevy_particle_systems) as a hot path. This change added about 50 fps to the example, from about 150fps to about 200 fps, when rendering around 10k colored sprites. Tracy Results: "This trace" is with the change. Change in frame time: ![image](https://user-images.githubusercontent.com/102993888/216752612-5e0ad0ce-1c59-4b56-873e-8018287408bb.png) Change in `queue_sprites`: ![image](https://user-images.githubusercontent.com/102993888/216752767-6f1a6a5c-6181-45d3-bf86-5823bd81dfc4.png)
1 parent e0bf431 commit 3af6179

File tree

1 file changed

+2
-1
lines changed
  • crates/bevy_sprite/src/render

1 file changed

+2
-1
lines changed

crates/bevy_sprite/src/render/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -640,11 +640,12 @@ pub fn queue_sprites(
640640

641641
// Store the vertex data and add the item to the render phase
642642
if current_batch.colored {
643+
let vertex_color = extracted_sprite.color.as_linear_rgba_f32();
643644
for i in QUAD_INDICES {
644645
sprite_meta.colored_vertices.push(ColoredSpriteVertex {
645646
position: positions[i],
646647
uv: uvs[i].into(),
647-
color: extracted_sprite.color.as_linear_rgba_f32(),
648+
color: vertex_color,
648649
});
649650
}
650651
let item_start = colored_index;

0 commit comments

Comments
 (0)