So i've got a few assets on a project rite now that have glass overlapping metal (like a coffee table for example) and i'm trying to figure out if there's a more efficient way of setting up my materials while avoiding sorting issues.
Currently what i'm having to do is split the opaque and transparent pieces into sub meshes, each with their respective materials. This isnt a huge issue, but if i could be saving on draw calls by having a single piece that would be much preferred.
Whats the best way of doing this?
(unity 5 btw)
Replies
You just have to create semi-transparent parts in your Albedo map (lower opacity/fill in Photoshop or similar), save in a format that retains this transparency (PNG, TIFF, etc [not JPG, etc]) and then set the Render Mode of your material to Fade, Cutout or Transparent, depending on your intended look.
Left: Fade with zero opacity in the center | Right: Fade with an opacity gradient with opaque speckles in the center
It should be noted that if you are going for a physically accurate look, you should also make a Metallic or Specular map (depending on the shader/approach used) to set the properties of the different physical materials (metal, glass, ...) for the various areas of your texture maps.
This is the correct approach. However, splitting up in various parts with their own material is a quick, easy fix. But splitting up meshes won't work well with skinned meshes, such as animated characters, and as you said, adds more draw calls.
Edit:
I realised the second picture maybe wasn't all that clear with that grey background.
If you use a transparent material for the entire thing, you're going to get sorting issues.
The way to avoid that is to use a transparent materials only for the bits you need to actually be transparent, and use an opaque version for everything else.
Cut out/alphatest only works if you're fine with not having things that are semi-transparent. As this is a table with a glass top, that's not going to cut it. The glass parts would be entirely see-through or entirely opaque.
All approaches work fine with skinned meshes. I'm not sure why you think it wouldn't...
Next time, I should make sure to first check who's methods I'm putting into question, before I spend time and effort formulating a "better method". And if I do put time and effort into it, I should test the method with a good example before posting...
And what I meant with "won't work well with skinned meshes" was that it'd be a real hassle having to cut up a character model into multiple parts and skin them individually to the bones.
Of course -now- I know that is pretty much what people do when making cosmetic items for Dota2 etc...
Let's just pretend that the only thing that happened here, was that I learned something? All agree? I agree...
You can fix most sorting errors by carefully re-ordering the vertices to draw in the order you want. It's a pain in the ass, especially with complex overlapping models. But it can be done.
The issue I usually run into though is the fillrate expense of all that transparency, which is usually more than the cost of multiple passes.
We have some stuff here that might help.
http://wiki.polycount.com/wiki/TransparencyMap#Sorting_Problems
Although, as long as you know that it's only going to be seen from that angle then yeah, it'll work.
Only place I've had it fail is when faces are penetrating each other, like an X.
But still, it's a pain to do, all manual.
I'm not sure if it's supposed to work as well as it does, but it works well in most cases.