Rasterization determines which pixels are drawn into the framebuffer, interpolating parameters (colors, texcoords, etc).
We can interpolate using formulae in barycentric coordinates:
In other words, , where , , and are the barycentric coordinates of with respect to the triangle defined by , , and .
Now, to rasterize a point in the triangle, we check .
The signed distance (the distance to the edge, positive if inside, negative if outside) can be computed with an implicit line equation:
To compute a barycentric coordinate for , we should choose such that , etc for and . In example:
So, in general, the barycentric coordinates of solve:
Also, the trilinear coordinates are easily converted into barycentric coordinates as where , , and are the side lengths of the triangle. Similarly, barycentric coordinates can be converted into trilinear coordinates as .
Instead of checking , graphics card used optimized incremental methods for triangle rasterization.
2. Visibility
When triangles overlap, perform hidden surface removal (keep track of visible surfaces). One option is the painters algorithm (sorting triangles by z-value), but this fails when triangles intersect.
Alternatively, a depth buffer (-buffer) is used. Each fragment gets a value in screen space, but only the value with the smallest value is drawn. This is implemented in hardware and is very efficient. Every time something is drawn to the framebuffer, the depth buffer is also updated.
3. Anti-Aliasing
Due to visual texture mapping, we get aliasing artifacts at boundaries and in textures.
The solution is to blur boundaries to reduce the effect. Supersampling computes the picture at higher resolutions and downsampling at boundaries.
A more common solution is a convolution filter that blurs the image. For example, a box filter averages the 4 nearest pixels, while a Gaussian filter gives more weight to closer pixels. This is very fast, but does degrade the image quality.
To antialias textures, we identify a point in the texture map and return an average around that point (mipmapping).