(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: