Search Unity

Sprite sorting in 3D camera

Discussion in '2D' started by Mr-LeoSantos, Aug 18, 2014.

  1. Mr-LeoSantos

    Mr-LeoSantos

    Joined:
    Mar 6, 2013
    Posts:
    18
    I'm experimenting with creating 2D sprites in a 3D context ( perspective camera, backgrounds made out of 3d meshes. Something like "Disgaea", for instance ). While Unity's sprite system sorts flawlessly in a 2d view, I'm running into trouble when the sprites overlap a regular mesh ( with an "unlit" material ) or when the camera orbits around.

    Here's an example. I'm moving the kitty along the Z axis, and only values below a certain value are visible. Curiously, if I rotate the camera around 180 degrees, the result is reversed. This behavior is consistent in the scene view and in play mode. The tile map behind it is a regular mesh, not a sprite.



    Changing the camera angle changes the threshold when the sprite disappears. All sprites are set to "Default" sorting layer, since my goal is to use their actual 3d position.

    I wanted to check if this is just a bug or the way Unity's sprites are intended to behave.

    Thanks!
     
  2. Punchbag

    Punchbag

    Joined:
    Oct 30, 2012
    Posts:
    48
    I posted a reply to this once already, but it didn't seem to stick.

    If you move the cat back until it disappears, then move the camera forwards, does it reappear?

    If so, have you checked the Far Clipping Plane's distance on the camera? A short distance to the Far Clipping Plane would create these symptoms.
     
  3. Mr-LeoSantos

    Mr-LeoSantos

    Joined:
    Mar 6, 2013
    Posts:
    18
    It's definitely not the clipping plane, which is set to a sufficient value (you can see objects behind the cat). Also, sometimes orbiting around the sprite (which doesn't change the camera distance) seems to create the problem.
     
    Last edited: Aug 19, 2014
  4. Mr-LeoSantos

    Mr-LeoSantos

    Joined:
    Mar 6, 2013
    Posts:
    18
    I figured it out, I think!

    Turns out that the "Unlit" shader cause sprites that are in front of it to not sort properly. Same thing with the Sprite shader applied to a regular mesh (don't know why you'd want to do that anyway). Here's a test with the Unlit shader applied to a plane behind two sprites, and one with a standard Diffuse shader instead of the Unlit shader. The camera does the same movement in both:


    The Unlit shader has the wrong behavior, but not the Diffuse. Can someone explain why? Should I file a bug, or is that expected?

    ( EDIT: It seems that any transparent shader causes the issue. The only one that works is the Unlit/Transparent Cutout )

    Thanks!
     
    Last edited: Aug 19, 2014