Sign in to follow this  

Flickering when using Occlusion culling

This topic is 1070 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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 ?

Share this post


Link to post
Share on other sites

If you use system such as this it will be a lot slower than not using it at all

 

Your first problem is that you read data from gpu IN THAT SAME frame that you submited queres - this way your cpu and gpu work in full sync with is realy bad

 

You cannot use bounding box that encloses shape to render it's occlusion proxy, for occlusion proxy you need real object or it's simplified version, it's not that easy to develop

working occlusion system with occlusion queres

 

better than thinking of individual object think of 'zones' for example if you are rendering big city and you are standing on the street, divide your city into zones, and assign occlusion proxy (some simple - probably convex - shape that encloses each zone) then render your city normally (in first frame) , THEN render occlusion queryes, THEN in next frame query them for results and  from this result decite to render or not to render zones (you should ideally have 2- 3 frames of delay between pushing occlusion query and fetching it's result - othervise gpu-cpu sync occur and performance will be lost

 

(ofcourse your camer moves, so you need to take that into account and do a LOT of heuristic to not produce artifacts)

Share this post


Link to post
Share on other sites

If you use system such as this it will be a lot slower than not using it at all

 

Your first problem is that you read data from gpu IN THAT SAME frame that you submited queres - this way your cpu and gpu work in full sync with is realy bad

I fixed that problem and actually I got 40-50%, and more improved performance.

I will think about what you've said and try to implement something.

Share this post


Link to post
Share on other sites

This topic is 1070 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this