Hello everyone!
I have implemented occlusion culling in my app and I think why the problem is happening but I am not sure how to solve it.
My scene is divided in different chunks (voxels) and I am rendering each voxel in a separate draw call.
In the 1st pass I render only the bounding box of the voxel and I start queries to check if the voxel is visible:
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LESS);
glDepthMask(GL_FALSE);
for (int i=0; i<numberOfVoxels; ++i)
{
glBeginQuery(GL_ANY_SAMPLES_PASSED, queryHandle[i]);
renderBoundingBox(i);
glEndQuery(GL_ANY_SAMPLES_PASSED);
}
glDepthMask(GL_TRUE);
In the 2nd pass I get the result from the query and if the voxel is visible I render it, otherwise - no :
for (int i=0; i<numberOfVoxels; ++i)
{
glGetQueryObjectiv(queryHandle[i], GL_QUERY_RESULT , &voxel[i].isVisible);
if (!voxel[i].isVisible) continue;
glBindVertexArray(vao[i]);
glDrawArrays(GL_TRIANGLES, 0, voxel[i].dataSize);
}
The problem appears when the bounding box is much bigger than the geometry in it, and there is huge empty gap in the box. When checking for depth test, this big box is hiding the smaller voxels behind it and this results in flickering.
One potential fix I came across is to divide such almost empty bboxes into smaller ones, as described in GPU Gems. But this is not that easy to do in my app and the performance may become even worse.
Do you have any other possible ideas and techniques I can use to solve that problem ?