MonoGame.StaticBatch - could be useful to some of you guys :)

Hi all,

I wrote a lib that takes a lot of static sprites and merge them into a grid of render targets, then draw only the visible textures using a simple grid-based culling.

Hereโ€™s a screenshot to illustrate what I mean:

In the pic above instead of drawing all those skeletons, trees and tiles separately, they were merged into a grid of textures (marked with white lines) during initialization, so now we only need to draw 9 textures to show them all. It reduced ~1500 draw calls to 9.

For more info / get the lib:

https://github.com/RonenNess/MonoGame.StaticBatch

From a test scene I made with +180K sprites, I got the following results:

  1. Using static batch: 6400 FPS.
  2. Drawing everything: 9 FPS.
  3. Drawing only visible sprites (bounding-box culling): 300 FPS.

I think its pretty nice :slight_smile:
But ofc the price is in RAM, the bigger your scene the more textures it creates, so watch out for that.

Have fun, and let me know if you have any questions.

8 Likes

Good job :slight_smile: