For this homework assignment, we will be implementing the rasterizer of a simple software rendering engine.
You will need to download this project: RasterizerHomework.zip (modified 1/22).
In it you will find a file called "Homework.cpp" with one MyRendererFunctions::Rasterize function
whose body is a stub.
The rasterizer is the part of the graphics processor that takes three vertices, with positions (X,Y) in screen space and some set of additional attributes. It performs two tasks:
One reasonably simple way in which the first task can be achieved is to first find a box that contains the triangle in its entirety, and then iterate over all the pixels, performing a "point-in-triangle" test.
Several possible issues appear that should be contemplated in order to create a robust rasterizer:
The basic assignment is to find the pixels that belong to the triangle, and output them. If this is done successfully, the various figures (a spinning cube, a teapot and a sphere) will become visible. It will be worth 8 points.
The triangle parameter contains an array vtx of three vertices.
Each vertex has a 4D position vector, and some extra data (two colors, one set of 2D texture coordinates and a fog value).
triangle.vtx[#].position.x and triangle.vtx[#].position.y contain the screen coordinates of a vertex in range [0, 0]-[width,height].
triangle.vtx[#].position.z contains the z-buffer value of a vertex.
triangle.vtx[#].position.w contains the clip-space 1/W value.
triangle.vtx[#].fog contains the fog attribute for the vertex.
triangle.vtx[#].data contains several attribute values for the vertex: diffuse color, specular color and texture coordinates.
The params parameter contains the coordinates and extents of the rectangle where we're rendering.
It is illegal to generate pixels outside of this rectangle.
The pixels array must be filled with the generated pixels, up to pixelsSize pixels
and the function must return the number of pixels generated.
pixel.x and pixel.y are the positive integer coordinates of the pixel.
pixel.z is the interpolated z-buffer value. Note that this attribute doesn't need perspective correction.
pixel.fog contains the interpolated fog value.
pixel.data contains the interpolated attributes.
You must send to JCAB your completed Homework.cpp file according to the instructions.
Extra grade will help you compensate your grade if you don't manage to successfully complete one or more basic assignments.
I will be granting the following:
Download it here.
There are four different solutions in the file:
Barycentric is a simple but complete solution based on looping the bounding rectangle, performing edge tests
and interpolating using barycentric coordinates. It works well, but has a very subtle math imprecision,
which boils down to (a/d) * x + (b/d) * y + (c/d) giving different results than (a * x + b * y + c) / dBarycentricCorrect is basically the same, but with the error corrected.ScanLineFloatPoint is the same as the reference rasterizer.ScanLineFixedPoint is the fastest.