COMP 5812M: Foundations of Modeling & Rendering 2019-2020
ASSIGNMENT 3: 2-D Rasterisation [10 marks]
In this assignment, you will build a simple 2-D rasteriser. We will omit the matrix manipulations for this assignment, and also not worry about perspective-correct interpolation.
Your code should output a set of PPM files representing various stages of the rasterisation process. For details of the PPM format, please see Appendix I or http://paulbourke.net/dataformats/ppm/. You should store a 128×128 image in PPM in 8 bit (1 byte) per channel RGB.
Your input data may be hard coded or read in from file. Since rendering multiple triangles is just a loop, this assignment will focus on rendering a single triangle, with the following attributes:
Vertex Position RGB UV
A (61, 10) (255,0,0) (0.160268, 0.290086)
B (100, 100) (0, 255, 0) (0.083611, 0.159907)
C (25, 90) (0, 0, 255) (0.230169, 0.222781)
a) Set the image to light yellow (255, 255, 192), and render an image with the barycentric coordinates for each pixel mapped to RGB with the following equations: [2 marks]
Clamp all values to the interval [0,255] and save the output in a file called abg.ppm
b) Modify the rendering to demonstrate the half-plane test by setting R to 0 if , to 255 if . Do the same for G with and B with . Output to a file called halfplane.ppm [2 marks]
c) Rasterise the triangle by applying the half-plane test to make the interior black (RGB 0,0,0).
Output the file as triangle.ppm [1 mark]
d) Render the triangle in colour, using barycentric interpolation from the RGB values given and save in rgb.ppm [2 marks]
e) Load the attached image (in PPM format). Use barycentric interpolation to calculate texture coordinates for each pixel in the triangle, then render the triangle with texture and save in texture.ppm. [2 marks]
f) Locate the pixel at coordinates (62, 65). Where on Earth is it? If you calculate it to 6 decimal places, you can tell me the name of the building with some help from Google. [1 mark]
PENALTIES:
Poorly structured or badly commented code may be penalised by up to 25% of the marks available.
Poorly formatted output files may also be penalised by up to a further 25% of the marks available.
Code without a readme or makefile may be penalised by up to 10% of the marks available.
Code that does not compile properly will be assigned a mark of 0, but I will usually give the student one chance to correct this.
DUE DATE: Monday, November 18, 10:00 am
APPENDIX I: PPM FORMAT
PPM is one of the absolutely lowest common denominator file formats for storing colour images. It consists of a short header (in ASCII text) followed by the image itself, with both an ASCII and a binary version. For this exercise, we will only consider the ASCII version.
The header consists of exactly 4 ASCII lines, consisting of:
Line 1: P3 The “magic number” specifying the file type. P3 for ASCII PPM
Line 2: # A line containing any comment you want – it will be ignored
Line 3: 37 34 The dimensions (rows x columns)
Line 4: 255 The maximum data value (i.e. single byte 0-255)
The remainder of the file is the RGB values displayed as integers with whitespace separating them. While it is common to put one row of data per line, it is not required: please do so in your output to make my life easier.
A small file with a red square inset in a blue border could therefore be represented as:
P3
# tiny black square
# 4 4
# 255
0 0 255 0 0 255 0 0 255 0 0 255
0 0 255 255 0 0 255 0 0 0 0 255
0 0 255 255 0 0 255 0 0 0 0 255
0 0 255 0 0 255 0 0 255 0 0 255
Note that I have added extra spaces in this to make the individual values clearer. It would be equally valid to represent it as:
P3
# tiny black square
# 4 4
# 255
0 0 255 0 0 255 0 0 255 0 0 255 0 0 255 255 0 0 255 0 0 0 0 255
0 0 255 255 0 0 255 0 0 0 0 255 0 0 255 0 0 255 0 0 255 0 0 255
or even to put all the data on a single line.