Sign in to follow this  
B_old

Occlusion queries for culling

Recommended Posts

Hi, there are some things that I don't understand regarding the use of occlusion queries for culling. I understand, that waiting for the queries to finish can take a while so the results are sometimes gathered a frame or so later. But in that case the view could have changed and the provided results useless. How is this usually handled?

Share this post


Link to post
Share on other sites
That's one of the downsides of [hardware] occlusion queries. If your game is running at 60fps, you're probably not likely to notice a frame or two of lag where an occlusion is concerned, especially if it's off in the distance.

Occlusion queries rely largely on temporal coherence and relatively smooth camera movements. If your camera jumps about wildly and your fps isn't up to it, you might want to consider something different as HOQ's downsides may become too apparent.

Share this post


Link to post
Share on other sites
Hm, ok.
So what you are saying is that there can definitely be situations where HOQs will fail if I'm not willing to wait for the result in the given frame?
How popular do you think are HOQs?

Is the common approach to wait exactly x (1 or 2 mabye) frames for the result or do the queries get the time they need?

I read a little about predications. They sounds quite good to me, although it could be that the predicated draw calls are always executed anyway. Would be interesting to hear about the successful usage of predications.

[Edited by - B_old on April 26, 2010 7:49:46 AM]

Share this post


Link to post
Share on other sites
Quote:
So what you are saying is that there can definitely be situations where HOQs will fail if I'm not willing to wait for the result in the given frame?


You can't not wait for the result as that defeats the object of HOQ. If you mean "HOQs will fail" conceptually, then yes. It's inherent with the nature of HOQs. What you see in the current frame, may not be correct with regard to occlusion queries.

Consider the case where you have a box in front of you, partially obscuring your view of the scene. If an object moves from being in view on the right to behind the box, there will be a frame (or two) where you will still draw the object behind (even though it should be fully occluded) because as far as your current query is concerned, it's still visible. Once enough frames have passed your current query will return that it's not visible which is correct. When the object emerges from behind the box on the left-hand side, there will be a frame (or two) where you will not draw the object behind yet because the current query thinks it's still invisible. This one-two frame lag will probably not be noticeable for the most part, but that will obviously depend on your FPS and how fast the object/camera is moving.

Quote:
How popular do you think are HOQs?

I've no idea on this one. I would personally think not hugely because of the issues mentioned above. I guess it depends on the application and the complexity of the scene. Someone else may have more knowledge on this.

Quote:
Is the common approach to wait exactly x (1 or 2 mabye) frames for the result or do the queries get the time they need?

The queries will finish when they finish. Unfortunately you don't have any control over how long they take - although drawing occlusion queries with simplified geometry can obviously speed things up.

Share this post


Link to post
Share on other sites
Quote:
Original post by RobMaddison
The queries will finish when they finish. Unfortunately you don't have any control over how long they take - although drawing occlusion queries with simplified geometry can obviously speed things up.

Sorry for being so slow, but I have to ask about this again: Every frame I issue an occlusion test. Right before I want to draw the actual geometry I look whether the test generated any result already. If not, I go ahead and draw the geometry. If there is an result I only draw the geometry depending on it's outcome.

Share this post


Link to post
Share on other sites
I wouldn't worry about the frame latency at all. The glow is only a visual effect. Will it affect the gameplay? I guess not, so don't worry about it.

Share this post


Link to post
Share on other sites
Quote:
Sorry for being so slow, but I have to ask about this again: Every frame I issue an occlusion test. Right before I want to draw the actual geometry I look whether the test generated any result already. If not, I go ahead and draw the geometry. If there is an result I only draw the geometry depending on it's outcome.

That's pretty much it, yes. Although if the last query result you have shows it to be invisible, you don't draw the geometry. You basically draw it based on the last query result you have.

If you still want to try them, here's a good resource on HOQs.

Share this post


Link to post
Share on other sites
In many situations, occlusion queries are free, even within the same frame. For example if you use a variation of light pre-pass rendering, they are guaranteed to have finished. You're using a rendered-to buffer as an input, so all drawing must necessarily have finished before the second pass, thus all queries are complete.
Similarly, if you use a variant of shadow mapping or stencil shadowing, you are not strictly guaranteed that your occlusion queries are done before you start with the first lighting pass, but it is highly likely.

You can tell the driver to use occlusion queries if they are finished and render everyting otherwise, too (conditional rendering). This exists as core feature for recent OpenGL versions, and as extension for older versions (and since it's a no-brainer for the driver, I'd be surprised if it can't be done under a recent version of Direct3D as well). This is less intrusive and less overhead.

Share this post


Link to post
Share on other sites

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