- Home /
Why is it possible to add additional materials to a model, beyond its sub-mesh count?
Just discovered that you can arbitrarily add additional materials to any model, beyond the number of its sub-meshes. This seems pretty strange ass technically it doesn't make much sense, since the purpose of sub-meshes is to allow efficient batching of a single model by shader/material.
Yet in Unity Editor you can add additional materials which are applied in additional passes by the looks of it, to the last sub-mesh in the model. This means if you had a single mesh model that you could add a second material to 'adjust' the first, say blend a colour over it.
This could be quite a cool feature, but as I said its not something I would have expected. So is this by design or just some quirk that may be fixed in future releases, thus maybe dangerous to rely on.
Just to be clear I am NOT asking about why a model can have multiple materials ( via splitting into sub-meshes per material/shader). I'm asking why you can add MORE materials than the number of sub-meshes in a model.
For example, open Unity and load a model with sub-meshes into the scene hierarchy. Lets say it had 3 sub-meshes/materials. In the inspector (make sure model is selected in hierarchy) you can change the material count from 3 to 4 or greater. Unity will duplicate the last material and the last sub-mesh will now render using both materials (presumably via 2 passes). You can keep adding materials, though they will all be applied to the last sub-mesh only.
Answer by equalsequals · Jul 13, 2010 at 06:19 PM
This is by design.
An example of how to use this would be using 2 separate material ID's on the same mesh.
You can do this in your 3D Modeling application such as 3DS Max by selecting faces of an Editable Mesh/Poly and setting it's material ID to an arbitrary integer. From there a sub-object material could be created and multiple materials applied to the same singular mesh.
Cheers,
==
You are describing sub-meshes using individual materials aren't you, which is exactly NOT what my question is about.
No, I am speaking of a single mesh using multiple materials. In any case, it is by design - not a quirk.
But if its by design why does it break down when a model has multiple sub-meshes? If it were by design I would expect each additional material to be applied in the same sequence to sub-meshes. That is if you have 3 materials (3 sub-meshes) you could add 3 more and each would blend with its original counterpart.
I just created 3 separate boxes and attached 2 to the third box. I then applied 3 separate materials, all diffuse, 2 with textures and 1 just a color and they all blended into eachother as expected. Sorry if I am not understanding, it could be a matter of lexicon or I just can't see your result. In any case - this isn't an efficient way of blending materials by any means, a better method would be to use a shader which takes different texture references and lerps them together using something like an alpha channel to achieve blending.
yeah i think language is getting in the way here, we could be talking of the same thing from different perspectives or completely different things ;) i'll see if i can mock up some screenshots to illustrate the issue/feature
Answer by Mike 3 · Jul 13, 2010 at 06:20 PM
I'm pretty sure it's by design, and it's something I use pretty frequently
My own personal experience is to use it for a layered clothing system - I add multiple cutout materials over a base diffuse layer to get different sets of clothing
Well it can definitely be useful,but I'm not sure it is by design, since it breaks as soon as you have multiple sub-meshes, as all additional materials are only applied to the last sub-mesh in the model. So works well for models with a single mesh, but doesn't for others.
Not sure how that disproves it being by design - the UI for being able to assign multiple materials to each submesh would be a lot more complex, ins$$anonymous$$d of the rather simplistic one we have which works for 99% of use cases
Well its inconsistent and somewhat unexpected behaviour. I don't think support for multi-mesh models would be much more complex, plenty of ways of achieving that. Is this doucmented anywhere? You see my problem is if it has slipped through by virtue of generic support for materials assigned to model, then it may be broken in the future.
That's the thing - you're talking about submeshes, which is not the same as multi mesh models. If you want to do multi mesh models (as opposed to one mesh with multiple submeshes), there isn't anything stopping you. If you want multiple submeshes with multiple materials, most likely you're overcomplicating things. The multiple materials per multiple submesh case is an extremely fringe one, and I'm not sure supporting it is even remotely a good use of time compared with other features and bugs
Answer by Chaoss · Sep 17, 2013 at 03:41 PM
Unity doesn't appear to support multiple materials per mesh, any subsequent materials are always greyed out so what I do is split the mesh and do it that way
Answer by badweasel · Feb 02, 2015 at 09:19 AM
Here's how I'm using that. I know that my mesh will have UP TO 5 submeshes. But at times it might only have 1. So I preload it with 5 instances of my material. Then I can programmatically define the number of submeshes I need at any given time and add them. I could add the materials as needed also but in this case chose not to.
Your answer
Follow this Question
Related Questions
How does submesh index map to material? 1 Answer
Combining blender submeshes 3 Answers
How to work with submeshes in editor 1 Answer
Assign new material to submesh? 1 Answer