如何在延迟阴影中从光线几何的内部绘制

How to draw from the inside of the light geometry in deferred shading

本文关键字:内部 绘制 延迟 阴影      更新时间:2023-10-16

我试图用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

但是因为我只渲染正面,当我在灯光里面的时候,它完全消失了,渲染背面不起作用,因为我将得到两倍的光功率(当我在里面的时候,一半[或正常量])。

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

在我的例子中,我是这样做的:

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

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

或者你可以在渲染时检查你是否在灯光体积内,并相应地切换正面