【发布时间】:2016-08-15 10:24:27
【问题描述】:
我知道从/向相同的纹理/位置读取/写入是一个非常糟糕的主意,因为这会导致未定义的行为。 但就我而言,如果禁用了深度测试并且我在着色器中读取了深度值,是否可以在读取同一纹理中的深度值的同时进行模板测试?
在我看来应该没有任何问题,因为我没有读取着色器中的模板缓冲区值。或者,当纹理必须在着色器中读取并且 OpenGL 使用它进行模板测试时,是否会出现任何与硬件相关的问题?
这个纹理填充了深度/模板值。我不想避免对特定像素(天空)进行一些繁重的 BRDF 光照(定向光)计算。
示例代码:
//Contains the depth/stencil texture(deferredDepthStencilTextureID).
//Two FBO's are sharing the same depth/stencil texture.
lightAccumulationFBO->bind();
glEnable(GL_STENCIL_TEST);
glStencilFunc(GL_EQUAL, 1, 0xFF);
//Disable writing to the stencil buffer, i.e. all the bits is write-protected.
glStencilMask(0x00);
glDisable(GL_DEPTH_TEST);
glEnable(GL_BLEND);
glBlendFunc(GL_ONE, GL_ONE); //Additive blending. Light accumulation.
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, deferredDepthStencilTextureID); //GL_DEPTH24_STENCIL8
//Bind other textures here...
shader.bind();
//Uniforms here...
postProcessQuad->renderQuad();
shader.unbind();
//Unbind all the textures here.
...
glDisable(GL_BLEND);
glEnable(GL_DEPTH_TEST);
glDisable(GL_STENCIL_TEST);
lightAccumulationFBO->unbind();
【问题讨论】:
-
您是只在此渲染过程中进行模板测试,还是使用修改模板值的模板操作?
-
我已经用示例代码更新了我的帖子。我没有在这个渲染过程中包含模板操作。我还设置了这样的模板掩码:glStencilMask(0x00);
标签: opengl textures shader depth-buffer stencil-buffer