Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OpenGL newbie question: what is back face culling?

Tags:

opengl

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

like image 816
fhucho Avatar asked Aug 29 '10 14:08

fhucho


People also ask

What is front face culling?

Foreshortening means that even the sides are facing away from the camera. Face culling allows non-visible triangles of closed surfaces to be removed before expensive Rasterization and Fragment Shader operations.

What does culling mean in graphics?

In 3D rendering the term culling describes the early rejection of objects of any kind (objects, draw calls, triangles and pixels) that don't contribute to the final image. Many techniques exist that reject objects at various stages in the rendering pipeline.

What is a culling function?

Culling refers to the automatic manipulation of the wordlist (proposed by Hoover 2004a, 2004b). The culling values specify the degree to which words that do not appear in all the texts of a corpus will be removed.

Does OpenGL automatically cull?

By default, OpenGL expects counter-clockwise winding order for triangles that are facing forwards. With backface culling enabled, triangles facing the other direction will be automatically culled. This occurs before rasterization.


2 Answers

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.

like image 167
Eric Lippert Avatar answered Sep 20 '22 22:09

Eric Lippert


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.

like image 35
ChrisF Avatar answered Sep 18 '22 22:09

ChrisF