Goal: In this assignment you will improve a basic ray tracer to add diffuse reflections.
Submission: Submit your assignment using this Google form.
The main components of this programming assignment are:
- 10% Part 0: properly turned in program
- 30% Part 1: add a colored "Cornell" box
- 40% Part 2: add one-bounce diffuse reflection
- 20% Part 3: add Russian Roulette
- Participation credit: You can receive participation credit (outside of this assignment) for posting your resulting imagery and video, good or bad, on the class forum!
You will only render spheres in this assignment, which are described in an input file. We will test your program using several different input files, so it would be wise to test your program with several such files. The input files describe an array of spheres and one or more lights using JSON. An example spheres file resides at https://ncsucg4games.github.io/prog1/spheres.json, and an example light file at https://ncsucg4games.github.io/prog1/lights.json. When you turn in your program, you should use these URLs in hardcode as the location of the input files — they will always be there. While testing, you should use different URLs referencing files that you can manipulate, so that you can test multiple input files.
All vertex locations are described in world coordinates, meaning they do not require any transformation. The eye is at (0.5,0.5,-0.5), with a view up vector of [0 1 0] and a look at vector of [0 0 1]. The window is a distance of 0.5 from the eye, and is a 1x1 square normal to the look at vector and centered at (0.5,0.5,0), and parallel to the view up vector. With this scheme, you can assume that everything in the world is in view if it is located in a 1x1x1 box with one corner at the origin, and another at (1,1,1). A white (1,1,1) (for ambient, diffuse and specular) light at location (0.5,1,0.5).
You should code this assignment yourself. You may not use others' code to determine the direction of reflection, or sum for light integration. You may use math libraries you find, but you must credit them in comments. You may recommend libraries to one another, speak freely with one another about your code or theirs, but you may never directly provide any code to another student. If you are ever uncertain if what you are contemplating is permissible, simply ask me or the TA.
Remember that 10% of your assignment grade is for correctly submitting your work! For more information about how to correctly submit, see this page on the class website.
Part 1: Add a colored Cornell box, and intersect triangles
Diffuse reflection doesn't work well in an open environment, so add the 1x1x1 box described above into your code, and color one wall red, the other blue. Make sure the light is at (0.5,1,0.5) (just below the box top). You will have to describe the box with triangles, and perform ray-triangle intersection. You may use intersection code you find, and even share your custom intersection code with fellow students. The box should have six sides for reflections, but do not render the side at z=0, so that you may see its interior. Whitted ray tracing is enough to earn this assignment credit.
Part 2: Add one bounce diffuse reflection
Now you will begin sampling the BRDFs at each bounce using path tracing. Sample each pixel 100 times and average the results. Shoot a ray toward one (the only) point light and then sample the surrounding hemisphere once, using a uniform distribution and rejection sampling. At the next intersection, sample the light only, not the hemisphere. Remember to check for shadows when sampling the light. Use the diffuse term (only) of the Blinn-Phong model as your BRDF.
Part 3: Add Russian Roulette
Rather than bouncing once, use Russian Roulette to continue bouncing half the time at each bounce. Weigh the obtained light appropriately.
EXTRA CREDIT GRADING:
Extra credit opportunities include the following:
- 1% Add multiple lights, and weigh their light appropriately
- 1% Add area lights, and weight their light appropriately
- 1% Add the specular term into your BRDF (make sure reflection is always < 1)
- 5% Add transparency with refraction