This assignment implements realistic metal and glass materials. Typical raytracers will generally perform a simple simulation of reflection and transmission/refraction through a material. Usually, each material will be assigned a reflective coefficient (kr), a tranmissive coefficient (kt) and an index of refraction (ior). When a ray strikes an object that is refractive, two new rays are spawned recursively. One is reflected from the surface, and the other is 'bent' according to the material's ior. The results of these rays are combined together, weighting each ray's contribution by the appropriate coefficients kr and kt. More sophisticated raytracers will also take into account attenuation, that is, the darkening of a ray's contribution as a result of travelling through the refractive object.
Two scenes that demonstrate these techniques were generated before implementing a more complicated reflection/refraction model: Some spheres, and a glass teapot.
Note that the glass in the above scenes do not demonstrate attenuation.
All glass objects have an ior of 1.33, a kt of 1.0, and a kr of 0.25.
Also, the teapot scene has gratutious use of depth of field effects...
A more realistic model can be calculated using a technique developed by
Schlick. Schlick estimates the fresnel equation with a less expensive
equation. When a ray hits a reflective surface, its contribution is
weighted by a function R rather then a static coeffiecient as above.
Schlick's equation:
R=R0(i)+(1-R0(i))(1-cos theta)^5
With metal objects, R0 is the material's reflectance at normal incidence.
With glass objects, R0 is calculated by taking ((1-ior)^2)/((1+ior)^2)
Notice that this equation is dependant on the index i, which is the wavelength of the light.
When a transparent surface is hit, R is calculated as above, and the
reflective ray is weighted by this value. The reflective ray is weighted
by (1-R) times an attenuation function I. The attenuation
function is dependant on distance travelled through an object and is defined
as:
I=I0*e^(k(i)*d)
where I0 is the illumation of the object, k(i) is a 'magic number' imperically
determined, and d is distance.
If k(i) varies depending on frequency, the green edges of a plate of glass can be modelled.
That being said, here are some sample pictures of metal and glass objects:
Notice that in the following scenes, glass objects cast no shadow at all.
This is a collection of metal spheres, the furthest sphere is made of platinum, the middle of gold and the closest of silver.
This is a collection of transparent spheres, the furthest sphere has an ior of 2.1 (diamond), the middle of 1.33 (water) and the closest of 1.45 (glass). The k(i) value of the coeffiecent was given equal weight across the spectra, so there is no 'coke bottle' coloring.
It is interesting to compare the middle sphere of this scene with the middle sphere of the scene using the simpler implementation. The major difference between the two images is that the simpler implementation has a much higher reflectance value (0.25 vs. 0.04). Personally, I find the simpler method more convincing!
To see a larger view of this scene, click
here.
(Actually, the metal sphere in the
larger scene is made of platinum rather than silver...)
Last, but not least, here are two versions of a glass teapot. This teapot was rendered using an 'in development' version of the raytracer at home on my P90. It is rendered using the 'coke bottle' filter, but has incomplete attenuation. (Refracted rays were attenuated, but internally reflected rays were not).
Here is the final version of the teapot. This also has a higher maximum recursion depth (allowing rays to be reflected up to 16 times, rather than the 8 shown above). Compare the pictures and see which you like better. Again, I tend to find the 'simpler' version more pleasing (then again perhaps I have an aversion to the color green?)
This is the same scene as the first glass teapot, but rendered using the 'coke bottle' filter. Again, the ior is 1.33.