- Home /
Why is only the last Material in the Materials array on a Mesh Renderer used?
I am trying to apply Diffuse, Specular, and Normal maps to a single mesh. I have the Diffuse map in a Diffuse Material, and the Specular and Normal maps in a Bumped Specular Material. After placing both materials in the Materials array on the object's Mesh Renderer Component, only the last material in the array is used. If the Diffuse material is the last material, then I have a colored mesh with no specular or normal map applied. If the Bumped Specular material is the last material, then I have an uncolored mesh with specular and normal maps applied.
Answer by Eric5h5 · Feb 08, 2013 at 07:54 PM
You can't combine materials like that; you'd need to use a single shader with a single material that contains all the elements, which in this case is the Bumped Specular shader. The reason you'd use an array of materials is if you had a mesh with submeshes, so each material gets applied to a different submesh.
Ok, that makes sense. I see now that the "Shininess" slot in the Bumped Specular uses the RGB channels for diffuse and the Alpha channel for specular. Before, it seemed like this was a shader that omitted Diffuse.
Answer by ThePunisher · Feb 08, 2013 at 08:28 PM
You can stack materials on the same mesh, but in your case what's probably happening is that only the top material is showing because it's covering all the previous materials. In other words, the last material in the array being applied.
To prove it you could grab a texture with some alpha sections in it and create a new material with a shader that handles transparency, then apply it as the last material in the array. Other materials (and their textures) should show through the alpha sections.
Thanks, that helps a lot. If I understand correctly, all of the materials are being used, but they are drawn in order, such that the last one is the only one that shows since it covers the rest.
@ThePunisher That is some fantastic info!
I am still learning textures and material settings. Just got the Uber Shader to play with.
I also just found out I can have one UV and have many materials set to that one UV and use them all over the model. That is possibly what submeshes are? One UV with a different material applied to different polygons within the same UV? Correct me if I am wrong on that.
Regardless, it works for me to do that.
The UV can look like a mess, depending on how it is set up. But I also found the UV only has to look nice for those that have to work with it, not for the render to use it well, or to have the textures look great on the model when rendered.