Master the fundamental concepts of software rasterizer through this focused micro-challenge.
A closed 3D model has outward-facing front triangles and inward-facing back triangles. When the camera sits outside the mesh, back faces are never visible. They would be hidden by front faces and the z-buffer anyway.
Back-face culling skips rasterizing away-facing triangles. For closed opaque models, this eliminates roughly 50% of triangles before any per-pixel work begins. OpenGL, Vulkan, and Direct3D enable it by default.
For triangle vertices A, B, C in counter-clockwise order (front-facing):
cLoading…
For example, a triangle on the XY plane facing +Z with camera at (0,0,5) has N pointing toward the camera and survives. A triangle facing -Z gets culled because the normal points away. The dot product measures cosine of the angle between normal and view vector; negative means angle > 90 degrees.
You will implement the culling test for a set of triangles and count survivors. This task requires computing face normals via cross product and comparing against the camera position. Wrong winding order when importing Blender or Maya meshes is one of the most common bugs in custom renderers.
Write a C program that implements back-face culling for a set of triangles.
Requirements:
Three hints are available for this task, revealed one at a time inside the code workspace so you can struggle productively before seeing them.
All starter code and reference implementations are available for your local setup.
View on Github