Search code examples
openglrendering-engine

Front to back rendering vs shaders swapping


Lets consider such situation. The scene contains given objects: ABCDE

Where order from camera (from nearest to farthest) AEBDC

And objects AC use shader1,ED shader 2,B shader3

Objects AC use shame shader but different texture.

Now what to deal with such situation?

  • Render everything from front to back (5 swaps)
  • Render by shader group which are sorted(3 shaders swaps).
  • Marge all shader programs to one(1 swap).

Does instructions like glUniform,glBindTexture etc. to change value in already in use program cause overhead?


Solution

  • There is no one answer to this question. Does changing OpenGL state "cause overhead"? Of course they do; nothing is free. The question is whether the overhead caused by state change will be worse than the less effective depth test support.

    That cannot be answered, because the answer depends on how much overdraw there is, how costly your fragment shaders are, how many state changes a particular sequence of draw calls will require, and numerous other intangibles that cannot be known beforehand.

    That's why profiling before optimization is important.