我知道从同一纹理/位置读取/写入是一个非常糟糕的想法,因为这会导致未定义的行为。 但在我的情况下,如果禁用了深度测试,并且我在着色器中读取了深度值,那么在读取相同纹理中的深度值的同时进行模板测试可以吗?模板测试(纹理相同)时读取深度值
在我看来,应该不会有任何问题,因为我没有读取着色器中的模板缓冲区值。或者,当纹理被着色器读取并且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); – karl88