Rasterizing Lines & Triangles

Due: Nov 18
Part I – Scan Conversion (2D)
In this assignment you will build an application which is able to rasterize both triangles and line segments. You may use any algorithm to rasterize the primitives but you must do the drawing yourself.

Your program should receive as input a file containing list of lines and triangles to be drawn in the given format (described at the end of this document). Each vertex of a triangle/line is allowed to have a different color specified. Therefore you must also implement color interpolation across a line/triangle. The rendered output should be displayed either in a window or as a bitmap as in the previous assignment.

You may assume that vertices lie within the viewport (no clipping is required). However, you will have to be careful to set the boundaries of your viewport so that this invariant is satisfied. Vertices are specified using 2D coordinates, meaning that you don’t have to implement any projection transformations.

Using OpenGL, write a program which draws the same output (lines and triangles with per-vertex color). Compare the OpenGL output vs. the output from your rasterizer.

Part II – Shading (3D)
Once you have 2D scan conversion working, extend your implementation to handle 3D triangles and perform Pong Shading.

You will need to implementView Volume Transformations, i.e. transform every vertex from the eye coordinate frame to the canonical view volume for rasterization. You can implement either orthographic (parallel) or perspective viewing.

You will be given several large 3D models (on the website) to read in (in the specified format) and display the rendered output. Each model will be sized so that it fits within the bounds [-1,1] along all 3 axes. Thus, you will also have to perform a minimal scene transformation in order to place the eye at a location other than the origin so that the whole model can be seen.

Extensions
There are several ways to extend your rasterizer for better results. Document what you have implemented, and be sure to include a sample showing your features off. If you implement any other extensions be sure to document them.
Mandatory Extensions (Optional for 575)
Grad students must implement these, they are optional for 575.
  Phong Shading – Interpolate the normal vector of each vertex across a triangle, using the current normal vector at each pixel to calculate diffuse, specular, and ambient components of the light contribution. You can assume a light source which is overhead (the vector to the light source is always (0, 1, 0).
  Z-Buffering – Maintain a depth buffer (analogous to a frame buffer except that it stores depth values instead of colors) to keep track of the depth at each pixel. Interpolate the Z coordinate (in eye space) of each vertex across each line/triangle and use the current state of the depth buffer to determine the visibility of a triangle at each pixel.
Extra Credit
Optional for both classes.
  Clipping – Clip primitives against the view volume. This is needed for a robust implementation to make sure you don’t draw any pixels outside of the frame buffer.
  Efficient Rasterization – Use improvement such as a span based algorithm to efficiently rasterize the triangles. Be sure to report the speed-up you see.

What to Turn In
Create a webpage with a short write-up and renderings of the sample scenes. Include:
-2D Rasterization Code & Executable
-3D Rasterization Code & Executable
-OpenGL previewer
-Renderings of some of the 2D and 3D sample scenes
Be sure to briefly explain your implementation, and document any extensions you’ve made and provide examples to show case them. You may be asked to demo your program by rendering one or more of the sample scenes to the course TA.

File Format
There are 2 types of file formats provided. The first format is for the simple 2D inputs for part I to test your basic scan conversion. The second format is extended to 3D triangles/scenes. (Note, some files use the Linux line ending convention and may not display correctly in notepad.)

2D Scenes
The input files will be structure in the following manner where // indicates a comment. Each triangle is defined by a list of 3 vertices where each vertex has its own line and consists of 6 floating point values specifying its position and color. Each line segment is defined by 2 endpoint vertices.

//start of file
numTriangles //integral number of triangles in the file (always on first line of file)
//begin a triangle
x1 y1 r1 g1 b1 a1 //vertex at (x1,y1) with color (r1,g1,b1,a1)
x2 y2 r2 g2 b2 a2 //vertex at (x2,y2) with color (r2,g2,b2,a2)
x3 y3 r3 g3 b3 a3 //vertex at (x3,y3) with color (r3,g3,b3,a3)
//end a triangle
//total of numTriangles triangles
numLines //integral number of lines in the file
//begin a line
x1 y1 r1 g1 b1 a1
x2 y2 r2 g2 b2 a2
//end a line
//total of numLines lines
//end of file

3D Scenes
The input files will be structure in the following manner where // indicates a comment. Each triangle is defined by a list of 3 vertices where each vertex has its own line in the file and consists of 10 floating point values specifying its position, color, and normal vector. Each line segment is defined by 2 endpoint vertices.

//start of file
numTriangles //integral number of triangles in the file (always on first line of file)
//begin a triangle
//vertex at (x1,y1,z1), color (r1,g1,b1,a1) and normal vector (nx1, ny1, nz1)
x1 y1 z1 r1 g1 b1 a1 nx1 ny1 nz1
//vertex at (x2,y2,z2), color (r2,g2,b2,a2) and normal vector (nx2, ny2, nz2)
x2 y2 z2 r2 g2 b2 a2 nx2 ny2 nz2
//vertex at (x3,y3,z3), color (r3,g3,b3,a3) and normal vector (nx3, ny3, nz3)
x3 y3 z3 r3 g3 b3 a3 nx3 ny3 nz3
//end a triangle
//total of numTriangles triangles
numLines //integral number of lines in the file
//begin a line
//vertex at (x1,y1,z1), color (r1,g1,b1,a1) and normal vector (nx1, ny1, nz1)
x1 y1 z1 r1 g1 b1 a1 nx1 ny1 nz1
//vertex at (x2,y2,z2), color (r2,g2,b2,a2) and normal vector (nx2, ny2, nz2)
x2 y2 z2 r2 g2 b2 a2 nx2 ny2 nz2
//end a line
//total of numLines lines
//end of file

Example files
Both link provides examples files along with the correct renderings.
2D Files
3D Files
Z-Fighting Example (Check back in a few hours)

About sjguy

Stephen in a researcher focusing in AI, Computer Graphics, and Robotics. He received his B.S. in Computer Engineering from UVa in 2006, and his M.S from UNC in 2009.
This entry was posted in Assignments. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *