Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice

Mixing Sprites and Meshes with Sorting Layers in Unity 5

Discussion in 'Unity 5 Pre-order Beta' started by InfiniteAmmo, Jan 28, 2015.

  1. InfiniteAmmo

    InfiniteAmmo

    Joined:
    Aug 12, 2008
    Posts:
    45
    Howdy.

    In Unity 4.x we used a little hacky script to get drop downs to make the "sorting layer" and "order in layer" parameters editable on MeshRenderers. By using a sprite shader on the mesh renderer, this enabled us to mix in meshes with our regular sprites.



    This is super useful for our game, because we have some giant background pieces that work way better as flat meshes.

    For example, in this shot the foreground buildings, steps, tunnel, pigeons etc are sprites, but the far bg buildings, hills are meshes.





    In 4.x we could also use a modified sprite shader to write to the ZBuffer to make effects like Sun Shafts work. Without depth information, the sun shafts go through the foreground buildings.

    So far in 5.x, we're running into problems with these methods.

    - our custom sprite cutout shader doesn't work anymore, i think this might have something to do with the different render queues? i've tried a number of things and can't seem to get sprites to zwrite. Instead, I'm trying to use the "standard" shader set to "cutout." This... sort of works in some scenes but not others?

    - on the artist's machine (he's on Windows, I'm on Mac) all the MeshRenderers seemed to forget their sorting layer, reverting to "Default." On my machine they were fine, but no amount of reverting files would restore the settings on his machine. I wrote a script to export/import all the MeshRenderer sorting layer data from all the scenes into xml. That seemed to "fix" it on his end, but it makes me worried that maybe those settings will get reset again?

    - the game seems to run incredibly slow inside the editor now that I've switched to Unity 5.x. Like unplayably slow. It seems like this slowdown is from rendering. If I make the game window really small, it runs fine. Scaling it up slows it down. The profiler seems to confirm that this is renderer based. We're using forward rendering, Gamma color space.

    IMO, Unity should support (encourage?) mixing meshes in with sprites using the sprite layering system. There's so much you can do with dynamic meshes, filling in large areas with flat meshes etc. I'd really love it if there was a less hacky way to do this! (maybe there already is and we just missed it?)
     
  2. InfiniteAmmo

    InfiniteAmmo

    Joined:
    Aug 12, 2008
    Posts:
    45
    Re: the performance problem: most of the slowdown seems to be from the 4.x antialiasing shader we're still using. Switching to the new 5.x one doesn't seem to help performance. DIsabling it entirely does though. Even with this off, the game seems to stutter a lot in the editor, whereas in 4.x it was running very smoothly even with antialiasing on.