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

Mesh generating issue with transparent material.

Discussion in 'Editor & General Support' started by xxxMegaxelaxxx, Jan 25, 2015.

  1. xxxMegaxelaxxx

    xxxMegaxelaxxx

    Joined:
    Feb 9, 2013
    Posts:
    8
    Hello. I am trying to practice with voxels and faced with strange problem with transparent material. When I am generating a mesh I am getting this result (photos from different angles, and I didnt generate top and bottom faces). Back faces are overlapping front. P.S. Sorry for my english, I tried to explain my problem fully.
    upload_2015-1-26_0-32-43.png upload_2015-1-26_0-32-56.png
     
    Last edited: Jan 25, 2015
  2. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    When you create a transparent mesh, you have to consider that Unity draws the triangles in the order you are passing them. That means you have to sort the faces to get the correct result, such that the more distant faces are drawn before the closer ones.
     
  3. xxxMegaxelaxxx

    xxxMegaxelaxxx

    Joined:
    Feb 9, 2013
    Posts:
    8
    Ok, how must am I to sort em? I can look at mesh from different sizes.
     
  4. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    You may e.g. calculate the distance of each triangle to the camera and then sort the triangles accordingly.

    It most likely requires quite some work on your code to make that good.
     
  5. xxxMegaxelaxxx

    xxxMegaxelaxxx

    Joined:
    Feb 9, 2013
    Posts:
    8
    So i havew to recalc mesh every iteration?
     
  6. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    Theoretically yes. Practically, I am sure there is one or the other optimization that can be used.
     
  7. xxxMegaxelaxxx

    xxxMegaxelaxxx

    Joined:
    Feb 9, 2013
    Posts:
    8
    Ye, I believe, that I will find it. Thank you for replies.
     
  8. xxxMegaxelaxxx

    xxxMegaxelaxxx

    Joined:
    Feb 9, 2013
    Posts:
    8
    Hey, you know, i changed "Transparent/Diffuse" shader to "Transparent/Cutout/Diffuse" and probleb disappeared.
     
  9. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    You were only writing about the transparent shader. The transparent shader doesn't write to the depth buffer and that causes the issue you were experiencing. The cutout shader on the other hand does write to the depth buffer which means the triangle sorting doesn't need to be made.
     
    Last edited: Jan 26, 2015
  10. xxxMegaxelaxxx

    xxxMegaxelaxxx

    Joined:
    Feb 9, 2013
    Posts:
    8
    Ok, I'll take this note.