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

Bug with order transparent submeshes in one mesh

Discussion in 'Editor & General Support' started by davhg, May 12, 2014.

  1. davhg

    davhg

    Joined:
    Apr 9, 2013
    Posts:
    9
    Hello

    I have one mesh with two sub meshes with two transparent materials: transparent balls at some distance from each other.
    I one view direction - render is correct, on other direction - render is not correct.

    Do sorted submeshes together?
     
  2. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    No, it is necessary to create two meshes.
     
  3. davhg

    davhg

    Joined:
    Apr 9, 2013
    Posts:
    9
    But now i reduce game objects in scene for speed up of loading.
     
  4. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    As you found out, that kind of batching only works for non-transparent objects. That kind of optimization simply doesn't work for transparent meshes. It would be necessary to sort the triangles in the code to get correct results and that is usually slower and even that has cases where you would find visual glitches, e.g. if triangles are overlapping.
     
  5. davhg

    davhg

    Joined:
    Apr 9, 2013
    Posts:
    9
    Batching working with all type of objects
     
  6. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    Batching does not work with transparent objects.
     
  7. davhg

    davhg

    Joined:
    Apr 9, 2013
    Posts:
    9
    In our project works fine, unity 4.3.4
     
  8. Metron

    Metron

    Joined:
    Aug 24, 2009
    Posts:
    1,137
    Obviously it does not... why? because batching doesn't take into account the depth sorting. It just throws in the meshes into one big mesh (mixing meshes and instancing)...

    When trying to batch transparent objects, it will not work because to get a correct transparency across all objects, you need to sort them back to front... which is an additional CPU consuming part...
     
  9. davhg

    davhg

    Joined:
    Apr 9, 2013
    Posts:
    9
    But it is working. Batching uses material and depth order.

    From unity document: "Semitransparent shaders most often require objects to be rendered in back-to-front order for transparency to work. Unity first orders objects in this order, and then tries to batch them - but because the order must be strictly satisfied, this often means less batching can be achieved than with opaque objects."

    https://docs.unity3d.com/Documentation/Manual/DrawCallBatching.html

    This issue - it is bug, because unity already uses part of mesh (sub meshes) for batching with other objects. But for sorting this transparent sub meshes, unity use only origin of main mesh. If unity store origin for all sub mesh - this issues will be fixed.
     
    Last edited: May 13, 2014
  10. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    Ah, I wasn't aware of that. Last time I checked it, it wasn't possible. The problem with your sub meshes is, that they both have the same origin. As such, Unity can't sort them. Just split them up into separate meshes.