1Rasterization
The hardware process where primitives are rendered to the screen, and defining which pixels are a part of said primitive.
2Rasterization: Point Primitives
Takes the closest fragment to the point.
3Rasterization: Line Primitives
Bresenham's Line Algorithm
Advance a primary axis each loop of rasterization. Each loop add to an error value the gradient of the slope.
If the error value >= 0.5, advance the periodic (other) axis and subtract 1 from the error value.
Primary axis = greater abs value of x and y (in the direction vector)
4Rasterization: Triangles
Place a bounding box around the triangle (clamping it's minimum and maximum x and y values)
Two ways to solve this:
Line Equations
Barycentric Coordinates
5Rasterization: Triangles: Line Equations
Take the line equations of each line of the triangle, and check the point p (the one you're testing) and see if it's on the correct side of the line.
Only points inside the triangle will pass all 3 lines.
6Rasterization: Triangles: Barycentric Coordinates
Calculate the area of the triangle t
Form 3 sub triangles around point p: t0, t1 and t2
A = area of t0 / area of t
B = area of t1 / area of t
C = area of t2 / area of t
If A+B+C <= 1.0, p is inside the triangle
7Vertex Interpolation
Applying the vertex attributes to the primitives they are a part of, smoothly across them.
8Vertex Interpolation: Lines
t = v1 - p / v1 - v0
Colour at point p = (v1 colour * t) + (v0 colour * (1.0 - t))
9Vertex Interpolation: Triangles
Using A, B and C from Barycentric Coordinates, times each vertex colour by the relevant coordinate number.
p colour = (v0 colour * A)+(v1 colour * B)+(v2 colour * C)
10Signed Area of a Triangle
Easy solution for calculating the area of a 2D triangle.
Take the 4 vertices that form the triangle's sides (first one twice), and multiply the numbers leading down, and then leading up. Take away the first result from the second result and divide by 2.
Much less computationally intensive.