Computer graphics Programming Assignment 7
In this assignment you will add lights, material properties and recursive ray tracing to the ray caster you have written.
As before, your program should read a file specified on the command line and create an image of the scene described in the file.
In addition to the name of the file, on the command line you should be able to specify the size of the output image, the maximal depth of recursion, and the ray weight threshold.
In addition to the statements described in the previous assignment, we add several new statements, to specify lights and material properties.
light_source { <X, Y, Z> color rgb<R, G, B> }
Where X, Y and Z are the coordinates of the location and R, G, B are the components of the color in the range 0 to 1. For example,
light_source { <3, 5, -6> color rgb<0.5, 0.5, 0.5> }
is a 50% white light at X=3, Y=5, Z=-6.
sphere { <0,0,0>, 1
pigment {color rgb<1.0, 0.0, 0.0> }
}
defines a red sphere.
The color you define is the way you want it to look if fully illuminated.
The parameter is called
pigment because we are defining the basic color the object actually is
rather than how it looks.
We will implement only the simplest pigment type, which uses the color statement to specify the pigment. As in the case of light sources, the color statement has the form color rgb<R, G, B>. In addition, the color statement may have the form color rgbf<R, G, B, F>, where F stands for ``filter'', and determines how transparent the object is; the actual transparency for each color component is determined by the product of the filter value and the color component value. E.g. <1,0,0,0> means an object that allows only the red light through. The default filter value is 0, which means that the surface of the object is not transparent.
finish {
ambient 0.2
diffuse 0.7
phong 0.5
phong_size 25
metallic 1
reflection 0.8
}
Any item can be omitted. When it is the case, it is assigned a
default value. The default values are listed below:
finish {
ambient 0.1
diffuse 0.6
phong 0.0
phong_size 40
metallic 0
reflection 0.0
}
Thus, finish {} is exactly equivalent to the expanded statement
above.
The ambient component has effect only if there is a non-zero
ambient light, which is specified using a special statement like
this:
global_settings {ambient_light COLOR}
where COLOR is of the form rgb <r,g,b> as for a light source.
The default is no ambient light.
sphere{ 1
pigment{ rgbf<1.0,1.0,1.0,0.5> }
interior {ior 1.5}
}
The default ior value of 1.0 will give no refraction. The index of
refraction for air is 1.0, water is 1.33, glass is 1.5, and diamond is 2.4.
For the index of refraction to have any effect, the object should
be transparent, that is, the color in the pigment statement should
have a ``filter'' component different from 0.0.
Further, assume that the direction ti the i-th light source is Li, the direction to the eye (or, in the case of a recursive ray, the incoming direction) is V, the normal is N, and the reflected direction is R.
finish {
ambient kamb
diffuse kdiff
phong kspec
phong_size p
reflection krefl
}
The total red intensity at the point is given by
In the formula above rrefl and rtrans are the red
components of the recursively traced reflected and refracted rays.
Note that for a transparent object (
)
the ambient
component and the diffuse component are attenuated and the specular
and reflected components are not. This is a peculiar POV-Ray feature
and this may be not true in other ray tracers. In addition for the
the specular component is scaled by either mr (the material red)
if metallic keyword is present in the finish,
or by ri (the light red) if it is not.
Implement the basic ray tracing algorithm described in class; for each point, shoot rays to all light sources, the reflected ray (if reflection is not zero) and the refracted ray (if the ``filter'' component of the pigment is not zero). In addition, implement the coordinate-aligned bounding box acceleration, that is, for each finite object (any object excluding quadrics), compute a bounding box (it need not be the smallest one possible); before intersecting a ray with the object, intersect it with the bounding box. Make the code for ray-bounding box intersection as efficient as you can.
The recursive spawning of rays is terminated when the maximal depth specified on the command line is reached, or when the ray weight is below a threshold. The weight is computed as follows: for pixel rays (the rays starting at the camera) it is set to 1. Each reflected or refracted ray is assigned a weight equal to the product of its current weight with the coefficient with which its contribution enters the summation in the lighting equation.