Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Creating overlapping meshes with a single transparency.

Discussion in 'Shaders' started by janimator, Dec 8, 2014.

  1. janimator

    janimator

    Joined:
    Apr 5, 2013
    Posts:
    52
    I have a single mesh composed of two or more overlapping planes. When I add transparency to the mesh the overlapping area are added together (image on the left) which is what I'm trying to avoid. The final result im trying to achieve is that the transparency will effect the mesh as a whole and the whole object with have a unified transparency(image on the left). Any ideas on how this can be done?
     
  2. brianasu

    brianasu

    Joined:
    Mar 9, 2010
    Posts:
    369
    You can try using BlendOp Max or Min not sure how it will work with other object blended with it
     
  3. janimator

    janimator

    Joined:
    Apr 5, 2013
    Posts:
    52
    Ill look into that. I guess I should mention that the planes on the mesh are textured, and the textures can be composed of various colors and transparencies. Rgba32 typically.
     
  4. brianasu

    brianasu

    Joined:
    Mar 9, 2010
    Posts:
    369
    Can you use worldspace UV ? You might have some z-fighting but it might help blend them.
     
  5. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    You may take Unity's transparent shader and create a variant of it that writes to the z buffer. Like that only one of them is going to be drawn.
     
  6. janimator

    janimator

    Joined:
    Apr 5, 2013
    Posts:
    52
    I think creating a z-buffer shader might be what I'm looking for. I'm new to shaders, especially in unity, so sorry if my shader vocabulary might be off. Google'ing "unity z-buffer shader" brought up this article which seems to be what im looking for.
    http://docs.unity3d.com/Manual/SL-CullAndDepth.html
    There's an image in there that shows a robot that has the issue I'm describing.

    What should i google'ing to figure out the process to create a shader that would achieve what im looking for?
     
    Last edited: Dec 8, 2014
  7. Flailer

    Flailer

    Joined:
    Apr 1, 2014
    Posts:
    66
    The problem occurs when you have more than one mesh though, if you want any kind of soft edge, such leaves overlapping the unfortunate side effect is this additive effect, and if you zwrite then you get the hard egdes of the mesh as well. What you can do tho, it use an alpha cut out shader with a stencil buffer then add in soft egdes, this should minimise the effect whilst giving you something you might desire.
     
  8. janimator

    janimator

    Joined:
    Apr 5, 2013
    Posts:
    52
    Thanks Stencil buffer is not something i knew about or considered. it looks promising. Is it a heavy operation?
     
  9. Flailer

    Flailer

    Joined:
    Apr 1, 2014
    Posts:
    66
    Not really no, obviously has a cost to it, like anything, but it's barely noticeable on mobile devices across a fair few meshes, so I presume it's fine to use quite extensively.