CPSC310A Assignment 11 - Image Map

Due Monday March 19


Modify your C++ ray tracing program to include the ability to render objects with image maps. The color of a surface with an image map is determined by using the pixels in an image that correspond to, or map to, points on the surface of the image.

The Image class should have a constructor that takes a string that represents the name of a ppm file to load a color raster from. Please refer to he ppm file format specification for details on how to read a ppm file.

The Material class should have a member value that represents an image map for a material. Not all materials have image maps, so the member value type should be a pointer to an image that is null when the material does not have an image map. A material in a material library file can specify that its color is specified with an image file with a line that begins with "decal" and looks like:

decal image_file_name.ppm

Where image_file_name.ppm is the name of a ppm file that the material's surface color is mapped from.

The Intersection class should have instance data for the two dimensional map coordinates (u, v) of an intersection point. For a sphere, the map coordinates can be calculated by using the latitude and longitude of the intersection point. For a mesh triangle, the map coordinates can be calculated by using the intersection's barycentric coordinates to interpolate the map coordinates of the three vertices. The map coordinates of a vertex are specified in an obj file with a face line that looks like:

f v1/vt1 v2/vt2 v3/vt3


f v1/vt1/vn1 v2/vt2/vn2 v3/vt3/vn3

Where v1, v2, v3 are vertex coordinate indices, vt1, vt2, and vt3 are vertex image map coordinate indices, and vn1, vn2, and vn3 are vertex normal indices. Image map coordinates are specified in an obj file with lines that begin with "vt" and look like:

vt u v

Where u and v are two-dimensional map coordinates.

The illumination function should be modified to check if the material of the intersection object has an image map. If it does, then the other material properties should be ignored and only the map should be used to compute the illumination. The illumination of an image map is calculated by converting the map coordinates, that range from 0 to 1, to the image dimensions. Fractional pixel coordinates can be either rounded or truncated.


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