Search Unity

Sorting of submeshes

Discussion in 'Scripting' started by devel, Jul 22, 2010.

  1. devel

    devel

    Joined:
    Mar 11, 2009
    Posts:
    140
    I have several meshes, some of them being opaque and some of them having transparent materials.

    The rendering order is fine, the transparent parts are drawn in the right order and it looks just as it should.

    Though, when combining the meshes (using Unitys Mesh Combiner), the rendering order gets screwed.

    Does Unity not sort the submeshes within a combined mesh?
    If it does, whats the decision based on whether a submesh should be drawn first?
    Is there any way to manipulate the rendering order of only the submeshes? I.ex. by passing the meshes or materials in a different order to the Combine function?

    I dont want to change the rendering queue of the shader since this would lead to wrong effects together with other objects.

    thanks for any hints.
     
  2. tomvds

    tomvds

    Joined:
    Oct 10, 2008
    Posts:
    1,028
    Objects with a transparent shader are placed in the Transparent rendering queue. Within this queue objects are sorted back-to-front using their distance to the player. This sorting works well for as long as:
    - The transparent objects never intersect.
    - No transparent object that is concave, has parts that are behind as well as parts in front of another transparent object (mathematically speaking: the transparent objects never intersect each others convex hull). In fact, concave meshes will probably already have sorting issues within it's own mesh.

    Mesh combining will combine objects with the same material into a single mesh (it doesn't use sub-meshes, as sub-meshes cause extra drawcalls, which would make the combine pointless). As soon as this is applied to transparent objects, the combined transparent mesh is virtually guaranteed to break the second requirement.

    The only solution is to not mesh combine transparent objects.
     
  3. devel

    devel

    Joined:
    Mar 11, 2009
    Posts:
    140
    Ok, so I know what to do :).

    Thanks for clarifying this to me!