Skip to content

Lab 5: Antialiasing a Rasterized Shape

drebain edited this page Jun 7, 2017 · 2 revisions

Lab 5: Antialiasing a Rasterized Shape

In this lab, you will implement simple antialiasing of a shape that is rasterized in a fragment shader.

The code for this lab is in the 'antialiasing' subfolder of the icg repository. You only need to modify the file ScreenQuad_fshader.glsl to complete the exercise.

Rasterizing an Implicit Shape

The shader code you are given draws a black-and-white outline of a simple shape to the screen. It does this by sampling the implicit function of the shape which takes a position uv in screen space and returns a value that is equal to zero if the point is inside the shape and one if it is outside. By default, this function is evaluated once per pixel, and is used to determine the color of the pixel.

Antialiasing the Shape

The true boundary of the shape is a hard edge: in terms of signal processing, this is a feature with infinite frequency. Because we are sampling this signal at finitely spaced points, aliasing occurs in the form of a jagged edge along the boundary of the shape.

The severity of this aliasing can be reduced by using more than one sample per pixel, and averaging the results of each sample. In the fragment shader, generate a grid of sample points inside the pixel and experiment to see how the visual quality improves when the number of points in the grid is increased.

Note: To generate the sample points, you will need to know the horizontal and vertical resolution of the frame, which are provided in your shader as the uniforms resolution_h, and resolution_w. These values are used to calculate the width and height of a pixel.