Sign in to follow this  
MrSparkle

How to implement occlusion culling

Recommended Posts

Hi, I'm looking for an approach to do occlusion culling based on bounding spheres. I have a big outdoor scene with hundreds of objects, that I only want to load into memory if they are potentially visible. I have already implemented a fast frustum culling algorithm based on the bounding spheres of the objects. The objects themselves are only loaded into memory (and rendered) if the bounding sphere is within the view frustum. Now I wonder if it could be possible to use the bounding spheres also to check if an object is occluded by other objects. I was thinking of rendering all objects in the view frustum from front to back in this way: (1) Clear the backbuffer (or offscreen rendertarget) (2) Loding the first (nearst) object into memory and render it (3) Check if the bounding sphere of the next object is completely occluded (4) If it's partially visible, load object into memory and render it, else skip object (5) Repeat steps (3) and (4) for each object in the view frustum But I guess, using this approach would be even slower than simply loading and rendering all objects because I have to check every pixel (in the area of the projected bounding sphere) in the render output for visibility. Because I render from front to back, it's just an simple alpha test, but in the worst case, I have to compare all pixels. How could I improve this kind of occlusion culling? It's very important that the occlusion culling is made with bounding spheres, because loading them from disc does take much more time than the actual rendering. Christian

Share this post


Link to post
Share on other sites
This really depends on the project. Moreover, the best method now won't necessarily be the best method once things get more demanding.

Occlusion culling takes the work off the GPU and onto the CPU. If the geometry is very complex, you may see benefits from occlusion culling, particularly if the objects are likley to occlude one-another frequently. But unless you have a lopsided system or are planning on pushing the GPU to its absolute limits, it's usually best to leave the burden on the video card.
If a significant proportion (say > 10%) of render-time will not witness any occlusions, then there's little point in implementing it: Relying on occlusions to boost an otherwise unacceptable framerate is poor planning. If the framerate is okay without it, there's not much need for it; if the framerate isn't okay without it, you'll be in trouble when nothing overlaps in screen space. For this reason I rarely use OC myself.

Also, be aware that your Z-Buffer relieves a big load from the GPU when you render things front to back. Although the vertex throughput remains high, the fillrate tends to benefit hugely. Once again: unless the vertex pipeline is your bottleneck (which is reasonably rare on modern GPUs) then you'd be wasting your time culling any further.

Otherwise, your method is, as far as I'm aware, as streamlined as they come.

Regards
Admiral

Share this post


Link to post
Share on other sites
Thank you for your considerations. The bottleneck in my applications is definately loading the models, shaders and textures from disc (or database or internet server or whatever). This is the reason I want to skip it for non-visible objects (beside the fact that I don't have infinite memory capacity).

Imagine a city with streets and houses along the streets. There could be possibly hundreds of houses in the view frustum, but there are only three or four visible in the foreground. So, theoretically I only need to load a few objects from disc instead of several hundreds. The only thing I need to know, is the position and the radius of the bounding sphere of each object.

I read about an using the DirectX Occlusion Query to check for occlusion, so I think I give this a try.

Christian

Share this post


Link to post
Share on other sites
Quote:
Original post by MrSparkle
I read about an using the DirectX Occlusion Query to check for occlusion, so I think I give this a try.

I wrote an article about this back when occlusion queries were new. Although it's a novel approach to the problem, the asynchronous nature of the queries quickly becomes prohibitive. To get any kind of decent performance, it requires far too much amortization and prediction.

D3D10 is another story though - it will have predicated rendering, which does this kind of stuff quickly.

If you are in search of a stable, fast, and easy culling method, I recommend just doing regular old frustum culling with a quadtree or octree.

Share this post


Link to post
Share on other sites
Yes, I found an articel in the GPU Gems book about the Occlusion Queries. Seems to be pretty complicated (start query in this frame and read the result in the next etc...) so I decided to use only frustum culling. Maybe I implement that later, or when using DirectX10...

Thanks!
Christian

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