The proper name for this problem is triangle rasterization .
This is a well-researched issue and there are many ways to do this. Two popular methods:
Scan line by line scan.
Each scan line requires some basic geometry to recalculate the beginning and end of the line. See the Bresenham line drawing algorithm .
Check each pixel in the bounding box to see if it is in a triangle.
This is usually done using barycentric .
Most people believe that method 1) is more effective, since you do not spend time testing pixels that may be outside the triangle, about half of all pixels in the bounding box. However, 2) it has a great advantage - it can be run in parallel much easier, and therefore for hardware, as a rule, much faster. 2) also easier to code.
The original article for describing how to use method 2) was written by Juan Pineda in 1988 and is called the “Parallel Algorithm for the Rasterization Polygon”.
For triangles, this is conceptually very simple (if you study barycentric coordinates). If you convert each pixel to the barycentric coordinates of a triangle, alpha, beta and gamma, then a simple test is that alpha, beta and gamma should be between 0 and 1.
source share