



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Material Type: Assignment; Class: Computer Graphics; Subject: Computer Science; University: University of Maryland; Term: Unknown 1989;
Typology: Assignments
1 / 5
This page cannot be seen from the preview
Don't miss anything!




Problem Set 4 CMSC 427 Distributed April 12, 2007 Due: Thursday, April 26 2006
For this assignment you will write a simple ray tracer. It will be written in C++ without using OpenGL. For full credit, it must support the following features:
Note that the BMPImage library sometimes has problems with weird image resolutions, so you should stick with either powers of 2 (e.g. 64x64, 128x128, ...) or standard resolutions (e.g. 640x480, 1024x768, ...).
The program must read from the command line the name of an input file describing the scene to be ray traced, the name of the output bmp file, and the image resolution. We have provided skeleton code that parses the command line and the scene input file. We have also provided sample input files, and the output files that the ray tracer should produce when using these as input.
The input file format consists of a series of commands, each followed by a list of parameters. Blank lines and lines beginning with # are ignored. The supported commands are:
Format Example Description
camera eye x,y,z look at point x,y,z up vector x,y,z y field of view degrees
camera 0.0 0.0 0. 0.0 0.0 -100. 0.0 1.0 0.
Specifies the position, orientation, and direction of the camera. The image is defined to be 1 unit away from the camera in the direction the camera is facing. "eye" is the camera's position "look at point" is a point in the scene the camera is pointing at "up vector" gives the camera's orientation "y field of view degrees" is the angle from the top to the bottom of the image in the camera's up and down directions
ambientLight intensity r, g, b
ambientLight 0.1 0.1 0.
Specifies an amount of light that is striking all objects in the scene. Each scene has at most one ambient light.
directionLight intensity r, g, b direction x, y, z
directionLight 0.3 0.0 0. 1.0 1.0 1.
Specifies a light coming into the scene from infinitely far away from the given direction ("direction" is the direction TO the light from any point in the scene). Direction lights can be shadowed.
pointLight intensity r,g,b position x,y,z
pointLight 0.0 300.0 0. 30.0 10.0 -50.
Specifies a point light source located at the given position. Since the light intensity attenuates with distance, you may want to make the initial intensity much larger than 1. Point lights can be shadowed.
material color r,g,b Phong cosine exponent specular fraction
material 1.0 1.0 1.
Specifies the material properties for all triangles and spheres declared after this point in the file (until the next material command). "specular fraction" is the fraction of the final color that comes from the Phong specular highlight and the mirror reflection. The remaining fraction of the final color comes from the diffuse Lambertian shading.
triangle vertex1 x,y,z vertex2 x,y,z vertex3 x,y,z
triangle 5.0 0.0 -50. 15.0 0.0 -50. 15.0 10.0 -50.
Specifies a triangle primitive with the given 3 vertices.
sphere center x,y,z radius
sphere 10.0 5.0 -47.
Specifies a sphere primitive with the given center and radius.
Notes:
One thing you need to be careful of when writing this program is that, due to roundoff error, the intersection distance reported by your intersect routines will be slightly incorrect. This can cause a problem if you shoot another ray from the intersection point, since it might end up intersecting the same surface it's supposed to be coming from. To prevent this, you should define some small constant epsilon (say, 0.01), and assume that any intersections at a distance along the ray less than this are not true intersections and ignore them.
The images produced by your program do not have to be pixel-for-pixel accurate to the example image, although if there's significant deviation you may be doing something wrong. It's also not impossible that there are bugs in the demo program, so let us know if your program is producing different output than the demo that you really think is correct.
Pencil and Paper exercises (5 points each)
b. Suppose the sphere reflects light according to the Phong model. If the point on the sphere (cos(π/4),0,B-sin(π/4)) appears in an image with intensity 1, and a point on the sphere at (cos(5π/16),0,B-sin(5π/16)) appears with intensity .4531, what will be the intensity of a point at (cos(9π/32),0,B-sin(9π/32))? If we were using Gouraud shading, and interpolated the value of the intensity at (cos(9π/32),0,B-sin(9π/32) from the intensities at (cos(5π/16),0,B-sin(5π/16)) and (cos(π/4),0,B-sin(π/4)) how much error would be caused by this interpolation? c. Challenge Problem: Suppose we use Gouraud shading for the sphere, and the material has a Phong reflectance of cos^20 (θ). We have vertices around the equator of the sphere (in the y = 0 plane) every 2 degrees. What is the maximum amount of error that can occur? What is the maximum amount of error that can occur with Lambertian reflectance? If you find it hard to solve this problem exactly, you might want to make some reasonable approximation in the solution.
a rate of: (^2) 0 1 2
a + ad + a d
. How would you choose a 0 , a 1 , a 2 , to model this
light?