thumbnail

Drawing Single-Color Triangles

Simple Rasterization

First, for the vertices of the triangle, I compute the difference equations between x and y coordinates. Then I iterate over pixels, calculating pixel coordinates with 0.5 offset, and computing edge equations using difference coefficients (these tell if the given point I’m iterating over belong in each half plane). If it belongs in all 3, or none of the 3, then we color in the pixel.

I take the x and y minimum and maximum coordinates to set bounds for rasterization algorithm

Optimized Solution

Antialiasing by Supersampling

I take the given advice and use a sample_buffer (one that is n times longer where n is sampling rate) Super sampling is useful because its basically calculating detail at a higher level and averaging/distilling it to a lower-res to get a more accurate picture, leading to less jaggies. I looped over pixels, and then over sample space to store results for different samples.

With higher number of super samples, we get better edges, and less “jumps” between values and hence jagged edges

Transforms

I was trying to make the left (facing us) hand wave, while the right hand hangs down.

Barycentric coordinates

“Pixel sampling” for texture mapping

“Level sampling” with mipmaps for texture mapping

Creative Art