Lab02 – Building a Recursive Ray Tracer

top

Lab Adapted from Jenny Orr’s CS 445 Computer Graphics, Fall 2012

Relevant Docs:

  1. Jenny’s Ray Tracing Notes
  2. Simple Ray Tracer Starter Code (SimpleRayTracerPart1-code on Fileshare:  Lab02)
  3. Simple Ray Tracer Code Notes (RayTraceCodeNotesOrr on Fileshare:  Lab02)

Due Dates: 
Part 1:  Thursday, Week 3 Lab, April 17, noon.
Part 2:  Thursday, Week 4 Lab, April 24, noon.
Part 3:  Thursday, Week 5 Lab, May 1, noon.

Goals

  • To understand recursive ray tracing.
  • To learn the basic components of a graphics system.
  • To understand the phong lighting model.

Summary Description

In this lab, you are to implement a simple ray tracer based on the discussion in class.

  • Week 1: It should be able to display several sphere objects which are flat shaded.
  • Week 2: It uses the Phong lighting.
  • Week 3: It implements shadows.
  • Week 3: It implements reflections (using recursion).
  • Week 3: It should contain at least 2 types of objects in addition to spheres (planes, cylinders, cones, etc.)
  • Week 3: It should be able to rotate and move the camera.
  • (Optional) It should have procedural and/or image based Textures

Resources

———————————————————————————————————

Part 1: Due April 17

This week, you are just get the main algorithm working. A sphere is already included. Shading will be ignored.

  • Download, compile and run the skeleton code from the sosoftware fileshare: Handouts/graphics/Labs/Lab02/SimpleRayTracerPart1.  There is a zip file, but you can also just drag and drop all individual files.   It should run but will display a black window.
  • In class, we will carefully go over the code. Make sure you understand what each class does before you continue. A summary of the classes can be found in Labs/Lab02/TheRayTracerCode.pdf.
  • Do the following:
    • Add a Camera class. Camera.h is already provided. You need to add Camera.cpp. Assume the image is stored as a 1D array of GLFloat elements.
    • Complete the implementation of the two functions in RenderEngin.cpp: render_scene and trace_ray.

The resulting image should look something like:
rayTracePart1

Demonstrate your program in lab no later noon on Thursday, Week 3 April 17. No need to turn anything in (yet).

———————————————————————————————————

Part 2: Due April 24

This week, you are to get the shading implemented. Do the following:

  • Complete the Material class so that it includes reflection coefficients (ka, kd, ks), colors (ambient, diffuse, specular), and specularity (for specular component). The methods to include are constructors, destructor, assignment operator, setters/getters.
  • Add a PointLight class which includes a color, location, and intensity. The methods to include are constructors, destructor, assignment operator, setters/getters. In addition, it is useful to have a method that calculates the direction from hit point to this light, where the hit point is passed in as a parameter.
  • In the build method in World, you will need to add PointLights to the scene and also add Materials to the shapes. You also need to make sure that the ShadeRec object that is passed back from the shape’s hit method, includes a link to the shape’s shader.
  • Modify RenderEngine::trace_ray and RenderEngine::calc_shade to determine the Phong lighting equation for the closest hit point.

The resulting image should look something like:

rayTracePart2

 

Demonstrate your program in lab no later noon on Thursday, Week 4 April 24. No need to turn anything in (yet).

 

———————————————————————————————————

Part 3: Due May 1

This week, you should:

  • Make sure that the CalcUVN method works in the Camera class. Use it to change the orientation of the camera. Also try moving the location of the camera.
  • Add several more objects such as a plane and cylinder. Try different locations and orientations of the objects to make sure the intersection calculation is working properly.
  • Add shadows. To do this, do the following:
    • For convenience, add a method to the PointLight class which calculates the shadow ray from hit point to the light.
    • add the method:
      bool RenderEngine::inShadow(Vector3D hit_point, PointLight* light) // called from calc_shade.
      Look at the Ray Trace Notes if you don’t remember what this method is supposed to do.
    • Once you feel the shadows are implemented properly, move your objects and (multiple) lights around to make sure that the shadows work under different conditions.
  • Add reflections. This is done using recursion in the trace_ray method using the variable “depth” to control the number of recursions. You will need to calculate the reflected ray at the intersection. Do the following
    • Add a reflection coefficient (kr) to the Material class.
    • add the method:
      RGBColor RenderEngine::calc_reflected(const Ray& ray, ShadeRec& sr, int rayDepth) // called from trace_ray
    • Once you feel the reflections are implemented properly, move your objects and lights around to make sure that the reflections work under different conditions. Change the depth value to get multiple levels of reflections.

The resulting image should look something like:

Part 3: Shadows onlyShadows and ReflectionsTilted Camera

Demonstrate your program in lab no later noon on Thursday, Week 5 Lab, May 1.

Generate several images showing the different shapes you have implemented with shadows and reflections. Include at least 1 image showing that you can move and reorient your camera. Place these images together with your code in your Cubbie or Workspace for Lab02.