You may find it useful to review Foley, van Dam, Feiner, and Hughes, section 16.5.2 as well as the introductory section of 16.12.
raytrace <scene description filename> <image output filename>The MAX_BOUNCES parameter in the input file specifies the maximum level of recursion for your ray tracer. If this parameter is set to zero, your program should function as a ray caster. Otherwise, your shading calculations will now call the ray tracing routine recursively for a reflection ray and a transmission ray. Each of these rays returns a color to be combined with the local illumination to determine the color returned by the current ray. The specular coefficient and color of the current surface indicate how much of the reflection ray's color may be returned by the current ray, and similarly for the transmission ray. The direction of the reflection ray is just the incident ray mirrored about the normal. The direction for the transmission ray may be computed as described in FVD 16.5.2. In the case of a total internal reflection, simply have the transmission ray return no light.
Recall that the index of refraction determines how much the light is bent during transmission. Assume the index of refraction for the empty space (“air”) is 1.0. Assume that the spheres are solid (not hollow). Further assume that transparent primitives do not intersect each other (i.e. contain one another or otherwise overlap). That would require a more complex algorithm for determining the index of refraction of the current material. Assume that light along the shadow rays is not refracted, but attenuates (filters) the color of the light in a frequency-dependent fashion according to the transmission coefficients and colors of the spheres between the surface and the light source.
A few interesting points to consider. Notice that our index of refraction model is not frequency dependent (all light is bent the same way). Also, our method of filtering the light refracted through the spheres is perhaps more surface-like than solid-like. For light to pass through a sphere, it follows along two transmission rays (e.g. rays T2 and T1 in Figure 16.54 in FVD). Each of these rays is filtered by the object's transmission coefficient and color. Thus the light has actually been filtered twice to pass through a single object. Do not attempt to correct this - simply implement it in the straightforward fashion described in FVD. The Watt/Watt description of transmission rays seems a bit different from FVD. In Watt/Watt, T1 and T2 are considered a single transmission. This avoids the previous anomaly, but it also differs in that it leaves out the local illumination and reflection ray at the junction where the ray exits the surface. It's not clear that either of these methods is more correct, so implement your recursion as described in FVD.
For your reference, a few other indices of refraction:
Dense glass 1.66
As with the first assignment, this assignment includes a sample scene description and the corresponding rendered image. Like the previous sample scene, this sample provides only one small test of your program's functionality. You should test your program on this file as well as many other test cases you devise to ensure that your program functions properly in all tricky circumstances.
# comment lines start with # and may appear anywhere
RESOLUTION: [x resolution] [y resolution]
FIELD_OF_VIEW: <full x field-of-view>
BACKGROUND: <red> <green> <blue>
MAX_BOUNCES: [maximum recursion level]
NUM_LIGHTS: [number of lights]
POSITION: <x> <y> <z>
DIRECTION: <x> <y> <z>
INTENSITY: <red> <green> <blue>
#in other words, one LIGHT…ENDLIGHT block for each light
NUM_SPHERES: <number of spheres>
#similarly, one SPHERE…ENDSPHERE block for each sphere
CENTER: <x> <y> <z>
DIFFUSE_COLOR: <red> <green> <blue>
SPECULAR_COLOR: <red> <green> <blue>
TRANSMISSION_COLOR: <red> <green> <blue>
REFRACTION_INDEX: <index of refraction>
As I described in class, one way you can implement some pretty simple parsing is as follows. Open the file with fopen(). Write a simple procedure to get each line of input. This procedure can include a loop using fgets() to read a line and then test to see if it's all blank or a comment. Return the first non-blank, non-comment line. Use sscanf() to get the useful data out of the input line. sscanf() works in the presence of white space and allows you to check that the expected number of tokens were read. Of course you are free to continue using whatever method of parsing you used in the original assignment assuming that it works and allows the program to be executed with the specified command line.