Rasterization in DrawSVG
In this project, I implemented a simple software rasterizer that draws points, lines, triangles, and bitmap images.
The whole project and codes can be downloaded from my Github repository.
without supersampling

with supersampling

Super Sampling
In this exercise, I used grid algorithm to determine sample positions. Color samples are taken at several instances inside the pixel when rasterizing primitives such as triangles.
Rather than directly updating render_target, I updated the contents of a larger buffer that holds the per-super-sample results. Then I calculated the average color value and fed it to the pixel.
With supersampling, jagged and pixelated edges are removed and the triangles look smoother.
original image
Texture mapping and Anti-Aliasing using bilinear interpolation
In this task, I assigned color components to pixels with a simple function called sample_nearest(), which looks at the pixel position and converts it to UV coordinate, and grabs the nearest texel. However, this method has a problem. If we are getting closer and closer to the object with texture, the image will become blockier and blockier, and eventually, we will see a colossal color block.
With bilinear interpolation, each pixel will pick the color value generated by bilinear interpolated the four texels around it, which gives a smoother result.


zoom in with nearest sampling

zoom in with bilinear interpolation

zoom in with bilinear interpolation

zoom in with trilinear interpolation

Trilinear Interpolation
Bilinear interpolation is excellent. However, it still has limitations. If the viewer is far from the textured object, they will see artifacts like jagged lines. Thus, trilinear interpolation with prefiltering is introduced.
Prefiltering is just pre-computing the mipmaps of the corresponding texture and assessing which mipmap to use based on the current size of the object.
Trilinear interpolation is adding another linear interpolation by interpolating the current mipmap with the upper level mipmap.
With trilinear interpolation, the result looks much smoother.
Without Alpha blending
Alpha blending
Project Name
Alpha blending is another crucial part when doing rasterization. As we can see from pic 1, an SVG file cannot be semi-transparent without alpha blending because pixels will obscure each other.
By introducing the alpha blending function into the system, rasterized pixels can be transparent and blend into each other during rasterisation.


With Alpha blending