如何在延迟着色中从光几何体的内部绘制

时间:2013-01-19 09:52:06

标签: c++ opengl glsl

我正在尝试使用OpenGL和GLSL实现延迟着色器,我遇到了光几何问题。这些是我正在采取的步骤:

Bind multitarget framebuffer
Render color, position, normal and depth
Unbind framebuffer
Enable blend
Disable depth testing
Render every light
Enable depth testing
Disable blend
Render to screen

但是因为我只是渲染正面,所以当我在光线内时它完全消失,渲染背面不起作用,因为我会获得双倍的光能力(而且当内部,一半[或者正常金额])。

如何从灯光几何体的内部和外部渲染相同的光源值?

2 个答案:

答案 0 :(得分:3)

在我的情况下,我这样做:

Bind gbuffer framebuffer
Render color, position, normal
Unbind framebuffer

Enable blend
Enable depth testing

glDepthMask(0);
glCullFace(GL_FRONT);   //to render only backfaces
glDepthFunc(GL_GEQUAL); //to test if light fragment is "behind geometry", or it shouldn't affect it
Bind light framebuffer
Blit depth from gbuffer to light framebuffer //so you can depth-test light volumes against geometry
Render every light

答案 1 :(得分:2)

如果我没记错的话,在我的延迟渲染器中,我只渲染光量的背面。 缺点是你不能进行深度测试,你只会知道光完成后光线是否在几何体后面并丢弃像素。 正如另一个答案所解释的,您可以进行深度测试。测试大于或等于观察背面是否在几何体后面,因此与几何体的表面相交。

或者,您可以在渲染时检查光量是否在光量范围内并相应地切换前面。