DirectX12- Triangle Culling and Winding Order

  • Tags : windows
  • time :

1. What is Triangle Culling

  • We all know that in existing 3D graphics frameworks, 3D models are arranged in an orderly manner by Triangles. For example, a rectangular prism has 6 faces, and each face can be split into 2 Triangles. So we can use the 12 Triangles arranged in an orderly manner like [Tri0... Tri11], and finally restore a 3D model of a rectangle:


  • At the same time, we can also observe from a perspective directly facing a face of a rectangular prism, such as:


    From this perspective, only the plane formed by the triangles Tri0 and Tri1 can be observed, and Tri2/3/4/5 cannot be seen. Therefore, this part of the Triangle can be previewed in the Rendering Pipeline of DirectX12 Culling Doing so can reduce unnecessary computation and improve rendering efficiency.

What is Winding Order

  • Winding Order It is knowledge in geometric graphics. Assuming a Triangle consists of three Vertex components, and the order in which the three Vertex components are inputted into the Input Layout of the DX12 driver is Ver0-> Ver1--> Ver2, this The layout order of Vertex is the winding order of Triangle :


    According to Left hand rule Under this winding condition, the normal vector of Triangle is the unit vector that flows outward from the paper and is perpendicular to the plane.
  • Attention: DirectX12 uses the left-hand rule to determine the plane normal vector, while OGL uses the right-hand rule instead .
  • So we can see that, The Vertex winding of each Triangle determines the direction of the normal vector of the Triangle shape .

How to use Winding Order for Culling

  • With the concept of bypass, the principle of elimination is actually very simple.
  • We know that during the rendering process of DirectX12, all 3D models must ultimately be unified into the View Space. Each 3D model is first modeled in local space, and then through the world matrix -> World space, then based on the parameters placed by Camera in the world space, obtain the observation matrix, and then use the observation matrix to transform the world space -> Observing space (pulling away...).
  • So observing space is also a three-dimensional space:


    Camera observation direction points to; Z direction, so we specify that, Compare the normal vector of any Triangle with the unit vector in the - Z direction (such as (0,0, -1)), leave the angle between the two vectors within the range of [0, Pi/2), and exclude them within the range of [Pi/2, Pi] Because a plane with an angle greater than Pi/2 is a plane facing away from the observation direction, it is invisible:


    How to determine the normal vector? It is determined based on the previously mentioned winding sequence.
  • So the entire principle of elimination is so simple, where the angle between the algorithm vector and the calculation vector is supported by mathematical formulas, and will not be elaborated here.
  • In addition, the entire calculation and judgment process of exclusion is done by the GPU Hardware end, because a simple 3D model may consist of thousands of Triangles, and the computational workload is very large.