I'm developing a little 2D game using OpenGL 4.x and I've also coded a very simple light system which does not take care of shadows. The main concept behind this light system is the frambuffer multiplicative blending. I basically have two framebuffers, one for the normal scene render and the other one for ambient light and the scene light sources. Then, I blend those two framebuffers and I get my final result (which is pretty good, to be honest).
In this model I have 3 different shader programs:
- One for rendering the normal scene (with texturing and other normal features)
- One for rendering lights, which compute light halos and other light effects
- One for blending the two framebuffers together
Now, in my main application loop I have to switch between those three shader programs in order to complete a full rendering cycle. I'm also planning to add more shaders to render different light effects and particles. At the moment I'm in the design phase of my game, so I'm not able to test out the performance of this approach and I have no previous experience with it. And for the same reason I'd like to start with the best approach possibile for this situation.
So my question is: considering your experience, is switching between several shader programs at each frame something good or is it a bad behaviour in a 2D enviroment ? Is using fewer shader programs but with more if
statement and more unused uniform variables a better solution?