Search Unity

Feedback 2D System Optimizations

Discussion in '2D Experimental Preview' started by Ferazel, Jan 8, 2020.

  1. Ferazel

    Ferazel

    Joined:
    Apr 18, 2010
    Posts:
    378
    I downloaded the Lost Crypt 2D demo and it looks really cool. Thank you! I'm glad that you're working on an integrated spine-esque animation system. Also that you've implemented a more robust toolchain for SpriteShape, Tilesets, and 2D lighting. All of these things are looking great, and will no doubt increase the visual fidelity of 2D projects. However, there is an aspects of the 2D system that is seemingly being ignored with these new features.

    PERFORMANCE

    The primary being fundamentally performance. 2D games are typically fill rate limited and the Lost Crypt demo project is full of problems in this regard. You need to recognize that fill rate is not free. Most consoles and mobile devices are fill-rate limited in the 2D space, yet there have been very few optimizations to help with this fact.

    One of the tools that people have used in the past SpriteSharp (https://assetstore.unity.com/packages/tools/sprite-management/spritesharp-mesh-optimizer-37599). The problem is that it appears that SpriteSharp's dev has disappeared (as is the problem with most 3rd-party assets) and Unity doesn't have anything comparable to the feature set that we could utilize.

    Some things I'd like to see focused on ASAP in the 2D toolchain:
    1. Tight mesh optimization. This has been a problem since the 2D stuff was introduced in Unity 4.2 and I don't think it's been improved since its release. This is a great tool to cut down on fill rate by increasing the vert count on sprites. The problem is that the mesh generation that happens automatically is extremely inefficient. Sometimes missing the most ideal mesh by hundreds of verts/polys. Sure throwing a few hundred verts extra into the tight mesh here or there may not sound like a big deal, but it adds up quickly. Please optimize your tight mesh algorithm to be more like the SpriteSharp's. There is no reason why I don't see why this couldn't be done.
    2. Opaque rendering. As you know, everything that is transparent is blended and it hurts fill rate tremendously having huge overlapping sprites that have multiple foreground and backgrounds of overlapping sprites. There is a solution to this, and it is using the depth buffer to quickly clip pixels that have a pixel in a foreground layer. I recognize with 2D lighting this is tricky, but we need to be able to do an opaque pass on all of the rendering layers in 2D so that we can spend GPU time on the things that actually need transparent blending.
      1. Sorry to keep harping on this, but SpriteSharp again has tools to assist with this. The biggest one is to allow us to split the sprite into opaque and transparent sprite meshes. With this being built-into Unity's Sprites that would be great, but even if we had to use 2 sprite renderers that is fine too.
      2. Add opaque support to the SpriteLit master node in shader graph in addition to doing an opaque pass on the renderer to depth test pixels.
      3. Allow sprite shapes and tilemaps to take advantage of opaque rendering to improve performance on the fill sprite.
      4. Add support for the renderer to render opaque sprites first to cut down on the transparent blending.
    3. Improved SkinnedSprite performance. This has already been brought up in the 2D animation forum, but I want to stress it here that the current performance is horrible. Even in the lost crypt demo with Burst installed, I'm seeing the sprite shape consume a huge amount of CPU time per frame by a factor 50% of the CPU frame time with only the character being the only sprite skin!
    4. GPU Instancing for Tilemaps. With tight meshes being used, obviously this creates a problem with GPU instancing as an option, but that doesn't mean that tilemaps can't benefit greatly from the feature and yet I'm not seeing support for this?
    Anyways, I do really appreciate everyone's hard work on the 2D system. I think the feature set is great, but I struggle to really be willing to use the features without some massive considerations to performance of the entire 2D toolchain. I want to stress again that Unity is trying desperately to get performance by default, but the 2D toolchain doesn't seem to reflect that.

    Are these performance improvements being considered? Is there time on the roadmap to implement performance improvements? Is there anything that the community can do to try to bump up the priority of this work?
     
  2. rustum

    rustum

    Unity Technologies

    Joined:
    Feb 14, 2015
    Posts:
    69
    Hi @Ferazel! Thank you for your detailed feedback. Allow me to reassure you that all of these are being considered, specifically items 1, 2 and 3. Item 4 isn't something we're actively working on, but we'll put it on our list of ideas with potential. The suite of 2D tools in Unity has been focused on functionality previously and we are now turning our attention to improved performance and better workflows!
     
    oakus and Ferazel like this.
  3. Ferazel

    Ferazel

    Joined:
    Apr 18, 2010
    Posts:
    378
    It is great to hear that the team can focus on improvements now that many of the core feature set has shipped. I think there are a ton of opportunities to improve the workflows for 2D including manual mesh generation (when the auto-gen isn't quite optimal), fast/efficient runtime atlasing, and the other optimizations mentioned above.

    Thanks!
     
unityunity