Repository navigation
Lab 3: Rasterizing a Triangle Mesh
In this lab we will extend our rasterizer from last week to render a full triangle mesh. Concepts include model, view, and perspective transformations, using a depth buffer, and interpolating normals.
Follow the same steps as last week.
For increased performance, change the build configuration in Qt Creator from Default/Debug to Release.
OpenGP defines matrices to perform these transformations:
/// Identity Model Matrix
Mat4x4 model = Mat4x4::Identity();
/// Camera Tranformation
Vec3 eye = Vec3(-0.2f,0.4f,1);
Vec3 focus = Vec3(0,0,0);
Vec3 up = Vec3(0,1,0);
Mat4x4 view = OpenGP::lookAt(eye, focus, up);
/// Perspective Projection
float fieldOfView = 80.0f; // degrees
float near = 0.1f;
float far = 5.0f;
Mat4x4 projection = OpenGP::perspective(fieldOfView, (float)wResolution/(float)hResolution, near, far);Note that if we apply a model transformation, other than pure translation, we will have to compute the corresponding normal matrix.
The normal matrix is the transpose of the inverse of the upper left 3x3 submatrix of the model matrix.
A depth buffer is used to keep track of how close to the camera the previous fragments drawn were, so we know whether a current fragment will be occluded or not.
As per the Phong Shading Model, surface normals can be interpolated over a triangle primitive by using the barycentric coordinates of the current fragment.
Contrast the result with flat-shading.