Today, I would like to speak about an optimization that I made. Here is the problem:
I put something like one thousand tori in my scene. Even if I do all lighting computions at the final step, the rendering still cost a lot of time just to render the "geometry". Here you can see that I'm at something like 10 frames per second.
So, how can we improve that ?
The first solution that probably come to mind is to use VBO. However, I don't think it's good with my pipeline since I need to render 4 different sprites for each entity (for the 4 passes/buffers). But then I thought: most of the scene geometry does not need to be rendered at each frame (we already do the shading in deferred), most objects do not move.
Hence I came with the idea to separate all entities in two sets: the static ones and the dynamic ones. Also, it's not because a "static entity" moves somewhere on the screen that I need to recompute the all scene. Thus I decided to split my screen into multiple tiles, and whenever I tile need to be rerendered, I do it. So that's nice, now I can render my scene again, with all the tori. As expected I run at 60 to 70 frames per second, like without any of them.
However, this means that if I move the camera, I still need to rerender the whole scene ! Which is really bad because it would make everything laggy. But hey, since we are rendering the static geometry in a separate buffer, I can just take a buffer a little bit bigger, and then move it with the camera (I basically just added 1 more tile in width and height). Whenever I reach the boundary, I can just blit (copy) my buffer on itself, one tile in the direction of the camera (really you need to swap between two differents buffers), and update the missing part. With this and my 1000 tori, I have a pretty smooth camera movement, with only one frame that takes a bit more of time to render (equivalent to ~20 FPS in this case).
This will allow me to render very complex scenes without having to worry about the number of draw calls. I hope that this can be useful for anyone with the same kind of 2D engine working with a depthbuffer.
And as bonus, here is a nice screen of the SSR:
free image hosting