CS 184: Computer Graphics and Imaging, Spring 2018

Project 1: Rasterizer

Michael Lu, CS184-aaz


Give a high-level overview of what you implemented in this project. Think about what you've built as a whole. Share your thoughts on what interesting things you've learned from completing the project.

Section I: Rasterization

Part 1: Rasterizing single-color triangles

To rasterize a triangle, I iterate over every sample in the bounding box of the triangle, and check if the sample lies within the triangle by comparing the area of the triangle to the area of the triangles created by the new point using a simple shoelace algorithm. This algorithm is no worse than one that checks each sample within the bounding box of the triangle because this algorithm does exactly that.

basic/test4.svg with default viewing parameters

Part 2: Antialiasing triangles

To implement super sampling, I iterate over each sub-sample within each pixel. I added a nested for-loop on the inside of the nested for-loop I used for part 1 to iterate over the sub-samples one pixel at a time. This smooths out the jagged edges along the sides of the triangle that are not accurately represented by a single sample.

basic/test4.svg with 1 sub-samples
basic/test4.svg with 4 sub-samples
basic/test4.svg with 9 sub-samples
basic/test4.svg with 16 sub-samples

Part 3: Transforms

robot doing a handstand

I simply rotated the arms and legs a bit and flipped the robot upside-down to put the robot in a handstand position.

Section II: Sampling

Part 4: Barycentric coordinates

Barycentric coordinates are essentially distances from vertices. For example, in the triangle gradients below, any point within the triangle takes on a color value equal to the weighted sum of the color values of the vertices based on the point's distance from each vertex.

Triangle gradient with RGB colors
Another triangle gradient with different colors
Color Wheel

Part 5: "Pixel sampling" for texture mapping

Pixel sampling is essntially sampling pixels in screen space and then computing and mapping the pixel coordinates to its corresponding uv coordinates on the desired texture. For nearest neighbor sampling, we simply map the pixel coordinates to its uv coordinates and then sample from the nearest texel in the texture. For bilinear filtering, we interpolate using the nearest 4 texels.

The difference between 1 sample and 16 samples is quite apparent, with the one sample pictures being more pixelated then their 16 sample counterparts. The bilinear filtering also contributes to the quality of the photo, although the relative difference between the 16 sample photos is less than the difference in the 1 sample photos.

Nearest interpolation with 1 sub-sample
Nearest interpolation with 16 sub-samples
Bilinear interpolation with 1 sub-sample
Bilinear interpolation with 16 sub-samples

Part 6: "Level sampling" with mipmaps for texture mapping

Level sampling is used when one screen pixel corresponds to multiple texels, usually due to minification of the image; therefore, we compute the uv coordinates of adjacent pixels in the x and y direction and use these points to determine which texel to sample from the texture.

For the most part, improving the anti-aliasing power, by using supersampling, pixel sampling, or level sampling, corresponds to poorer perfomance in terms of computation time and hardware workload.

Level zero with nearest pixel sampling and 1 sub-sample
Level zero with bilinear pixel sampling and 1 sub-sample
Nearest level with nearest pixel sampling and 1 sub-sample
Nearest level with bilinear pixel sampling and 1 sub-sample
Nearest level with bilinear pixel sampling and 16 sub-samples
Trilinear filtering with 1 sub-sample
Trilinear filtering with 16 sub-samples

Section III: Art Competition

If you are not participating in the optional art competition, don't worry about this section!

Part 7: Draw something interesting!