CPSC310A Assignment 6 - Lights

Due Monday February 13

Details

Create a C++ program that can produce a ray traced image of a scene containing spheres and colored lights. The light that is reflected off of a sphere, or the illumination, should be calculated using the Phong reflectance model. You should create a light class and an intersection class to help write this program.

Phong reflectance calculates the illumination of a point on an object for each light in the scene as the sum of three different types of illumination. The first, ambient illumination, is calculated with the equation:

Ia = Ka * ia

Where Ka is the material's ambient reflectivity and ia is the light's ambient intensity. The diffuse illumination is calculated with the equation:

Id = Kd * (|L| ⋅ |N|) * id

Where Kd is the material's diffuse reflectivity, N is the normal of the surface of the sphere at the point of intersection, L is the direction from the intersection point to the light, and id is the light's ambient intensity. The specular illumination is calculated with the equations:

Is = Ks * (|N| ⋅ |L + V|)Ns * is

Where Ks is the material's specular reflectivity, N is the normal of the surface of the sphere at the point of intersection, L is the direction from the intersection point to the light, V is the direction from the intersection point to the camera, Ns is the specular exponent, and id is the light's ambient intensity.

If |L| ⋅ |N| is less than 0, then the light is on the back side of the surface and the diffuse and specular illumination should not be added to the total illumination. If there is an object between the intersection point and the light, then the object is in shadow and the diffuse and specular illumination should not be added to the total illumination. Note, you can determine if a point is in shadow by creating an intersection function that returns true if any intersection occurs with a ray and any object in the scene. The ray passed to this function should have the intersection point as its origin, the light vector as the direction, the distance from the intersection point to the light as the maximum parametric distance, and a very small value for the minimum parametric distance.

The location and illumination of a light is specified in a scn file with a line that begins with "light". A light line looks like:

light px py pz ar ag ab dr dg db sr sg sb

Where p is the position of the camera, a is ambient intensity, d is the diffuse intensity, and s is the specular intensity. A scene can contain multiple lights. The illumination at an intersection point is the sum of the illumination of all the lights in the scene.

The scene class intersection method should be modified to return an intersection object. The intersection class represents the intersection of a ray and a sphere. It should have member data for the location of the intersection, the surface normal, the view vector, and the material of the surface. The scene class should also have a function that computes the illumination given an intersection point.

Submission

Tar your code in a file that contains your name and submit it on the course Inquire site.