问题
I want to render a volume(VERSION combined with programmable pipeline and fixed pipeline) using only programmable pipeline (no fixed pipeline) which using glsl. To achieve this, I need multipass the renderer which means render different scene with different shaders in a sequential order.
There are three methods come to my mind:
- using one shader program and detach shader -> attach shader -> recompile program whenever rendering new scene.
- using one shader program per pass, then there exits multiple shader programs.
- using subroutines in glsl to choose different subroutines when render different pass.
I wonder when should I use the 1st method? 2ed method? etc. can any experienced developer help?
回答1:
Many problems can be solved without multiple passes. Just try to make a technique without them. If nothing else works use method 3.
My thoughts about this:
- Method 1 is very slow and unuseable.
- Method 2 is much work but if done well it is "fast".
- Method 3 is easy and elegant but has a additional processing overhead. You may render your object several times and pass your current pass number to your shader.
Example for method 3:
uniform int currentPass;
/* OTHER UNIFORMS */
void main()
{
if(currentPass == 1)
{
/* DO SOMETHING */
}
else if(currentPass == 2)
{
/* DO SOMETHING */
}
else if(...) { ... }
}
On my mind the best approach is to use only very few shaders (maybe one material shader, one post processing shader, etc.), so your method 3 is nearly perfect.
Ever thought about uber-shaders? They are something "like" your method 3. Google it :) I recommend also this question.
Also be careful, the if-statements may weaken your performance very much.
来源:https://stackoverflow.com/questions/10597385/handle-multiple-passes-when-rendering