#Is it a good idea to pool materials?

6 messages · Page 1 of 1 (latest)

novel grotto
#

I have entities (≈10000) and each entity has its own material.
I found that if I spawn them all at once and add their materials to Assets, bevy spend a lot of time to run prepare_materials.
But actually, these entities aren't all visible at the same time. So, I'll pool these materials and reuse. Is this a good idea? Thanks.

novel grotto
#

It seems that instead of first prepare thousands of materials and freeze, it needs to prepare 10~20 materials every frame.
IDK how this will affect to fps...

dire kettle
#

cant you reuse a single material ?
Are they all that special ??

it's quite common to have a texture that has a lot of data (colors) so the meshes access the data using different UV Mappings.

But in general reusing materials is a good idea.
You can just clone() the Handle<Material>

#

The creation of Materials can also be done in a own thread,
only the integration into the assets must be done in the bevy system.

and it also sounds that you system could just work with Lazy Loading

#

meaning: You create the material once you need it the first time.
what still could become a problem if a lot of new Entities with new materials spawn.
I personally ran more into performance troubles with meshes.

novel grotto
#

No, I can't because they have to be calculated from each component.

However, I noticed that it will be prepared when something changed in a material. This means that if I have to change the material obtained from the pool, it's no different from creating the material and adding to Assets on the fly.
So I don't even have to pool. I will do 'Lazy Loading' you called. I don't think my game does a lot of spawning at once, so it shouldn't be a problem.

Thanks you!