Demo for Project 5


(1)Here is my implementation of RayTrace.java. I added a "flag" in methods object.Shade and surface.Shade(...) to indicate whether or not a ray is inside an transparent object.

If a ray is inside a transparent object, it will be reflected by the inner side of the object, and also refracted into the material outside the object(usually air). The refracted part will be used to do intersection check with other objects. The reflected part will be bounced back and forth inside the object, and when it hits the inner surface of the object, it will be splitted into refracted part and reflected part, and so forth. In current demo, the depth of the recursive tree is set at 4, to save time.

If a ray is inside an transparent object and hits the surface(which is determined by method intersect(...) in object class), it will be used to calculate the optical property of the inner surface of the object, which can include diffused light, specular reflected light from un-intercepted directional or point light sources(no ambient light sources!), as well as reflected and refracted light from other objects, i.e., a recursion. When the ray is outside the object, we also need to include ambient light calculations.

All these concerns have been discussed in method Shade(...) of class Surface in RayTrace.java.


(2)Here are a few tests for refractions and reflections inside a crystal ball:

  • A crystal ball emerged in ambient light. Here is the corresponding data file.

  • A crystal ball emerged in directional light. The light shines from top to bottom. Note that the fuzzier bright spot is in fact the refraction/reflection of light source by the inner side of the ball. You will also see such "reflected(and also refracted)" bright, fuzzier than light source spots in the next few demos. Here is the corresponding data file.

  • A crystal ball emerged in point light source. The point light source is in the front of the ball(near eye). Here is the corresponding data file.

  • A crystal ball emerged in point light source. Note that this point light source is behind the ball. Here is the corresponding data file.

  • A crystal ball emerged in two point light sources, one directional light source, and ambient light. Here is the corresponding data file.


  • (3)Here are another few demos:

  • Here is a ball on top of a pattern. The ball has refraction index of 1.0, so in fact no refraction at all. There is ambient light, a directional light source and a point light source, both shining from left to the ball. Notice the reflections on top of the ball(reflected by inner side of the ball), at the bottom of the ball(reflected by outside of the ball), as well as the image of the pattern behind the ball. Here is the corresponding data file.
  • Here is the same ball on top of the same pattern in the same environment, but for this the ball has refraction index of 1.08, therefore, not like the previous index-of-refraction = 1.0 case, you can see the image of the pattern behind the ball is twisted. Here is the corresponding data file.
  • Here is the same ball on top of the same pattern in the same environment, but for this the ball has refraction index of 1.33, therefore it is a water ball. For this case, you cannot see the image of the pattern behind the ball because large bending angle of the refracted light. Here is the corresponding data file.
  • In this demo, we use the same ball(with index of refraction of 1.08) on top of the same pattern in a different environment, namely we change the background color to red. Note that you see the top reflection and the center refraction images of the pattern become redder, which is because the light through the ball is in fact a mixture of the background color(through reflections and refractions by the inner side of the ball) and the light from pattern.Here is the corresponding data file.