GMV Coursework 1

Ray tracing: You are given a functioning ray casting program which computes the ambient, diffuse and specular component of light on a point on an object. You are asked to implement new functionalities to the ray tracer. This coursework has 2 parts.

Part 1: (50%)

 You are required to add shadow rays to ray tracing

  1. Implementing shadow rays requires you to shoot rays from the intial hit point on the object towards each light to test if that point is illuminated.

Part 2: (50%)

You are required to implement recursive ray tracing.

  1. Implementing recursive casting (reflections) requires you to reflect rays from the hit point using the method described in the notes. Note that there is a maximum recursion depth.

Extension:

If you want, you can get extra points by implementing an acceleration method by testing the interestion of rays with bounding boxes of objects, instead of the polygons. You can extend this to the use of a hierarchical bounding box technique to accelererate the computation of the recursive ray tracer.

  1. Create the hierarchical bounding box structure. You can group boxes in a random way. 
  2. Use this structure to accelerate the ray tracing computation.
  3. Update the hierarchical bounding box structure by grouping objects that are near in space and/or with similar size.

Important:

You need to hand in a print out of your commented code (only yours with the context), a short report refering to the technique you use - description of equations if necessary, the choice you made in your algorithm, and analysed results. I.e., you should include some pictures you produced in your report.

These images show the before and after adding ray-tracing:

Question 1+2:

These images are based upon a scene file called complexscene.dat and are rendered using the C++ version. Materials vary from object to object and the lights are point and directional lights. The first image is done with the vanilla code (no shadows or reflections), whereas the second image was created with shadows and recursion (MaxDepth set to 4). You can choose a lower value so that your code runs more quickly. Your result images should look similar to the latter.


 

Java: You can continue from your own code from lab2, or start from the model answer to lab exercise 2. This code can be found here and the Javadoc is available here. Again a ZIP file of the code and documentation can be found here. Copy all the .java files to your home directory. Also copy the simplescene.dat. Compile the java code, and then run by executing "java SimpleRay simplescene.dat".

C++: You can continue from your own code from lab2, or start from the model answer to lab exercise 2. This code can found as a ZIP file of the code and documentation can be found here. Compile the code, and then run by executing "ray < simplescene.dat".

A windows .net version is available here.


Question 1:

The part of the code you must edit is in Scene.java, in the method calculateColour.

Hint 1

Note when tracing towards lights that you want to know if there is an object between the hit point and the light. The easiest way to do this is to set up a ray so that when t=0 you are at the hit point, and when t= 1 you areat the light. If you cast the ray and thefirst intersection point occurs when t>0 and t< 1 then something blocks the light. I.E. Make a ray with

   Origin = p;
   Direction = direction;

BUT do not normalise direction. I.E. at line 134 do not do:

  direction.normalise();

and your test for success will look something like

  if (t > 0)  { 
     if (t <  1) {
     /* In shadow skip to next light */

Note that you still must normalise the direction to the light before doing the specular contribution, otherwise the vector h will be skewed. Think carefully what should happen in the case of directional lights.

Hint 2

In the Question code there is one change from the answer to Exercise 1 - the label "nextlight" has been added in calculateColour (see comment in the code). Look up what "continue" does.


Finally

The software described here and in the associated directories are for your personal use only, and in conjuction with the coursework for this course.

On no account may they be shown or in any way given to any person not on this course without permission from Anthony Steed.

They may be copied to your personal machine for use at home, without requiring permission.

On no account may any aspect of the software be used or modified for use for any commercial reason whatsoever.


Anthony Steed, A.Steed@cs.ucl.ac.uk
Jan Kautz, j.kautz@cs.ucl.ac.uk