$29
The goal of this project is to write a ray tracing renderer. Your program should be able to read scene data from a text file according to a defined scene description language. From this, your program will then render an image of the scene and write out the image to a file. This is the first half of a two-part project which will accomplish this objective. For this first part you will cast eye rays into the scene for each pixel, test these rays for intersection with sphere objects, and then use the diffuse shading equation to find the color for each pixel. In the second half of the project you will expand your Ray Tracer to detect intersections between rays and cones. You will also expand your shading function to include ambient and specular color as well as cast shadows and reflection. Keep this in mind when deciding on implementation details.
You have four primary goals for the first part of this project:
1. Initialize the scene
2. Cast eye rays for each pixel
3. Implement detection of ray intersection with spheres
4. Implement the diffuse shading equation
Project 3B: Ray Tracing Spheres
The goal of this project is to complete your ray tracing renderer. In this project you will expand your ray tracer from part 3A to detect intersections between rays and cones. You will also expand your shading function to include ambient and specular color as well as cast shadows (via shadow rays) and reflection (via recursive ray casting).
You have four primary goals for this second part of the ray tracing project:
1. Detect ray/cone collisions.
2. Expand your shading function to include ambient and specular lighting.
3. Cast shadow rays to determine when a light should contribute to the color.
4. Implement reflection by recursively casting new rays into the scene from inside your shading function.
Scene Description Language
Each scene is described in a .cli file using the grammar described below. These files are contained in the /data folder from part 3A. The suffix “cli” stands for “command language interpreter”. Note that the .cli files are plain text files, so you can look at the commands in them using just about any text editor. Below are the commands that you should implement for this assignment. You should have already implemented several of these commands to complete part 3A, so you really only need to concentrate on "cone" and "surface".
fov angle
Specifies the field of view (in degrees) for perspective projection. You will need to convert this to the focal length d. You will then use this together with the eye position and the u, v, and w vectors to create the eye rays.
eye x y z
Specifies the eye position in 3D coordinates.
uvw ux uy uz vx vy vz wx wy wz
Specifies an orthonormal frame of vectors u, v and w that describe the camera's orientation.
background r g b
Background color. If a ray misses all the objects in the scene, the pixel should be given this color.
light x y z r g b
Point light source at position (x,y,z) and its color (r, g, b). Your code should allow up to 10 light sources. For the second part of this assignment, you will cause these lights to cast shadows.
surface Cdr Cdg Cdb Car Cag Cab Csr Csg Csb P Krefl
This command describes the reflectance properties of a surface, and this reflectance should be given to the objects that follow the command in the scene description, such as spheres and cones. Note that for this second part of the assignment, you need to add ambient, specular, and reflective terms. The first three values are the diffuse coefficients (red, green, blue), followed by ambient and specular coefficients. Next comes the specular power P (the Phong exponent), which says how shiny the highlight of the surface should be. The final value is the reflection coefficient (0 = no reflection, 1 = perfect mirror).
Usually, 0 <= Cd,Ca,Cs,Krefl <= 1.
sphere radius x y z
Create a sphere of a given radius with its center at (x, y, z).
cone xb yb zb h k
Specifies the creation of a cone with its axis aligned with the y-axis, and with a base (the sharp point of the cone) at the position xb, yb, zb. The height of the cone is given by h. The factor k specifies how quickly the cone widens. The equation for the cone is: (x-xb)^2 + (z-zb)^2 = (k(y-yb))^2
write [filename].png
Ray-traces the scene and saves the image to a PNG image file.