c++3dculling

Back-face culling, does chosen vertex for view vector on triangle matter?


I want to hand implement back-face culling, before passing the tris to the GPU. So I am trying to understand the algorithm. So Wikipedia says for back-face culling to use the first vertex in the triangle:

enter image description here

Does the vertex on the triangle chosen to create the view vector (the view vector in the Wikipedia picture is (V_0-P)) matter for back-face culling though? Like is there potential edge cases when choosing the first vertex actually culls a visible triangle?

So another question, if it actually does matter, is there an optimal point somewhere in the triangle that will always cull face that are only not visible (could be a vertex, on the edge of the triangle, or in the interior)?


Solution

  • Your questions:

    Does the vertex on the triangle chosen to create the view vector (the view vector in the Wikipedia picture is V_0 - P) matter for back-face culling though?

    No, V0 ("the first vertex") is chosen arbitrarily. The math also holds for any other choice of V0, V1 and V2.

    Like is there potential edge cases when choosing the first vertex actually culls a visible triangle?

    Mathematically, this is not possible.

    In practice, this may happen if P lies in the plane the triangle is in (i.e. dot(-V0, N) is very close to 0.0) due to the rounding errors of floating point math. This may show up during rendering as a flickering line depending on your model, camera position, algorithms, implementations, etc.
    I don't think these cases generally pose an actual problem in such a way that they need handled differently. One issue is that it is difficult to detect if a triangle is visible but shouldn't have been (or vice versa). Another issue is that handling these cases requires more computations. E.g. computing dot(-V0, N) for all six possible choices for V0, V1 and V2, doing a majority vote, and then there still is no guarantee that the result is correct.