Lately, I've been learning some OpenGL for fun, and I've been thinking about hidden surface removal.

Say you have a high poly count static scene, with nothing that moves, no bones, physics, etc. Just static models to be drawn. I was thinking that you could put all the faces in the scene into a quad/octree. And with the camera position, and dimensions of the view frustum, you could traverse the tree to construct an index buffer of all the faces that are within the view frustum (facing towards you of course). You could then update the index buffer with glBufferSubData(), and draw with glDrawElements(), and you would do this every frame, and if my limited understanding is correct, this should theoretically draw only the faces you see, right?

So is this a good/valid way to do occulusion culling? If not, how else can you do it?


It's all about tradeoffs.

But first, occlusion culling is to hide what is being hidden by other objects, not what falls outside the viewing frustum. What you described is called frustrum culling.

Sure, you can do that and only request to draw polygons that you will see, but those calculations, along with the time required to update the index buffer may have a non negligible impact on performance, mostly on the CPU, but will also require a GPU sync to reupload the index buffer.

Compare that to drawing everything without culling. You will certainly need to upload your data to VRAM, but only once. GPU processing will then happen for each vertex. The CPU will hardly notice this is going on.

Keep in mind that viewport culling is an extremely simple operation for the GPU.

Ultimately, you're trading GPU cycles for CPU cycles. Deciding whether to do what you propose is affected by a number of factors, including fhe type of geometry you have, the hardware you use, and what else is going on in your game besides rendering.

As always, when we talk performance, it is usually advisable to measure first and act later. Bottlenecks may exist where you least expect them, and places where you think bottlenecks exist may wxhibit no problems at all.

Consider also changing the unit of culling. It may not be necessary to do per polygon culling, when you can get away with per mesh, or per submesh culling.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.