Search Unity

Mobile Transparent Sprite Performance

Discussion in '2D' started by Marrt, Jun 18, 2015.

  1. Marrt

    Marrt

    Joined:
    Feb 7, 2012
    Posts:
    613
    Short: What's the best way to do Sprites that only have opaque pixels, full transparent pixels (0% alpha) BUT no semitransparent pixels?

    Long:
    I tried to educate myself on how to do sprites efficiently on Mobile. What i found out so far is that the main performance killers are

    -Drawcalls (this taught me about batching, atlas, packing tags and how sorting order may break batching)
    -Number of pixels you draw (increases dramatically with the use of transparent shaders, capped by FillRate)

    So after stumbling across a lot of threads from 2011 (http://forum.unity3d.com/threads/wh...ch-an-issue-on-mobile-dev.109463/#post-725378) i wanted to know if there is anything new to consider now

    Use case: A number of my tile-sprites generate mostly quads with 90% transparent pixels. I could match the geometry more closely to cut out most of the transparent pixels but how would this work with animated Sprites like characters?

    I dynamically generate my blocks with different borders and transition-line-tiles that have a lot of transparent pixels but not semitransparent pixels. This really kills performance as most of them seem to have a lot of transparent rendering going on - if i read the profiler correctly. This is my Block-Template (scaled up by 3) and a use case to see how they are combined and drawn:

    Tiletemplatex3.png
     
    Last edited: Jun 18, 2015
  2. Kuan

    Kuan

    Unity Technologies

    Joined:
    Jul 2, 2014
    Posts:
    87
    SpriteRenderer should generate a sprite mesh automatically and thus cutting off most of the transparent pixels. You can verify this by changing the shading mode in the scene view to "wireframe" or "shaded wireframe".
     
    theforgot3n1 likes this.
  3. Marrt

    Marrt

    Joined:
    Feb 7, 2012
    Posts:
    613
    Thanks for helping me again Kuan! I already checked the wireframe and it seems that my sprites are always getting a quad as mesh, except some stuff like arrow triangles, see picture:
    upload_2015-6-22_16-51-17.png

    The arrows in the pic use a 200 "PixelsPerUnit"-setting while the rest is at 16PxPU.

    Here are the things i do:
    -nearly all game Textures (at least all on the picture) are set to compressed with "game" as packing tag
    -they get packed into 2 atlases, depending on if they have alpha
    upload_2015-6-22_16-55-56.png upload_2015-6-22_17-1-58.png
    -Character has a SpriteRenderer & Animator
    -Blocks have empty GameObjects that get their SpriteRenderer & Sprite only at Runtime

    Anything that breaks tight Spritemeshing? How does PackerPolicy impact on that, it doesn't change anything for me after setting it to tight and repacking.
     
  4. ChuanXin

    ChuanXin

    Unity Technologies

    Joined:
    Apr 7, 2015
    Posts:
    1,068
    For your textures with quad meshes, you could try checking if the mesh type is set to Tight or Full Rect. You could do this by:
    • Selecting the texture
    • In the inspector, set the Texture Type to Advanced
    • Check Mesh Type under Sprite Mode and see if it set to Tight.
     
    theforgot3n1 likes this.
  5. Marrt

    Marrt

    Joined:
    Feb 7, 2012
    Posts:
    613
  6. ChuanXin

    ChuanXin

    Unity Technologies

    Joined:
    Apr 7, 2015
    Posts:
    1,068
    Based on your project, the mesh defaults to Full Rect as the tiles are too small (16x16). Tight mesh type requires the sprite to be at least 32x32 in dimensions.

    Is your character size similar in height and width to the tiles in your test build?
     
    Marrt likes this.
  7. Marrt

    Marrt

    Joined:
    Feb 7, 2012
    Posts:
    613
    Yes, everything very tiny and pixelated 16x16, 16x32

    I guess i have to check if spritesharp can deal with those resolutions, thank you for your help!