The model that I have has a couple of submeshes with different materials.
The shader I have is just a simple color blend but I would like it to blend with the different submeshes materials. What do I need to add to achieve this?
Can you better explain what you would like? You say âThe shader I have is just a simple color blend but I would like it to blend with the different submeshes materialsâ. Shaders donât blend materials. What do you mean?
So here is a screen-shot of the materials that are on the object.
There are 3 different materials on 3 different sub-meshes of the object. When I select this object I add a 4th material with the shader that I mentioned before. The shader is transparent, so I imagined that if I put it as a last material everything that precedes it in the materials array will get shown with the shader on top. But it seems that its only the last material that shows with the shader.
So my question is, how would I go about making all other materials show with the shader?
Or is there a better way of sort of highlighting objects that has sub-meshes and different materials?
The material list is not a sequence of materials, but a list of one material per sub-mesh. So technically you cannot simply add a material to have it applied to all those before.
Except it appears in Unity editor that you can arbitrarily add materials, which I was very surprised to discover as it doesnât make any real sense.
This means if your model has a single mesh, then you can overlay other materials. I guess it must just treat them as separate passes. Iâm unsure if this is intentional, but its quite a cool feature.
Of course once you have more than one submesh the âoverlayâ technique breaks down. From a quick test the additional materials are always applied to the last submesh (i.e last real material).
As for your actual question, you need to either
a. Assign you blending shader to all the materials of the model, though losing their original material.
b. Write a new shader to incorporate the blending. Depending upon your requirements, this could be as simple as adding an alpha property. Alternatively perhaps add it as an additional pass, though you may have to swap shaders/materials still.
c. Combine the sub-meshes, though if they are actual meant to be using different materials, with say different textures applied, then this will force them to all use the same shader. However there should now only be one submesh so using your original idea would work.
d. Duplicate the model, then combine its meshes, thus arriving at âcâ above. However now you can apply your blending shader/material to the duplicate and if the shader states are set up correctly will blend over the original model.
Thanks a lot Noisecrime for the explications. That is something I didnât understand before.
Now about your propositions.
The materials on the submeshes have different shaders and textures so I cannot make something that will result in loosing that information.
The only option I have is to add something to them that will keep the original look but will blend and highlight the part I am selecting.
So the method I wanted to use was to create a new material slot and add there the material that holds the transparent shader with a color that would highlight the mesh, but this shader that I am using at the moment shows only with the last material of the array and since this last material is used only on a submesh, only that part get highlighted where the last material is.
Iâve looked into the combine mesh proposition of kingdruid, and Iâve found this (mesh.CombineMesh): http://forum.unity3d.com/viewtopic.php?t=35239
I donât know if it is the same as what kingdruid suggested with the set triangles.
The other thing is that the full mesh of the sclera for example contains more than 60k vertices, so as Iâve read somewhere I canât use combine mesh where that vertex limit is reached.
So at this point, I think the shader option would be the most suitable, but what should I add to the shader that I already have (first post) to get the desired result?
EDIT: Iâve edited this whole post because some things I wrote were confusing.
Okay I think I have an idea.
Could you please tell me if it is something usable?
So lets say the object has 3 sub-meshes with 3 different materials using different shaders and textures.
Lets say Specular with only main color,
Transparent/Specular with a texture and
Bumped Specular with another texture and its bump.
So how about modifying each shader used, to have an additional texture slot. When the object is not selected it would be empty so that would make no effect to the textures already used by the shader. But when it becomes selected it would look up the materials used on the object and put a texture in the slot and the shader would blend this texture according to its alpha with the textures or colors already used in the material, thus giving the desired âhighlightedâ effect.
Would it work like this?
Thanks a lot
Greg
EDIT: Having re-read this thread I think Noisecrime was talking about a similar solution! So disregard the first sentence of this post please!