I’m having trouble looking for information in this topic, when it’s more efficient to simply switch programs instead of having a large and complicated shader?
Someone told me that even a simple IF statement might be a reason to precalculate that condition and choose programs accordingly.
Any help with this or any “good practices in GLSL-ES” book/tutorial I can read?
It almost depends of what you are meaning.
Branching in a shader program affect performances in GPU terms: if your vertex arrays are very long, I would avoid branching; instead use preprocessor and link multiple different programs.
Having a single-complex-huge shader program boost performance in CPU terms: each glUseProgram takes time, and you may want to call it only once (al least less).
Are the CPU advantages greater than the GPU advantages? Answering to this question answer your question.
…
Personally I go with preprocessor and I avoid branching for fundamental purposes. Each shader program has well-defined interfaces, and different objects implements them; attaching different objects complete the program implementation.
Implementing a #include directive helps a lot. Common declarations are included in different objects, and only statically accessed attributes and uniforms are effectively linked into the program.
This is an example of a shader program of mine: