Hi!
I was able to successfully implement the stencil routed k-buffer algorithm for transparent objects.
Here you can find the short paper with the explanation.
The algorithm uses multisample and the stencil test.
I found out that my frames drop drastically due to the following group of instructions in my render loop:
const uint32_t m_nTransparencyLayers = 0x1u << 3;//I use 8 transparency layers
//I need to clean my stencil buffer each render loop
for (uint32_t i = 0; i< m_nTransparencyLayers; i++)
{
glStencilFunc(GL_ALWAYS, i + 2, m_nTransparencyLayers - 1);
glSampleMaski(0, 0x1u << i);
m_pFrameBuffer->DrawBlank(m_pShaderBlank);
}
Comments on the last function (DrawBlank
):
- I bind a custom frame buffer if it is not, it uses multisample, according to the algorithm
- I draw a full screen quads, the vertex shader only outputs the four vertices, the fragment shader outputs black
- I need to call this function in order to “flush” for each sample (enabled using
glSampleMaski
) the correct stencil reference value set withglStencilFunc
The algorithm works perfectly but calling this “cleaning” loop kills my performance.
If you have any tips/suggestions I will really appreciate.
Thanks