我知道從同一紋理/位置讀取/寫入是一個非常糟糕的想法,因爲這會導致未定義的行爲。 但在我的情況下,如果禁用了深度測試,並且我在着色器中讀取了深度值,那麼在讀取相同紋理中的深度值的同時進行模板測試可以嗎?模板測試(紋理相同)時讀取深度值
在我看來,應該不會有任何問題,因爲我沒有讀取着色器中的模板緩衝區值。或者,當紋理被着色器讀取並且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