Search code examples
openglmathgraphicsprojectionrasterizing

finding out triangles inside the projection plane


Lets assume the following three lines represent the vertices of a triangle in 3D space after projection transformation (these are just arbitrary values just for example):

0.0000000 0.0000000 0.9797980
0.1191754 0.0000000 0.9797980
0.0000000 0.1191754 0.9797980

If the projection plane is a square of length 2 (top left point (-1,1) and bottom right point (1,-1), and I have already performed clipping with respect to z-axis, z co-ordinates will be within [-1,1] by now. So, how will I determine the triangles which are totally outside the projection area like the image below ? Will they have all their x, y values of each vertex >1 or <-1 ?


Solution

  • No. Even if all vertices are outside of the visible area, the triangle can still be visible. This would, for example, be the case for this points:

    -2  -2  0.5
     2   2  0.5
     2  -2  0.5
    

    Although both, the x and y component are outside of [-1, 1] the triangle still covers half of the screen.

    Actually, there is no easy solution to exactly determine which triangles are outside (or inside) the visible region. Depending on your needs there are several options:

    If it is acceptable to classify some triangles as visible although they are not, you could test whether all points are outside the same side of the visible region. For example, if all points have x < -1 and so on.

    If you really need a perfect classification, the Sutherland–Hodgman algorithm might be an option. When the output list is empty, the triangle is completely invisible.