Question about the Material System

I had a question about the way Unity handles materials in the engine. As I understand from here:

Unity can apply a specific material effect to a given object. IE, make the object have a highly reflective, metallic finish. However this appears to apply universally to the entire object, so if I were to make an object reflective, the ENTIRE object would be affected.

Now, let’s say I have an object like this sword hilt:

For sake of argument, the yellow and gray parts are meant to be gold and silver, respectively. The grip is ebony with a low polish, the black on the pommel and guard is polished jet, and the red parts are meant to be garnets. This model is all one object, however different parts of the hilt should react differently to the light:

The gold and silver would be highly reflective, as would the jet and garnets. The wood grip would be more diffuse. Let’s also say that to make it more complex, the background to the clips holding the grip together is more of a frosted texture than being highly polished, to make the raised details “pop” more. The background there would then be more diffuse.

As I understand from the Materials and Shaders manual entry, if I were to apply a particular effect to the model as it currently exists it would affect the entire thing, since it’s all one object and material. What I’m curious about is whether it’s possible to create a shader that can apply multiple material effects to the same object based on a mask image.

I’m not talking about a specular map, as I’m not JUST trying to determine how diffuse or shiny the surface is. This would be a separate map that works WITH the spec map by setting the material properties of whatever is under a map. Say, (255, 255, 255) is a very reflective surface ideal for the “jet” and “garnets” on this sword, while (65, 65, 65) is somewhat less reflective, but still very polished (ideal for the polished “gold” and “silver” parts of the hilt). This would essentially allow multiple materials to be applied to the same object. It could be either a separate map, or used as an alpha mask applied to the Spec map.

Any thoughts?

Aside from custom shaders, it’s easier to make the object have submeshes and then apply different materials to the appropriate parts.

–Eric

Here’s the problem:

At least in the case of Blender the Material applies to the ENTIRE object and not just the individual submesh. Additionally, if I wanted to make each part of the model that’s supposed to be a different type of material (metal vs. wood, etc) a separate mesh, it would require an unwieldy number of meshes, as well as possibly inflating the poly count.

I really think shaders would be the way to go. Am I correct in assuming from your post that what I’m asking IS possible, it would just be more difficult to set up?

You simply need the specular map shader in unity. The alpha channel then controls the shininess of said parts. This is also known as a gloss map shader. The specular one is built into unity though. Spec/bump/normal can emulate nearly any surface known to mankind so I’m not sure why you’re set against using it.

Certainly, its capable of making weapons (its the shader people use in pc/console games like skyrim)

If it has submeshes, just drag the relevent materials on it in unity.

No, I use Blender and there’s no problem making submeshes with multiple materials. There may be other ways, but I just map different textures to different submeshes.

I expect that it’s possible, but you’d have to write a custom shader.

–Eric

Eric,

The main problem with your approach is complicated model like my sword hilt would require not only a lot of extra meshes, it may also push the poly count.

Hippo,

What I’m getting at is that the spec/shiny of a surface is only part of the story. Take two materials: One Reflective and one Normal using Unity’s default shaders. Give them both the same specularity (say, (255, 255, 255) for full spec) they’re not going to look the same. The “normal” one is going to look less reflective. Yes, I can use the specular map to fine-tune the final effect, but if I have an intricate design I need to put on one object–say, metal filigree on a wool tunic–even if I make it highly specular the metal wouldn’t look right if I used the Normal shader because the reflectivity of the metal will be missing. Likewise, if I use the Reflective shader, now my wool fabric is going to look like its made of metal regardless of how low the spec is.

I’m just looking for a way to mix reflective and non-reflective materials on one object without having to take Eric’s approach.

Anyway, he’s pretty much answered my question. I was mainly looking for confirmation that a custom shader COULD be written to provide the functionality I’m looking for.

No, it would require 1 submesh per material. If you have 2 materials, then there are two submeshes. But if all the minute details are meant to be different materials, then yes, you would want the different reflectivity to be mapped via texture rather than using polygons.

–Eric

You can have a look at my lil Shader-pack 747185–27253–$Eyecy Shaders.zip (3.6 KB) i did some time ago.
It lets you add a Colored Specular map with a gloss map in it´s alpha channel. So you can handle differnent reflectivities in one material.
The Gloss map (Alpha Channel) is defined by Dark = Wide specular and Bright = Tight specular (Gloss)

I don´t know but i guess the shaders don´t work well with lightmaps.

It is always possible to reduce Drawcalls by good texturing.

A sword is something where 1 material is more than enought if it is not shown super detailed.

Eric,

Exactly. In the case of the sword example I posted, there’d be a LOT of places where there’s smaller details that might be reflective to stand out from a non-reflective background (think about those coin commercials where they offer $20 coins that have a frosted relief image on a mirror background). It’d take FAR too many polys to make that a separate mesh.

Eyce,

What you’re describing sounds a lot like what I’m looking for: an Alpha channel that allows one material to be both Reflective and Non-reflective on top of the base specularity.

There is a few shader packs that let you plug in a specular channel seperately, like advanced surface shaders for instance - its my preference since I can control the specular values better, however, you could easily load up photoshop, and transfer your specular layer into the alpha channel, as that is how unity plugs it in by default.

Eyce,

Your pack is ALMOST what I’m looking for. You don’t happen to have one that also adds Reflection using a cube map to the Normal-BumpSpec, do you? That’s the main thing I’m looking for: A shader that separates how reflective an object is from its specularity.

In Unity’s built-in shaders the specular map in the RGB’s Alpha channel controls them both. What I’m looking for is the ability to have high-spec/low-reflective and vice-versa surfaces on the same material. IE, both a mirror and a highly polished piece of wood have high specularity, but the mirror is very reflective while the wood isn’t. With the built-in shaders the only way to do so is, as Eric said, using multiple materials. However as we’ve already discussed, depending on the mesh this may not be practical.