Multiple Materials per Object- is it really "bad"?

Hi all, thanks in advance for your thoughts-

I’m working on some art assets that really work best with multiple materials, since they have multiple tiling textures on various parts (created via IDs and Multi-SubObject in Max).

I know I COULD bake out a single, simple, diffuse map- but this would lose all the nice up-close texture detail that tiling gives, and make things much more complex for me to edit.

I also hope to be able to edit these various materials via script mid-game, but that’s another story.

Reading through the Unity docs, I saw that multiple maps per object is “bad for performance reasons”. I would like to know, is this simply stating the obvious (more maps =, well, more maps), or is there something nasty that happens when doing this (ie, Unity just doesn’t like it/deal with it well).

I would ASSUME that using 5 plain color maps + 2 256x256 maps would be actually better than a single 512x512 map even, or at least a 1024x1024. However, am I completley wrong? And would it be different if each of those materials were on a unique object (going back to the “it just causes issues when mult maps on one object” hypothesis").

Lastly, lets say I decide to keep these multiple materials per object- is there a way to control them individually? As in, I want to drag my own maps onto the object, and have it use those (since otherwise Unity keeps importing it’s own…blarg).

Thanks!!!

The reason multiple materials is “bad” is that each material is a so-called drawcall. A drawcall involves things like loading a new shader, different textures, etc. This is normally an expensive operation (and unrelated to the amount of vertices involved).

That doesn’t mean you shouldn’t use multiple materials. It just means you might run in to trouble if you use multiple materials for every single object in your game. But even then there are methods to reduce drawcalls without sacrificing materials (look for “Mesh Combining” in the reference manual or on the forums).

3 Likes

Hi tomvds, thanks for the info-

to be more specific: i realize that, naturally, more materials = more work for the game. However, i’m wondering if all the materials being one ONE mesh is going to multiply the performance loss?

For example, which scene would perform better:

Scene A: One mesh, 6 materials on it. All materials are either flat colors or less than 256x256 texture, tiling.

Scene B: 6 meshes, all the same materials as above.

Scene C: 1 Mesh, one 2048x2048 map.

I’m certain other factors would normally come into play, but i’m most interested in knowing whether having all those materials on one mesh causes more performance loss than being on seperate meshes? Just making sure i’m not cutting my FPS in half due to some silly error :stuck_out_tongue:

Thanks!

C would perform better. A and B are pretty much the same.

–Eric

3 Likes

If your using flat colour just make a colour chart and UV map so each mesh has its UV’s on the correct colour. then all your objects only need 1 material.

1 Like

This topic is something I’ve wondered about as well but I’ve put off until I am in an optimize phase. Thanks for the thread responses. When you say a color chart, do you mean just a texture with all the flat colors you’re going to use and then do your unwraps in the proper section? If you use the same material for multiple meshes, is the way to save is to combine meshes? Right now I have a race car where the wheels, car body and driver are all different meshes. I could combine the driver and car ( he doesn’t animate ).

thanks for all the replies, and glad to know maybe this will help at least one/two others out.

A few questions:

1)Tysoe- (slaps forehead) duh! I’ll do this, definitely. Thanks!

2)Eric- That seems odd. A fairly gigantic 2048x2048 material would be BETTER than multiple flat color/small tiling materials? I suppose it only needs to be loaded/dealt with once, and I guess the situation could flipflop depending on the amount of memory available, to load up such a big’ol map. Then again, it is the only map in the entire level, so should be fine :stuck_out_tongue:

Also, thanks for the B-A clear up. Good to know they play out the same.

3)Hyjinx- I would say you should keep your meshes separate, so you can animate them/edit later, easier. Then again, if you know for a fact you will never need them separate, I would def say to make them all one. My thoughts :slight_smile:

Thanks again!

Texture size has little impact on speed; mipmaps ensure that few texels are actually computed on far away objects. Draw calls have a significantly higher effect on speed.

–Eric

@Eric, are you certain? C consumes more memory, but wouldn’t that reduce the drawcalls to 1?

Cheers,

Galen

Yes, so it would perform better as I said. :slight_smile:

–Eric

Ahh punctuation … forgive me, I am apparently reaching the age where my eyesight isn’t what it use to be :slight_smile:

Cheers,

Galen

Well, it is just a few pixels after all; I edited it to make it more obvious. :wink:

–Eric

I went into my game and redid every mesh so that every mesh shared only 1 material in the entire scene. After I did that I got a performance boost.

But only when I optimized the shadows and lights did I see the huge performance boost I wanted.

Word to the wise, focus on lighting and shadows also along with draw calls and such.

1 Like

A single pixel light can double or even tripple your draw call count if it’s casting shadows. So you should keep lights to a bare minimum and try and use direct/parallel lights as much as possible since they are the cheapest.

1 Like

I think a lot of this mesh/texture optimisation should be looked at in the context of your project and the target platform. Just like code optimisation, you could spend weeks reworking stuff for marginal increase with the project not moving forward. My horror project uses tons of materials/textures/lightmaps with hundreds of drawcalls but on my nvidia 8800GT i still get a framerate in the many hundreds.

iPhone dev is obviously different but I take each project individually when modelling and coding.

Regards,
Matt.

1 Like

ufda, thanks for all the info :smile:

I was happily placing “force pixel lights” all over, when I noticed that the vertex lights looked terrible.

It’s ironic, because I’m normally all about lightmapping- just this time the game would be best served with small unity lights :stuck_out_tongue:

2 objects and 5 lights became 54 drawcalls, and another scene (these are all static-top-down scenes, only 1 object in the scene moves around) has 17 lights and 5 objects. yoiks, drawcalls must be ugly there…relative to what they should be, anyway.

I was using the dynamic Unity lighting because I hope to animate the lights in-game…maybe I will have to just bake it in (iPhone game). Will have to test and see. No shadows, at least.

oh, big question- say i lightmap all, is there a way to have the lights be vertex only, but ONLY affect specular, not actually light the object (dont’ want them messing up my pretty pretty lightmaps :stuck_out_tongue: )

this is very interesting and informative.

i am currently working on a project using only the material vertex colour and no texture and am wondering if this how this performs against using a texture.

it seems odd to think that using 6 flat material colours would be worse than using one large texture.

thanx

kieron

it depends on the hardware and shader … depending on that it can perform better but if you get too many draw calls it will die totally

sorry i should clarify this is an iphone project. i am beggining to wonder if really the iphones hardware really locks you to a very narrow set of solutions.

thanx