-
Notifications
You must be signed in to change notification settings - Fork 0
Home
This is a basic raytracer made for our Graphics course. It was built on top of a template code provided by the teacher Jacco Bikker (see 'The assignment' page).
NAMES & STUDENT IDS Amber Elferink, 5491525 Miriam Sterl, 5664187
In this folder, there are two folders named: 'MergedAllIncludingAlias' and 'MergedbonussesExceptAlias'. 'Including Anti-Aliasing' contains everything we have made, with a resolution of 1920x1080. Approx Rendertime: 1 minute/frame 'MergedbonussesExceptAlias' contains everything we have made, excluding the anti-aliasing feature, with a resolution of 1024x512. Approx Rendertime: 3.5 seconds/frame
Screenshot
BONUS ASSIGNMENTS We implemented the following bonus assignments in our ray tracer:
- Triangle support. We made a new subclass Triangle of our Primitive class. This class contains a constructor method to create a triangle given its three corners and the material it is made of and a method to calculate the intersection of a ray with the triangle (if it exists). This is done by first calculating the intersection of the ray with the plane the triangle lies in, and then checking if the intersection point lies inside the triangle. To make the triangle implementation visible, we added a reflective triangle to our scene, which nicely reflects the spheres in front of it and the checkerboard floor. It works with diffuse triangles as well.
- Spotlights. To create a spotlight, a subclass was made under the normal Light class. This has the extra member variables direction and angle. When a shadowray reaches the light source, the dot product of the shadow ray with the direction of the spotlight is calculated. If the resulting angle is smaller than the angle of the spotlight, the intersection is lit. Otherwise it is not. This provides a nice round spotlight to light up the spheres.
- Anti-aliasing. Instead of sending one ray per pixel in the Raytracing class, 5 rays per pixel are sent, with a slight offset. The colors that these intersections return, are averaged. This average color is then plotted as the final pixel color on the screen, which gives a smooth result, where normally pixelated edges would be visible.
- Refraction. We added a new type of material, Dielectric, to the already existing materials (Diffuse and Reflective). Using the formulas and discussion provided in the book by Shirley et al. (see SOURCES below for a more detailed description), we added two new methods to the Scene class, namely Fresnel and Refraction. Fresnel calculates the reflectance of the material under the particular angle of the incident ray and then calls the methods Reflection (already implemented for reflective materials) and Refraction. Refraction then calculates the direction of the refracted ray and traces that ray. To make the implementation of dielectrics visible, we added a dielectric sphere with the refraction index of glass to our scene.
SOURCES To implement our ray tracer, we used the following sources:
- The slides from Jacco Bikker's lectures (Lecture 4, 5 and 6).
Of course we used these slides to understand the ideas of ray tracing.
We also borrowed the code provided for the following things:
- finding the intersection of a ray with a sphere and a plane
- setting up the screen (that the scene is projected onto)
- giving the floor a checkerboard pattern (although we altered it a little so that we wouldn't have a middle row with double the normal width)
- calculating the total light transport to a certain point.
- The book used for the course, Fundamentals of Computer Graphics by Peter Shirley et al. From this book, we used the discussion and formulas given in the paragraph about refraction (10.7 in the 2nd edition) to calculate the reflectance of dielectric materials and the direction of refracted rays.
- Triangles: We used the plane intersection method, adapted to check if the intersectionpoint is between the three points. Source of formula: http://geomalgorithms.com/a06-_intersect-2.html
- Anti-Aliasing: Used the concept explained in: https://www.codeproject.com/Articles/19981/Simple-Ray-Tracing-in-C-Part-IV-Anti-Aliasing
You can move around in 3D space by WASD and aiming the mouse, however, due to the framerate, it is very slow.
Still some weird stuff remains: The planes sometimes don't show up, like the current walls in Scene (except for the visible red wall). We have switched off that reflected surfaces show intersections in the debug, so it seems like the spheres don't intersect on the debug, while they do in the program.