Search Unity

Cutout transparency from alpha channel creating partly transparent models in-game

Discussion in 'Shaders' started by Everbrave, May 28, 2015.

  1. Everbrave

    Everbrave

    Joined:
    Nov 13, 2014
    Posts:
    23
    So I'm modeling some trees using planes for the leaves in Maya. In the Maya viewport I'm seeing the inside textures showing through the planes. I'm sure this is due to the drawing order or just a poor viewport renderer, or maybe there's an issue with using a Tif for an alpha cutout texture. But when I render the model comes out fine. So I assumed that with Unity 5's standard shader, this issue would also be solved when rendered in-game.

    But it's not.

    When switching to the legacy transparency shader it fixes the transparent model issue, but now light doesn't affect the model at all. This is definitely going to be a problem as well.

    I'm sure thousands of developers use alpha channels to cut transparency from geometry planes (trees in nearly every low to mid poly game), so I know there's something simple I'm missing. What shader should I be using, or is this an issue I can solve in Maya?

    Thanks in advance.
     
    Tetra likes this.
  2. AlexBM

    AlexBM

    Joined:
    Mar 26, 2015
    Posts:
    16
    Problems with transparent objects are very commonplace in OpenGL. Unfortunately, there is no universal way to solve them all at once, (actually, you may try to google Order Independent Transparency, but solely for education purposes)
    Each specific case requires its own trade-offs and approaches.
    It's not exactly clear what's going on in your case, but it's rather strange that your models doesn't look right even in Maya viewport, which is rendered on per-triangle basis. Make sure that your normals and polygon facings are OK.
    Also you can try to slice your tree to several different pieces, making for example trunk and branches be visible in Unity as separate objects, so it can sort it properly and not send entire tree mesh in one drawcall, However, again, it's not clear what's going on in your case. Screenshots might help to understand your problem better.
     
  3. UnityGuillaume

    UnityGuillaume

    Unity Technologies

    Joined:
    Mar 16, 2015
    Posts:
    123
    It's indeed pretty strange.

    Alpha CUTOUT will simply discard pixel that are under a given alpha limit. They are otherwise rendered as any opaque object, so lighting acts on them properly, and they can intersect, as each pixel is depth tested.

    Alpha TRANSPARENCY on the other end is rendered after everything, in back to front order, so they blend properly & don't have something far drawn above something close. But the problem is that if your translucent object have lots of parts (like if all the triangles of your leaves are one objects), then you will have a problem because the renderer can't order each triangles, it draw them in the (immutable) order they are define so can end up with a case such as :

    A leave from behind a closer leave could be drawn last, and "erase" the close one (the computer just do alphaDrawn*colorDrawn + colorPresent * (1 - alphaDrawn)...)


    So be sure you use the Cutout version of the shaders, not the transparent one. But yes please include screenshot, will help narrow the problem.
     
    anthony-pinskey likes this.
  4. Everbrave

    Everbrave

    Joined:
    Nov 13, 2014
    Posts:
    23
    Oh man. I was away for a couple weeks and then completely forgot I posted his here.

    The problem has been solved thanks to some double sided shaders I found on the Asset Store which had a cutout alpha option. And yes, UnityGuillaume, I was looking for alpha cutout, not transparency. The shaders I was originally using was layering the planes incorrectly. I was using planes, laid out in cone shapes to form the basic shapes of pine trees. Then I used alpha channels to cut jagged bottoms from the pixels near the bottoms of the cones.

    In case it helps someone else, I found that turning on the "depth peeling" option in my Maya viewport renderer options fixed the issue in Maya as well.

    All in all, the problem is all solved and our game is well on it's way. Thanks for the help guys. Sorry I didn't get back sooner to thank you.