Should I always use GL_CULL_FACE?
Asked Answered
P

3

14

Should I always be using this method when rendering? Does it slow down much on bad graphics cards?

If the end result will not have many culled faces, should I even be using this method then?

Perry answered 6/3, 2010 at 17:37 Comment(1)
Face culling should generally always be enabled if you don't need a face to be visible from both sides. It'll probably speed things up a bit as it'll save you some fill rate.Tacit
A
24

If all your models are defined correctly (convex, with consistent vertex winding), culling will never hurt performance, and will nearly always help performance.

Imagine you are rendering a cube, with culling disabled. The faces on the back (far side) of the cube get rendered facing away from you, and whatever back face material attributes you've chosen get applied. Then the faces on the front of the cube get rendered: since the back faces that were just rendered are the inside of the cube, they are 100% occluded by the front faces.

If the cube was oriented differently, the front faces might be rasterized first, but the back faces will still be processed and then the fragments rejected by the z buffer.

Net result: you rasterized 2x as many fragments as necessary. This gets to be a big deal with large numbers of polygons or complex pixel shaders. Face culling allows you to completely avoid rasterizing faces that you know won't show up.

If you have a character model with ~100,000 polygons, face culling halves the amount of work the pixel hardware has to do every frame. This is a big savings if you have big surface shaders.

If you're working with small models and no shaders, culling really doesn't matter these days. But it's good practice to enable anyway.

Andalusite answered 6/3, 2010 at 18:7 Comment(1)
I don't think you really answered this question "If the end result will not have many culled faces, should i even be using this method then?". I also wonder if the performance gets worse if I ONLY render front facing polygons.Chuff
R
8

Enabling face Culling (usually back-face) has a significant impact on the rendering performance.

Now the question to be answered is then "why isn't culling enabled by default or why isn't used always?" there are several factors which determine whether enabling culling is feasible or not. One is the model being rendered and how it is viewed.

For every polygon in the model, if only one face either front or back is visible (when the model is viewed from all possible angles) then we can cull the other face.

For Ex: "Cube", no matter if you are looking from inside or outside of it, when rotated, you can see only one side of every 6 polygons which make-up the cube.

Another Ex: "Sails of a ship Model" as in my Sea-Wars(3d) game, the sails of a ship model is a surface built with several flat polygons. When a boat moves around in the water, one can see both sides of the sail. In this case culling either of the faces is not desirable.

Hence culling can be enabled for all the models in the scene which follow cubes semantics and disabling for all other models.

P.S. Face Culling should be used whenever possible.

Respiratory answered 15/1, 2011 at 0:25 Comment(0)
E
0

It depends on the stuff you are rendering. In general culling is desirable. The only reason I can imagine not to use it is to render models that have visible backfaces. Another scenario where culling might not be wanted could be poorly modeled models where the vertices are defined in the wrong order.

Eagle answered 6/3, 2010 at 17:43 Comment(1)
what about the culling ratio? if it doesnt really make the result any different from that what it was before culling, should i even use culling? in other words: is there much impact on speed when this is enabled?Perry

© 2022 - 2024 — McMap. All rights reserved.