handle multiple passes when rendering

独自空忆成欢 提交于 2019-12-08 05:17:27

问题


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:

  1. using one shader program and detach shader -> attach shader -> recompile program whenever rendering new scene.
  2. using one shader program per pass, then there exits multiple shader programs.
  3. 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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!