tags:

views:

113

answers:

4

What exactly is back face culling in OpenGL? Can you give mi a specific example with e.g. one triangle?

+2  A: 

Back face culling is where the triangles pointing away from the camera/viewpoint are not considered for drawing.

Wikipedia defines this as:

It is a step in the graphical pipeline that tests whether the points in the polygon appear in clockwise or counter-clockwise order when projected onto the screen. If the user has specified that front-facing polygons have a clockwise winding, if the polygon projected on the screen has a counter-clockwise winding it has been rotated to face away from the camera and will not be drawn.

Other systems use the face normal and do the dot product with the view direction.

It is a relatively quick way of deciding whether to draw a triangle or not. Consider a cube. At any one time 3 of the sides of the cube are going to be facing away from the user and hence not visible. Even if these were drawn they would be obscured by the three "forward" facing sides. By performing back face culling you are reducing the number of triangles drawn from 12 to 6 (2 per side).

Back face culling works best with closed "solid" objects such as cubes, spheres, walls.

Some systems don't have this as they consider faces to be double sided and hence visible from either direction.

ChrisF
I still don't understand it :) If I have a red triangle, it should be drawn in both cases (vertices are in cw or ccw order). With face culling, the triangle would disapear if I looked at it from behind.
fhucho
@fhucho - in this case you are considering that the triangle is in effect double sided and want to turn back face culling "off".
ChrisF
@ChrisF - Thanks, I get it now.
fhucho
@fhucho - no problem. You might be able to do per object back face culling where you can turn it on for cubes, spheres etc. and off for "open" objects. But this will depend on your application.
ChrisF
+1  A: 

Triangles have their coordinates specificed in a specific order, clockwise IIRC.

When the graphics engine look at a triangle from a specific direction, and the coordinates are counter-clockwise, it knows that it's looking at the backside of the triangle through an object. As the front side of the object is covering the triangle, it doesn't have to be drawn.

Guffa
It's actually the other way around by default -- CCW points indicate a forward-facing triangle, and CW points indicate backward facing. There's a way to change this, though.
cHao
+3  A: 

If you look carefully you can see examples of this in a lot of video games. Any time the camera accidentally moves through an object - typically a moving object like a character - notice how the world continues to render correctly. That's because the back sides of the triangles that form the skin of the character are not rendered; they are effectively transparent. If this were not the case then every time the camera accidentally moved inside an object either the screen would go black (because the interior of the object is not lit) or you'd get a bizarre perspective on what the skin of the object looks like from the inside.

Eric Lippert
A: 

It's only and optimization technique.

When you look at a closed object, say a cube, you only see about half the faces : the faces that are towards you (or, at least, the faces that are not towards you are always occluded by another face that points towards you)

If you skip drawing all these backwards-facing faces, it will have two consequences : - the rendering time will be twice better (on average) - the final render won't change (since another, front-facing face will be drawn on top of a "culled" one)

So you basically get x2 perf for free.

In order to know whether the triangle is front- or back-facing, you take v0-v1 and v0-v2, make a cross product. This gives you the face normal. If this vector is towards you ( dot(normal, viewVector) < 0), draw.

Calvin1602