The past semester I took CS 15-662, which is my first experience with Computer Graphics. I find doing the semester-long project, implementing core code blocks in a 3D software codebase especially challenging but fun. I learned about about antialiasing, mipmaps, half-edge data structures, path tracing and many many fascinating concepts that allowed the birth stunning environment and characters in animations and games.
Part 1 - Draw SVG
The first part of this semester long project is to implement a rasterizer. After setting up the hardware renderer, I was first asked to implement line-drawing and triangle drawing. For line rasterization, I used the Bresenham's algorithm. I started with lines in the first octant and later incorporated lines with slope greater than one or negative slope. For the triangle drawing, I iterated all the points bounded by the three vertices of the triangle, and then performed point-in-triangle test.
The results from line and triangle rasterization were really good, as the two pictures showed. Based on that, I filled the code blocks that allow antialiasing using supersampling. The way to accomplish super sampling is that instead updating the render target directly, the rasterization updates a larger buffer and then resolve the supersample buffer to the render target using a unit-area box filter.
I added a few code blocks so that the program can draw svg files with hierarchies and can respond to viewport transformation inputs, all involving manipulation of the element's transformation.
Besides, I also implemented antialiasing using trilinear filtering. The codebase already has the code to allocate buffers for different level of mipmaps and I filled the content of the buffer using a box filter. During the rasterization, the program first computes which level to sample from the mip-hierarchy, and then performs a trilinear sampling on the previous and next level. After the implementation, the program is able to respond to scale change with nice results.
The final step is to implement alpha blending using pre-multiplied alpha, which allows the program to render shapes with transparency.