   Batching semi-transparent sprites
  I am working on 2d game, build up from semi-transparent textured quads sprites). The game is rendered as a 3d scene where all the quads simply face the camera. The quads are positioned in different z depths to provide a parallaxing effect. All quads are additionally dynamic, i.e. move around at runtime in both x-y-z.Currently, each sprite makes an individual render call, which has shown to become the dominating CPU bottleneck of the application (1000+ render calls per frame). To solve this I need to apply batching, but that has turned out to be rather difficult as semi-transparent quads require depth-sorting in order to be rendered correctly.To make things even harder, the individual quads currently define different render states, such as different blend modes (or shaders).I am trying to figure out a good way to batch these textured quads, supporting correct sorted rendering, variable z-depth, and different render states. So far I have come up  with:* I need to minimize the number of render states whenever possible, including using a texture atlas containing all textures. Different color effects should for example be calculated on CPU, and put into each vertex when possible.* A simple algorithm for batching could be as follows:- Sort all quads back to front.- Create a batch for the quad furthes away from the camera, and keep adding the quads in back to front order until a new render state is met.- When a new render state is met, create a new batch and start adding quads again- When all quads have been added to batches, the batches are already sorted and can be rendered back to front for correct results.* The above algorithm is not very flexible, and when building a level I should be very careful when adding in objects with speciel render states, as they can seriously mess up the batching.Am I missing a better solution?Any thoughts are welcome.   
  What other render-states (aside from textures) are changing between your different sprites?   ;  Currently only blend mode. But the possibility of allowing different shaders to be used on different objects might be nice later on.   ;  You have a good solution, using a texture atlas will definitely help you to batch your sprites. I will also use always the same shader (their is a few chances for the shaders to be the bottleneck, in your case). Using the same shader will help you to increase your batch size. And shader switch is the worst thing in 3D (after render target switch).   