【问题标题】:OpenGL shading pipeline efficiency with FBOs使用 FBO 的 OpenGL 着色管道效率
【发布时间】:2016-01-24 19:18:27
【问题描述】:

我一直致力于实现延迟着色,因为我希望在我的场景中至少有 20 盏灯。我在使它足够快时遇到了问题(现在仍然如此),但后来我做了一个我认为会使其变慢的更改,但实际上几乎是我的帧速率的两倍。

初始代码:

geometryPassFBO = createFBO(); // position texture, normal texture, colour texture and depth buffer
while (1)
{
    bind geometryPassFBO.
    allObjects.draw();

    bind systemFBO();
    for each light
        send light info
        draw light sphere sampling from position, normal and colour textures.

    blit depth buffer from geometryFBO to systemFBO

    for each light
        light.draw(); // draw a cube to represent the light

    2DObjects.draw(); // frame rate, etc...
}

我正在设置一个模板测试,如果在几何过程中设置了像素(即背景正常 = 0,0,0 和位置 = 0,0,0 和颜色 = 0,0,0。

但是,我在将组合的深度/模板缓冲区复制到默认深度/模板缓冲区时遇到了困难。显然这不是很好,因为我们不知道系统深度/模板缓冲区采用什么格式。所以我读到最好设置另一个 FBO,我们可以在其中指定深度/模板缓冲区格式,渲染为此,然后 blit 或渲染屏幕四边形以将其输出到屏幕。

因此,在添加任何模板材料之前,我只是添加了新的 FBO 以使该部分正常工作。

我的新代码现在看起来像:

geometryPassFBO = createGeometryFBO(); // position texture, normal texture, colour texture and depth buffer
lightingPassFBO = createLightingFBO(); // colour texture and depth buffer
while (1)
{
    bind geometryPassFBO.
    allObjects.draw();

    bind lightingPassFBO();
    for each light
        send light info
        draw light sphere sampling from position, normal and colour textures.

    blit depth buffer from geometryFBO to lightingPassFBO

    for each light
        light.draw(); // draw a cube to represent the light

    2DObjects.draw(); // frame rate, etc...

    bind systemFBO;
    render screen quad sampling from colour texture.
}

这按预期工作。出乎意料的是,我的帧率从 25 FPS 跃升至 45 FPS。

这是为什么?必须为屏幕四边形执行额外的着色器通道如何比不执行更有效?

快速跟进问题。使用简单的顶点和片段着色器根据 gl_FragCoord 对纹理进行采样,或将颜色附件直接传送到系统 FBO,哪个更有效地渲染屏幕四边形?

【问题讨论】:

    标签: c++ opengl fbo deferred-rendering deferred-shading


    【解决方案1】:

    嗯,大概是这样的:

    从geometryFBO到lightingPassFBO的blit深度缓冲区

    正如您所指出的,格式转换可能很慢。但是由于您为此 blit 操作定义了输入和输出缓冲区,它们可能使用相同的深度格式。因此,blitting 操作可能会进行得更快。

    另外,你可能根本不应该这样做。在渲染光立方之前,只需将geometryFBO 的深度/模板缓冲区附加到lightingPassFBO。请记住在渲染灯光后移除附件(否则您的延迟通道将具有未定义的行为,假设您正在从延迟通道中的深度缓冲区读取数据)。

    至于您关于 blitting 与全屏四边形的问题,我有一个更好的问题:为什么您要在一个场景中累积 20 多个灯光,而不使用高动态范围照明?因为渲染到屏幕的最后一遍也应该使用色调映射将您的 HDR 图像转换为 LDR 以供显示。

    但至于确切的问题,blit 操作应该不会比 FSQ 慢,假设没有进行格式转换。如果发生格式转换,那么将内容带到顶点着色器可能会更有效。

    【讨论】:

    • 谢谢,这是有道理的。我将研究交换深度缓冲区的附件。在回答你的问题时,我没有做 HDR,因为我还没有做。在提高性能后,它是我列表中的下一个。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多