Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

How to render thousands of sprites in set order

Discussion in 'Shaders' started by betonos, Aug 10, 2012.

  1. betonos

    betonos

    Joined:
    Apr 2, 2012
    Posts:
    12
    Hi,

    I have 2D sprites on my screen and want them to render in set order. I am using ortho camera, but I'd really prefer to keep the sprites on the same Z for many reasons.

    So, I've tried using RenderQueue, but:

    1) I have really lot of sprites to handle (thousands of)
    2) renderqueue value has to bee positive integer
    3) default renderqueues are set in the range up to 4000 (Background is 1000, Geometry is 2000, AlphaTest is 2450, Transparent is 3000 and Overlay is 4000)
    4) many external scripts I use (NGUI, tk2d) rely on default materials, that base on default renderqueues
    5) so I end up having to fit my sprites somewhere for example between 1000 and 2450 and this is simply not enough for me, I need much more values available

    Any idea how to solve the problem without moving the sprites on Z?

    The solutions I've thought of:
    1) Write custom properties on objects that custom shaders use to set custom rendering priority within this group of sprites - but I believe this is a complicated thing to do and I am afraid of the rendering performance adding another sorting shader.
    2) Changing the default Unity values for the rendering queuqes (Background is 1000, Geometry is 2000, AlphaTest is 2450, Transparent is 3000 and Overlay is 4000) - but I don't know if it is possible or if this is a const within Unity?
     
  2. betonos

    betonos

    Joined:
    Apr 2, 2012
    Posts:
    12
    No, no, no overdraw planned. Imagine this: imagine you are writing a graphics editor and you need the functionality of "move forward", "move backward" etc. You can have literally 1000s of objects on screen, little overdraw, but you still need to have total control over what is behind what.

    So far I've somewhat solved the problem: solution to problem no. 4) was to overwrite the renderQueue using LateUpdate, therefore not caring what NGUI or tk2d does earlier to the materials.
     
  3. Martin-Kraus

    Martin-Kraus

    Joined:
    Feb 18, 2011
    Posts:
    617
    Please specify your reasons.
     
  4. aubergine

    aubergine

    Joined:
    Sep 12, 2009
    Posts:
    2,878
    I just wondered in what situation you will have to render thousands of seperate objects on screen which also need accurate sorting?
     
  5. Martin-Kraus

    Martin-Kraus

    Joined:
    Feb 18, 2011
    Posts:
    617
    Partly transparent sprites representing a large crowd of characters if you want to avoid alpha test and discard for performance reasons (?)