Back-face culling
In computer graphics, back-face culling determines whether a polygon that is part of a solid needs to be drawn.[1][2][3] 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.[4]
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.[2] 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.[5]
History
[edit]Back-face culling has been used since at least the 1970s.[6] It has been used in many video games, including the original 1984 BBC Micro version of the game Elite.[7] By the mid 1990s, many graphics systems could implement back-face culling in hardware.[4]
Implementation
[edit]One method of implementing back-face culling is by discarding all polygons where the dot product of their outward pointing surface normal, , and the line of sight vector, , is greater than or equal to zero:
In the case of rendering a polygon specified by a list of vertices, this might be calculated by
where P is the view point, V0 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 V0
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):
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:
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.[8]
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
Then for some other triangle, also in two dimensions,
define a matrix that transforms the unit triangle:
so that:
Discard the triangle if matrix M contained an odd number of reflections (facing the opposite way of the unit triangle)
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.
References
[edit]- ^ Foley, James D.; van Dam, Andries; Feiner, Steven K.; Hughes, John (15 June 1990). Computer Graphics: Principles and Practice (2nd ed.). Addison-Wesley. ISBN 978-0-201-12110-0.
- ^ a b Watt, Alan; Watt, Mark (1992). Advanced Animation and Rendering Techniques. Addison-Wesley. ISBN 0-201-54412-1.
- ^ Jones, Huw (2001). Computer Graphics through Key Mathematics. Springer. ISBN 1-85233-422-3.
- ^ a b Kumar, Subodh; Manocha, Dinesh; Garrett, Bill; Lin, Min (1996). "Hierarchical back-face culling" (PDF). 7th Eurographics Workshop on Rendering: 231–240. Retrieved 2025-02-08.
- ^ Hoeven, van der, Jorick (2008). Non-Photorealism in Interactive Rendering Systems (PDF) (BA in Computer Science thesis). University of Oxford. Archived from the original (PDF) on 2021-11-02. Retrieved 2023-08-10.
- ^ Sutherland, Ivan E; Sproull, Robert F; Schumacker, Robert A (1974). "A Characterization of Ten Hidden-Surface Algorithms". ACM Computing Surveys (CSUR). 6 (1). ACM: 1–55. doi:10.1145/356625.356626. Retrieved 2025-02-08.
- ^ Moxon, Mark (2020). "How Elite draws solid-looking 3D ships by only drawing visible faces". bbcelite.com. Retrieved 2025-02-08.
- ^ Eberly, David H. (2006). 3D Game Engine Design: A Practical Approach to Real-Time Computer Graphics. United States: Morgan Kaufmann Publishers. p. 69. ISBN 0122290631.