What is the best way to optimise materials?

My scene has quite a number of geometries using a handful of textures but each geometry has the potential to have an individual diffuse colour. ie, same car model but different paint job colour.

I read somewhere that materials should be reused. I understand that the materials will share the same textures but is it possible to use the same material but with different diffuse colours?

A way I could approach this is to sub class a material. Is that possible? What I mean by that is, is it posible for me to create a material that only specifies a diffuse colour with a reference to another material defined as Lighting.j3md - In this way only the diffuse colour will be individual and all other parameters will be shared. Is that possible?

I spent quite some time in the forum and wiki but couldnt find anything on material optimization that seemed applicable to what I believe I need to acheive.

or, is it that this is something i do not need to be concerned about. I would really like some guidance on this.

Many Thanks

Reusing material instances won’t give you any performance increase. Best way would be to trash the diffuse color approach and use a texture atlas for colors, then batch the objects.

I have been thinking how I can use the atlas. It seems odd to have a whole tile 512,512 dedicated to just one colour or a blend of a couple/few. I am thinking of writing a shader to perform this on the fly.

Also, it appears the atlas alters the texcords for each mesh to point to the correct tile? If this means all the geometries that share the same mesh will be affected then this will not work for me.

I am quite liking the idea of writing my own shader so the material only has the parameters that will change. The geos can share the mats that are identical. Is it posible to hardwrite Texture2Ds to shaders without the need for materials to pass a reference? this would be super because the textures are constant, only the colours change.

Regards

You’ll still end up with separate geometries with separate parameters and don’t gain any performance. If you batch the geometries you’d set different texture coords for each (sub)mesh and point them to the color in question on the atlas, which only has to be a few pixels for each color really.

If you only have a handful of colored materials (like 5 - 9), you can just batch without worrying about atlasing or anything. It will create N batches (one for each color) but you will still get a huge reduction in number of objects rendered.