Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OpenGL - Not Draw Completely Occluded Polygons?

Let's say we have a set of polygons, can change the camera view angle and can translate the camera in the 3D environment. From certain view angles some of these polygons are completely occluded by one or several of the other polygons. For each drawn frame we know the exact coordinates for each of these polygons and can iterate through them in the "increasing distance to camera" or "decreasing distance to camera" order.

Now my question:

What is an efficient way to prerender determine whether a polygon is completely occluded by others, so that we could simply skip it in the drawing process to boost performance?

like image 464
Fejwin Avatar asked Jan 19 '23 14:01

Fejwin


2 Answers

The technique you're looking for is called Occlusion Culling and is a rather complex task.

Being able to iterate through them in increasing camera distance order (front-to-back) gives you some advantages. Just rendering them this way lets you profit from early z-testing features of nowaday's graphics hardware and the polygons only have to go through vertex-processing and rasterization, but need not to be fragment-shaded. This can also be achieved without sorting the polygons but rendering them (in an arbitrary order) in a so-called depth-prepass, where you disable color writes and only render the polygons' depth values. Now in the next rendering pass (the real one) you also profit from early z-rejection.

You might also use hardware occlusion queries of nowaday's GPUs like explained in this GPU Gems article.

But like Hannesh said, it should always be weighted if the overhead of the occlusion culling is worth it. I assume the front-to-back sorting in your case doesn't just come out of nowhere. Maybe the depth-prepass is a viable alternative requiring no sorting. Whereas you can use occlusion queries in a way that doesn't require any sorting (like described in the link), in this case it's not as effective as with front-to-back sorting.

like image 154
Christian Rau Avatar answered Jan 27 '23 20:01

Christian Rau


What you're thinking of is called Occlusion culling. Modern graphics cards have functions you can call that tell you exactly that. You have to have already rendered the occluding scene first though. The alternative is to do this on the CPU.

However, I would not suggest doing what you are trying to do in any case. Graphics cards are fast at rendering static data in big chunks. If you are modifying that data to remove hidden surfaces, you're going to kill performance no matter how fast your occlusion algorithm is. And graphics cards a smart, if they realise that a polygon is completely covered they'll throw it out the the pipeline early.

If you are not already doing so, put your polygons into a static vertex buffer. Vertex buffers are a great way to rendering a lot of polygons quickly.

like image 37
Hannesh Avatar answered Jan 27 '23 20:01

Hannesh