Home Unity

Best way of dealing with transparent & opaque within one material

polycounter lvl 19
Offline / Send Message
MikeF polycounter lvl 19
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

  • Farfarer
    That's the way to do it, split it into transparent and opaque parts.
  • MikeF
    Offline / Send Message
    MikeF polycounter lvl 19
    Great, thanks Farfarer
  • Hyshinara
    [IGNORE THIS POST]
    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
    Fade_with_zero_opacity_center.pngFade_with_opacity_gradient_and_opaque_speckles_in_center.png

    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.
    Fade_with_opacity_gradient_and_opaque_speckles_in_center_in_front_of_crates.png
  • Farfarer
    What he's asking is having a mesh that has both opaque and transparent parts to it.

    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...
  • Hyshinara
    Ok, so, I never actually used transparency on geometry with overhangs. I did a test just now and see what you mean with the sorting issues... I stand corrected and feel like a total dunce.

    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...
  • Farfarer
    You don't need to actually split then into separate meshes, so long as they've got different materials applied, Unity automatically splits then into sub meshes at import time, so you still get to treat it as if it's a single object.
  • Mant1k0re
    Offline / Send Message
    Mant1k0re polycounter lvl 8
    Okay so for clarification sakes, no matter what you got to use at least 2 materials in those cases, no way to save on drawcalls like OP wanted, yes?
  • Farfarer
  • Mant1k0re
    Offline / Send Message
    Mant1k0re polycounter lvl 8
    Thanks, that explains a lot... Oh well, more UV space for the mesh globally then :)
  • Eric Chadwick
    Well, actually you can use 1 material for the whole thing.

    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
  • Farfarer
    You can reorder the verts, but that generally only works from a certain side.
    Although, as long as you know that it's only going to be seen from that angle then yeah, it'll work.
  • Eric Chadwick
    I've done it for foliage seen from multiple angles. The backfaces need to be ordered too, can't rely on a 2-sided shader (which is usually a bad choice anyway).

    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.
  • echofourpapa
    Offline / Send Message
    echofourpapa polycounter lvl 4
    I've had some decent luck with custom shaders with different blend modes and no alpha test, but rendered before the transparency queue usually in the AlphaTest queue.

    I'm not sure if it's supposed to work as well as it does, but it works well in most cases.
Sign In or Register to comment.