# Back-face culling

In computer graphics, back-face culling determines whether a polygon that is part of a solid needs to be drawn. Polygons that face away from the viewer do not need to be drawn, as they will be obscured by other polygons facing the viewer. This process makes rendering objects quicker and more efficient by reducing the number of polygons to be drawn.
For example, in a city street scene, there is generally no need to draw the polygons on the sides of the buildings facing away from the camera; they are completely occluded by the sides facing the camera. If multiple surfaces face towards the camera, then additional use of methods such as Z-buffering or the Painter's algorithm may be necessary to ensure the correct surface is rendered. Back-face culling is typically quite a cheap test, only requiring a dot product to be calculated, and so it is often used as a step in the graphical pipeline that reduces the number of surfaces that need to be considered.
In general, back-face culling can be assumed to produce no visible artifact in a rendered scene if it contains only closed and opaque geometry. In scenes containing transparent polygons, rear-facing polygons may become visible through the process of alpha composition. Back-face culling may also be applied to other problems. For example, in wire-frame rendering, back-face culling can be used to partially address the problem of hidden-line removal, but only for closed convex geometry. Back-face culling can also be applied to flat surfaces other than polygons, for example disks, which have a constant normal vector or extended to patches where the surface normal can be bounded.
A related technique is clipping, which determines whether polygons are within the camera's field of view at all. As clipping is usually more expensive than back-face culling, back-face culling it often applied first. Another similar technique is Z-culling, also known as occlusion culling, which attempts to skip the drawing of polygons that are covered from the viewpoint by other visible polygons.
In non-realistic renders, certain faces can be culled by whether or not they are visible, rather than facing away from the camera. "Inverted hull" or "front face culling" can be used to simulate outlines or toon shaders without post-processing effects.

## History

Back-face culling has been used since at least the 1970s. It has been used in many video games, including the original 1984 BBC Micro version of the game Elite. By the mid 1990s, many graphics systems could implement back-face culling in hardware.

## Implementation

One method of implementing back-face culling is by discarding all polygons where the dot product of their outward pointing surface normal, $N$, and the line of sight vector, $L$, is greater than or equal to zero:
    $L\cdot N\geq 0$
In the case of rendering a polygon specified by a list of vertices, this might be calculated by
    $\left(V_{0}-P\right)\cdot N\geq 0$
where P is the view point, V$_0$ is the first vertex of a triangle and N could be calculated as a cross product of two vectors representing sides of the triangle adjacent to V$_0$
    $N=\left(V_{2}-V_{0}\right)\times \left(V_{1}-V_{0}\right)$
Since cross product is anticommutative, defining the normal in terms of cross product means that the normal direction is dependent on the vertex order (winding):
    $\left(V_{1}-V_{0}\right)\times \left(V_{2}-V_{0}\right)=-\left(V_{2}-V_{0}\right)\times \left(V_{1}-V_{0}\right)$
Consequently, the vertex ordering is usually chosen such that front-facing triangles have clockwise winding, N defined as above is the normal directed outward from the object. In this setup, back-face may be regarded as a test of 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, but the polygon projected on the screen has a counter-clockwise winding then it has been rotated to face away from the camera and will not be drawn.
If the points are already in view space, P can be assumed to be (0, 0, 0), the origin, simplifying the above inequality:
    $V_{0}\cdot N\geq 0$
It is also possible to use this method in projection space by representing the above inequality as a determinant of a matrix and applying the projection matrix to it.
Another method exists based on reflection parity, which is more appropriate for two dimensions where the surface normal cannot be computed (also known as CCW check).
Let a unit triangle in two dimensions (homogeneous coordinates) be defined as
    $U_{0}={\begin{bmatrix}0\\0\\1\end{bmatrix}},U_{1}={\begin{bmatrix}1\\0\\1\end{bmatrix}},U_{2}={\begin{bmatrix}0\\1\\1\end{bmatrix}}$
Then for some other triangle, also in two dimensions,
    $V_{0}={\begin{bmatrix}x_{0}\\y_{0}\\1\end{bmatrix}},V_{1}={\begin{bmatrix}x_{1}\\y_{1}\\1\end{bmatrix}},V_{2}={\begin{bmatrix}x_{2}\\y_{2}\\1\end{bmatrix}}$
define a matrix that transforms the unit triangle:
    $M={\begin{bmatrix}x_{1}-x_{0}&x_{2}-x_{0}&x_{0}\\y_{1}-y_{0}&y_{2}-y_{0}&y_{0}\\0&0&1\end{bmatrix}}$
so that:
    $MU_{0}=V_{0}$
    $MU_{1}=V_{1}$
    $MU_{2}=V_{2}$
Discard the triangle if matrix M contained an odd number of reflections (facing the opposite way of the unit triangle)
    $\left|M\right|<0$
The unit triangle is used as a reference and transformation M is used as a trace to tell if vertex order is different between two triangles. The only way vertex order can change in two dimensions is by reflection. Reflection is an example of involutory function (with respect to vertex order), therefore an even number of reflections will leave the triangle facing the same side, as if no reflections were applied at all. An odd number of reflections will leave the triangle facing the other side, as if exactly after one reflection. Transformations containing an odd number of reflections always have a negative scaling factor, likewise, the scaling factor is positive if there are no reflections or even a number of them. The scaling factor of a transformation is computed by determinant of its matrix.