Starting from:

$29.99

Assignment 2 – Lighting

Assignment 2 – Lighting

Figure 1: Expected result for Phong lighting model, shadows and reflections.
In this assignment, you will implement the Phong lighting model and add reflections to your scenes. 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 implementations of the plane and cylinder intersections into the files Plane.cpp and Cylinder.cpp. Furthermore,“todo”commentshavebeeninsertedinScene.cpptoindicatewhereyou need to add your implementations. If you already set up a GitHub repository last week to collaborate with your fellow group members, you can just copy the TODO comments fromScene.cppovertoyourrepository(orjustnotewhereyourimplementationneeds
1
to go and get started). In the expected_results directory, we provide the images you should expect your finishedcodetoproduceforasubsetoftheprovidedscenes. Onesuchresultisshownin Fig. 1.
Phong Lighting Model and Shadows
The goal of the first part of this assignment is to implement the Phong lighting model. Follow the explanations from the lecture slides and the formula in Fig. 2. In the file Scene.cpp,youneedtofillinthemissingcodeinthelighting()functiontocompute the variable color.
Figure 2: Phong lighting formula.
Start by computing the global ambient contribution. The result of this step is shown in Fig. 1 on the top left. Then, for each light, add in its diffuse and specular contributions (see Fig. 1 top middle and top right). You will probably find it helpful to review the attributes stored in classes Light and Material. Feel free to use the existing vector functions in vec3.h, e.g. mirror, reflect, norm, dot, and normalize. To add shadows to your scene, discard the diffuse and specular contributions from light sources that are blocked by another object. You can determine which light sources are blocked by generating a shadow ray (see lecture and exercise slides) and using the intersection() function. The expected result is shown in Fig. 1 lower left.
Reflections
Thesecondpartofthisassignmentistoaddreflectionstoyourscene. InthefileScene.cpp, you need to fill in the missing code in the trace() function to update the variable color. Followtherecursiveraytracingalgorithmexplainedinthelectureandthe todo comments in the code. Use the material.mirror to determinehow reflectivethe material isand the function reflect() to compute the reflected ray. Compute the final returned color using linear interpolation: color = (1−α)·color+ α·reflected_color, (1)
2
where reflected_color is computed by recursively tracing a ray reflected at the intersection point (see the exercise slides), and α is the material.mirror property.
Grading
Each part of this assignment is weighted as follows:
• Ambient contribution: 10% • Diffuse contribution: 15% • Specular contribution: 20% • Shadows: 25% • Reflections: 30%
What to hand in
A.zipcompressedfilerenamedto ExerciseN-GroupI.zip where N isthenumberof the current exercise sheet and I is the number of your group. It should contain only: • Thefilesyouchanged(inthiscase,Scene.cpp)andtherequestedprogramoutput. It is your responsibility to ensure that all files that you have changed are in the zip. • Areadme.txtfiledescribinghowyousolvedeachexerciseandtheproblemsyou encountered. Indicate what fraction 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