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.
You are required to add two components of ray tracing - shadow rays and recursive transmission of light.
These images show the before and after adding ray-tracing:
These images are based upon a new scene file called complexscene.dat (i.e. "java SimpleRay complexscene.dat" if you use java, or "ray < complexscene.dat"). Some materials are different, the lights are both point lights (directional lights would be blocked by the walls). The 2nd image was created with MaxDepth equal to 4. You might choose a lower value so that your code runs quickly.
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".
The part of the code you must edit is in Scene.java, in the method calculateColour.
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< /P>
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 (light instanceof DirectionalLight || (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.
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.
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 Celine Loscos, c.loscos@cs.ucl.ac.uk