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:  Change in `queue_sprites`: 
This commit is contained in:
parent
e0bf4311d3
commit
3af6179076
@ -640,11 +640,12 @@ pub fn queue_sprites(
|
||||
|
||||
// Store the vertex data and add the item to the render phase
|
||||
if current_batch.colored {
|
||||
let vertex_color = extracted_sprite.color.as_linear_rgba_f32();
|
||||
for i in QUAD_INDICES {
|
||||
sprite_meta.colored_vertices.push(ColoredSpriteVertex {
|
||||
position: positions[i],
|
||||
uv: uvs[i].into(),
|
||||
color: extracted_sprite.color.as_linear_rgba_f32(),
|
||||
color: vertex_color,
|
||||
});
|
||||
}
|
||||
let item_start = colored_index;
|
||||
|
Loading…
Reference in New Issue
Block a user