Starting from:

$29.99

Assignment 3 – Raytracing Meshes


Introduction to Computer Graphics
Assignment 3 – Raytracing Meshes

Figure 1: Expected result for ray tracing toon face triangle meshes.
In this assignment, you will implement ray tracing for triangle meshes. The framework code for this assignment extends the one from last week; if you download a fresh copy from Moodle, you will need to copy your solutions from the lighting assignment into the file Scene.cpp and also move over your ray-cylinder and ray-plane intersections from Assignment 1. Furthermore,“todo” comments have been inserted in Mesh.cpp to indicate where you need to add your implementations. If you already set up a GitHub repository to collaborate with your fellow group members, you can just copy the TODO comments from Mesh.cpp over to your repository (or just note where your implementation needs to go and get started). In the expected_results directory, we provide the images you should expect your finishedcodetoproduceforasubsetoftheprovidedscenes. Onesuchresultisshownin Figure 1.
1
Vertex Normals
The starting point of this assignment is the compute_normals() function in the file Mesh.cpp. Here,youwillhavetocomputethevertexnormalsweightedbytheopening angles. Before you start implementing this function, thoroughly study the file Mesh.h, making note of the member variables and methods and understanding the purpose of each one. Also check how functions Mesh::read(), angleWeights(), and function Mesh::intersect() are implemented in Mesh.cpp. Compute each vertex normal n(Vik) as an average of incident triangles’ normals n(Ti), weighted by the opening angle wk(Ti).
Tomakeyourimplementationmoreefficient,insteadoftraversingthroughalltheneighboring triangles of each vertex, you should loop through all the triangles of the mesh, visitingeachtriangle Ti onlyonce. ForeachvertexVik ofthetriangle Ti,addthecontribution wk(Ti)n(Ti) to the normal of the vertex Vik (see the exercise slides). Use the function angleWeights() to get the weights wk for each triangle. After all triangles are visited, you should normalize all computed vertex normals.
Ray-triangle Intersection
Thesecondpartofthisassignmentistoimplementtheray-triangleintersectionpresented in the second lecture using the explicit barycentric coordinates representation (see also the exercise slides and formula below).
Use Cramer’s rule to solve the above system and follow the comments in Mesh.cpp to add the missing code in intersect_triangle(). In certain scenes, some objects should be flat shaded (e.g., the desk in the office scene) whileotherobjectsshouldbePhongshaded(e.g.,thechairs)toappearmorerealistic. This
2
differenceliesinhowthemesh’ssurfacenormalvectorn(x) iscomputedforlightingthe point x. A member variable draw_mode_ read from a scene file determines whether an mesh object should be flat shaded or Phong shaded. For flat shaded meshes, the intersection normal is simply the normal of the intersected triangle. For Phong shaded meshes, you should use the normal interpolation formula below to compute the normal n(x) at intersection point x (interpolating the intersected triangle’s three vertex normals).
Here α, β and γ are the barycentric coordinates of x computed with Cramer’s rule, and n(A), n(B) and n(C) are vertex normals of vertices A, B, and C respectively. Be sure to normalize your normal vectors after interpolating them.
Efficient Ray-Mesh Intersections
To accelerate rendering, you will need to implement the bounding box test for triangle meshes. Fill in the missing code in Mesh::intersect_bounding_box(). This function should check whether a ray intersects with the current mesh’s bounding box. Each mesh’saxis-alignedboundingboxhasalreadybeencomputedbyMesh::compute_bounding_box() (youdonotneedtoeditthis),andtheboxcornersarestoredinclassmembersMesh::bb_min_ and Mesh::bb_max_. Youwillusethesetwoboundingboxcornersinyourintersection implementation.
Figure 2: Axis-aligned bounding box example.
To check if your ray-box intersection implementation is correct, we provide another executable, debug_aabb, which visualizes the bounding box intersections for all meshes inascene. Ray-boxintersectionpointsarevisualizedinred,andthebrightnessindicates how many bounding boxes intersect with the ray. Run ./debug_aabb 0 and compare your output images with the ones provided in expected_results.
3
Parallelization
(NOTE: this section is optional, and it is NOT graded.) To render even faster, you can use multiple cores of your machine to trace rays in parallel. You can do this with either OpenMP or TBB. On Linux/GCC, OpenMP should just work without any additional libraries. On macOS, only the latest versions of Clang support OpenMP, so you may be better off installing TBB. TBB can be installed from your package manager (e.g., apt on Ubuntu, MacPorts or Homebrew on macOS), or directly from the official release page (https://github.com/01org/tbb/releases).
Grading
Each part of this assignment is weighted as follows:
• Vertex normals: 20% • Ray-triangle intersection + normal calculation: 50% • Bounding box intersection: 30%
What to hand in
A .zip compressed file renamed to Exercisen-Groupi.zip where n is the number of the current exercise sheet and i is the number of your group. It should contain only: • The files you changed (in this case, Mesh.cpp) and the requested program output (in this case, rings.png, mask.png, and office.png, along with their debug_aabb variants). It is your responsibility to ensure that all files that you have changed are in the zip. • A readme.txt file containing a description on how you solved each exercise (use thesamenumbersandtitles)andtheencounteredproblems. Indicatewhatfraction of the total workload each project member contributed. • Otherfilesthatarerequiredbyyourreadme.txtfile. Forexample,ifyoumention some screenshot images in readme.txt, these images need to be submitted too.

More products