Currently, I have models with hundreds of reasonably complex components, and each has its own material assigned. This is so that they can be different colours and different opacities.
I have read that sharing materials is good practice, but for me to do this it would take some refactoring, so before I embark on doing it, I wondered the following…
Am I correct in thinking that if modals require different colours and opacities, there has to be a separate material for each?
Are there any benchmarks for how much performance gain there is between sharing materials with hundreds of components?
Most of the time I change opacities only to fade in/out components, so I animate the opacity between 0-100. Is there a neater way of doing this so that I can share materials?
Yes. (unless you convert them to instances with InstancedMesh, in which case you can also have a unique color per-instance.)
Usually performance is decent/usable for under ~200 or so and then starts to drop off a cliff… at that point you might want to be more aggressive about sharing materials or using InstancedMesh
Opacity isn’t really supported by instancing, so you might be out of luck… but if you’re only changing opacity on one mesh, you could temporarily swap its material with a unique one, and then set it back when the opacity is done changing.
If this code/mechanism is going to be a fundamental part of your app… you can investigate more customized solutions, like a modified InstancedMesh + material, modified to add an opacity per instance… but then you may lose a tiny bit of performance since all those instnaced will have to be marked as transparent regardless if they are fully opaque or not. There’s not always a clean/easy way to tailor these use cases.