Search Unity

To many 2d drawcall make the game slow

Discussion in '2D' started by Otomii Lu, Dec 2, 2014.

  1. Otomii Lu

    Otomii Lu

    Joined:
    Apr 17, 2014
    Posts:
    20
    To many 2d drawcall make the game slow

    I will have at lease 100000 2d sprite on the screen. When the camera big enough to see them, I find the game is so slow.
    For The 100000 sprites are also very small, but the drawcall is still big. and how can I do?

    I think the camera must render one single sprite to be just a pixel . but seems upset :(
     
  2. GarBenjamin

    GarBenjamin

    Joined:
    Dec 26, 2013
    Posts:
    7,441
    Do you really need 100,000 independently moving / animating objects?
     
  3. imaginaryhuman

    imaginaryhuman

    Joined:
    Mar 21, 2010
    Posts:
    5,834
    Well 100,000 is a lot of objects, no matter what. In order to get that to batch to, say, less than even 50 drawcalls, you'd need 2000 objects in each batch, which I think is unlikely to happen. Also not just the batching/drawcalls, but the sheer overhead of processing 100,000 objects.. dealing with all those transforms, generating the geometry, pushing it to the gpu etc... you might not notice it with 5000 objects but at 100,000 it adds up.

    Are all the sprites static ie they don't move, or are they like tiles in a grid, or are they all dynamic?
     
  4. Otomii Lu

    Otomii Lu

    Joined:
    Apr 17, 2014
    Posts:
    20
    Hi

    they have a parent root that will move and rotate

    They are tiles in grid, they are using unity native 2d sprite.

    When the scene really far , too many draw call
     
  5. Otomii Lu

    Otomii Lu

    Joined:
    Apr 17, 2014
    Posts:
    20
    More , The parent root will rotate around y axis in order to show another side 2d tile grid
     
  6. Otomii Lu

    Otomii Lu

    Joined:
    Apr 17, 2014
    Posts:
    20
    More , do there a way to put 2000 objects in each batch?and generating the geometry, pushing it to the gpu ?

    Any information will be really helpful to me . I was crazy to this problem
     
  7. imaginaryhuman

    imaginaryhuman

    Joined:
    Mar 21, 2010
    Posts:
    5,834
    Well Unity sprites already get batched and use a spritesheet. You do have one spritesheet texture that is shared by all of the tiles, right, not like 100 different textures?
     
  8. Otomii Lu

    Otomii Lu

    Joined:
    Apr 17, 2014
    Posts:
    20
    Yes just one
     
  9. Otomii Lu

    Otomii Lu

    Joined:
    Apr 17, 2014
    Posts:
    20
    Fell a little upset, still cannot solve the problem :(
     
  10. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    Use shuriken and set positions manually. This is pretty damn fast (not quite point sprite speed but good enough).
     
  11. Otomii Lu

    Otomii Lu

    Joined:
    Apr 17, 2014
    Posts:
    20
    Hi hippocoder, thx anyway

    More , I cannot catch the idea on how to set positions manually , any more information is god to me , sorry for noob.

    More, some of the tiles have collider2d , and the color of them are dynamic.
     
  12. nysochn

    nysochn

    Joined:
    Dec 3, 2014
    Posts:
    6
    i think you will prepare a big sprite that contain all of the sprites you want to show
     
  13. Otomii Lu

    Otomii Lu

    Joined:
    Apr 17, 2014
    Posts:
    20
    I will provide the player dynamic to destroy single part of the tile.
    If they are a big sprite, I cannot destroy it as part
     
  14. GarBenjamin

    GarBenjamin

    Joined:
    Dec 26, 2013
    Posts:
    7,441
    If it is 100,000 objects making up one huge object the individual objects must either be tiny or all not onscreen simultaneously.

    If tiny like a few pixels or less you could simply make larger objects. Say you represent whatever with 6,250 4x4 pixel objects instead of 100,000 1-pixel objects. The player destroys the 4x4 objects which breaks off and then you can shatter that piece down into 16 1-pixel bits.

    If the object is massive and not all on-screen then deactivating any objects that are off-screen should speed things up.
     
  15. imaginaryhuman

    imaginaryhuman

    Joined:
    Mar 21, 2010
    Posts:
    5,834
    But then what happens when he zooms out and all objects are showing?
     
  16. Otomii Lu

    Otomii Lu

    Joined:
    Apr 17, 2014
    Posts:
    20
    WOW ,hi imaginaryhuman , I found I have paid for your Gradient Shader Pack ,reaally good asset :)

    >But then what happens when he zooms out and all objects are showing?

    when I zoom out , more sprites go into the camera and be slower :(
     
  17. Otomii Lu

    Otomii Lu

    Joined:
    Apr 17, 2014
    Posts:
    20

    Thx GarBenjamin :), thx for your suggestion , your solution maybe the only solution ,I cannot control the camera how to render the sprite, can I? what I can do is only to combine , but It will need a lot of work for too many logic in on the 2d sprite :(
     
  18. GarBenjamin

    GarBenjamin

    Joined:
    Dec 26, 2013
    Posts:
    7,441
    I must have missed the bit about needing to zoom out. Really don't know what is being made. With it being sprites I figured it was 2D and there would be no zooming.
     
  19. Otomii Lu

    Otomii Lu

    Joined:
    Apr 17, 2014
    Posts:
    20
    I can zoom the camera and rotation the 2d object in the camera, the 2d object have six different faces with their own collider, single 2d object is one tile :(
     
  20. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
  21. Otomii Lu

    Otomii Lu

    Joined:
    Apr 17, 2014
    Posts:
    20
    Thx hippocoder indeed , I will try , THX again
     
  22. imaginaryhuman

    imaginaryhuman

    Joined:
    Mar 21, 2010
    Posts:
    5,834
    There is an even faster way to render thousands of `tiles`, but I'm thinking of putting it into an asset, so I guess I can't tell you. So I guess that makes this comment kind of useless, lol but it is possible to render hundreds of thousands of tiles at high frame rates.
     
  23. Otomii Lu

    Otomii Lu

    Joined:
    Apr 17, 2014
    Posts:
    20
    I will try to find some way to control the camera render. seems not much information
     
  24. imaginaryhuman

    imaginaryhuman

    Joined:
    Mar 21, 2010
    Posts:
    5,834
    Can you combine some of the sprites into a larger, single sprite?
     
  25. Otomii Lu

    Otomii Lu

    Joined:
    Apr 17, 2014
    Posts:
    20
    If I will combine, I must combine at runtime , because for every player , the tiles are different