渲染时处理多次通过 [英] handle multiple passes when rendering

查看:48
本文介绍了渲染时处理多次通过的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要渲染一个体积 (VERSION combined with programmable pipeline and fixed pipeline) 仅使用使用glsl的可编程管线(无固定管线).为此,我需要多次通过渲染器,这意味着需要按顺序使用不同的着色器渲染不同的场景. 我想到了three methods

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. 使用一个着色器程序并分离着色器->附加着色器->每当渲染新场景时重新编译程序.
  2. 每遍使用一个着色器程序,然后退出多个着色器程序.
  3. 在渲染不同的遍时使用glsl中的子例程来选择不同的子例程.

我想知道什么时候应该使用第一种方法? 2ed方法?等等.有经验的开发人员可以提供帮助吗?

I wonder when should I use the 1st method? 2ed method? etc. can any experienced developer help?

推荐答案

许多问题无需多次通过即可解决.只是尝试使一种没有它们的技术成为可能. 如果没有其他效果,请使用方法3.

Many problems can be solved without multiple passes. Just try to make a technique without them. If nothing else works use method 3.

我对此的想法:

  • 方法1非常慢且无法使用.
  • 方法2的工作量很大,但如果 做得好,这是快速".
  • 方法3既简单又优雅,但有一个 额外的处理开销.您可以多次渲染对象,然后将当前的通过编号传递给着色器.
  • 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.

方法3的示例:

uniform int currentPass;

/* OTHER UNIFORMS */

void main()
{
    if(currentPass == 1)
    {
         /* DO SOMETHING */
    }
    else if(currentPass == 2)
    {
         /* DO SOMETHING */
    }
    else if(...) { ... }
}

在我看来,最好的方法是仅使用很少的着色器(也许是一个材质着色器,一个后期处理着色器等),因此您的方法3几乎是完美的.

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.

是否曾经考虑过超级着色器?它们就像您的方法3.谷歌" :) 我也建议此问题.

Ever thought about uber-shaders? They are something "like" your method 3. Google it :) I recommend also this question.

也要小心,if语句可能会大大削弱您的性能.

这篇关于渲染时处理多次通过的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆