GL backface culling

Tobi
Unregistered
 
Post: #1
Hi folks,

I've started using OpenGL's built-in backface culling and it's giving a good performance boost. But is it really the fastest way to perform backface culling or is some sort of algorithm faster for this than OpenGL ??

Thanks in advance,

-Tobias Opfermann
Quote this message in a reply
Feanor
Unregistered
 
Post: #2
Because the back face culling process is pretty standard and is probably always hardware accelerated, there is no way you could out-perform it using a custom algorithm. I can't say that I know the complete details of OpenGL's algorithm, but I believe it creates a line between the first two verts in a triangle and checks which side the third vert is on (probably in the order submitted but I have no real idea). If you have front face set to CCW (standard IIRC), then if the third vert is on the right of the line defined by the first two, the triangle is facing backwards and so it isn't drawn. The algorithm is simple and I'm sure the hardware implementation is optimized as far as it can be.

You might want to ask yourself if you do a lot of setup of back-facing verts (though I can't see why), in which case you'd want to cull them yourself before even sending them to OpenGL. But since OpenGL is doing the textures and the lighting, you're safe to let it do bf culling too. You get extra benefits from OpenGL doing the culling if you're using either vertex arrays or display lists. If you culled yourself, I think you'd have to resubmit the array or rebuild the list every time a triangle was hidden or revealed. That sounds inefficient to me.

b
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #3
Generally a good guideline for this kind of thing is that if you can perform a test for more than N polygons at once, you should do that; otherwise just leave that test to OpenGL.

Unfortunately, N is highly dependent on both the test an the 3D card. For an ATI Rage128, N is almost always 1 Wink

Ultimately though, there's no substitute for trying several approaches and seeing which one is faster.

For the specific case of back-face culling, BSP trees give you the test for free...
Quote this message in a reply
Tobi
Unregistered
 
Post: #4
Thanks for the info.

I guess I'll stick to the GL Bf Culling. I'm using interleaved arrays for nearly everything, so doing an algorithm here seems to waste time.
Another thing like this:

I'm using an algorithm to do the clipping of all the objects on the 6 clipping planes. It's quite fast but I suppose OpenGL to be faster here as well. Can anyone confirm that?

-Tobi
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #5
Again, if you were going to cull individual polygons then yes, OpenGL would be faster, but because you can exploit the structure of the world, you can cull hundreds or thousands of polygons with a single test -- and that is worthwhile. Indeed, structures like Quadtrees, octtrees and BSP trees exist mainly to help with this task.
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Tree Culling Jake 13 5,908 Jan 7, 2005 02:44 AM
Last Post: arekkusu
  Alternate Back face culling Sohta 6 4,663 Aug 6, 2004 06:10 PM
Last Post: Sohta
  Math problem involved in culling DJBlufire 5 3,262 Feb 4, 2003 06:35 PM
Last Post: NYGhost