Search Unity

Opaque sprites & default sprite shader render queue

Discussion in 'General Graphics' started by LiterallyJeff, Dec 16, 2019.

  1. LiterallyJeff

    LiterallyJeff

    Joined:
    Jan 21, 2015
    Posts:
    2,807
    Hello!

    I've been looking into optimizing shaders lately, and I feel that I'm missing some info with regards to Sprites.

    Say I have a square sprite that is fully opaque, and is rendering using the Sprites-Default shader which renders in the Transparent queue with Alpha Blending.

    It's my understanding that this queue renders back to front to support transparency, so doesn't that mean it will be overdrawing on all pixels?

    If that is true, I'm wondering why Unity doesn't provide a geometry queue cutout shader for sprites without semi-transparency for maximum optimization? Surely this is desired for mobile games, especially those with pixel graphics, and I don't see many people attempting to edit the default shader of their own volition.

    Thanks for any info about this.
     
    Last edited: Dec 16, 2019
  2. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,343
    Correct.

    This only matters if you also use a depth buffer and aren't rendering everything at the same Z. Otherwise it offers no benefit and is no different than rendering using an alpha blend as coplanar surfaces will still overdraw. Most simple 2D projects seem to work totally in 2D and rely on the render order exclusively, which would mean opaque sprites don't help.

    Plenty of people do, and there are several assets to help with this. But for most basic projects it probably doesn't matter a lot even on low end mobile.

    If it's something you care about, having good sprite meshes will probably save you way more overall than using opaque meshes most of the time. Otherwise you can use something like SpriteSharp which will both produce much better sprite meshes as well as has having an option to split sprites into opaque and transparent parts to reduce overdraw if you also take the time to deal with the z position of your sprites.
     
  3. LiterallyJeff

    LiterallyJeff

    Joined:
    Jan 21, 2015
    Posts:
    2,807
    Thanks for the detailed response!