Problem Set 4 - Programming - Computer Graphics | CMSC 427, Assignments of Computer Graphics

Material Type: Assignment; Class: Computer Graphics; Subject: Computer Science; University: University of Maryland; Term: Unknown 1989;

Typology: Assignments

Pre 2010

Uploaded on 02/13/2009

koofers-user-hto
koofers-user-hto 🇺🇸

9 documents

1 / 5

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Problem Set 4
CMSC 427
Distributed April 12, 2007
Due: Thursday, April 26 2006
Programming
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:
A camera with arbitrary position, direction, and orientation
Arbitrary image resolution
Triangle and sphere primitives
Ambient, directional, and point lights
Arbitrary materials defined by a color, Phong exponent, and specular fraction
Diffuse and specular shading, and mirror reflections
Cast shadows
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.
pf3
pf4
pf5

Partial preview of the text

Download Problem Set 4 - Programming - Computer Graphics | CMSC 427 and more Assignments Computer Graphics in PDF only on Docsity!

Problem Set 4 CMSC 427 Distributed April 12, 2007 Due: Thursday, April 26 2006

Programming

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:

  • A camera with arbitrary position, direction, and orientation
  • Arbitrary image resolution
  • Triangle and sphere primitives
  • Ambient, directional, and point lights
  • Arbitrary materials defined by a color, Phong exponent, and specular fraction
  • Diffuse and specular shading, and mirror reflections
  • Cast shadows

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)

  1. Suppose we have a viewer at (0,0,0) looking at a surface located at (1,2,10) and there is a point source of light located at (10,6,5). If the surface reflects light with Phong reflectance, what surface normal would it need to have to produce the brightest possible specularity to the viewer?
  2. Suppose the ground is the y =0 plane. There is an infinite wall whose base is on this plane, along the line described by the equations y=0, and x= 0. The wall has a height of 10 feet, so that its top is described by the line y= 10, x =0. There is a directional source of light, with the direction (cos π/6, sin π/6, 0). a. What is the length of the shadow cast by the wall? We want the distance from the edge of the shadow to the wall (that is, don’t say the shadow has infinite length). b. Suppose the light source is an infinitely distant fluorescent tube. The top of the tube is in the direction (cos (π/6 + π/20), sin (π/6 + π/20), 0). The bottom of the tube is in the direction (cos (π/6 - π/20), sin (π/6 - π/20), 0). There is an equal amount of light coming from every direction between these two. This produces soft shadows when the tube is partially visible from a point. Suppose a point on the ground that is not in shadow has an intensity of 1. Give the intensity of an arbitrary point on the ground ( x, 0, z ).
  3. Suppose there is a white sphere centered at the point (0,0,B) with unit radius, illuminated by a directional light source from the direction (1,0,0). B is some arbitrary, very big number. We are making B big only so that you can assume that all vectors from the viewer to any point on the sphere are in the same direction. We view the sphere from the position (0,0,0). a. Suppose the sphere is Lambertian. If the point on the sphere (1,0,B) appears in an image with intensity 1, what would be the intensity of the point (cos(π/20), 0, B – sin(π/20))?

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.

  1. Instead of a point source of light, let’s imagine a continuous light. For example, consider a line segment of light stretching from (-1,0,0) to (1,0,0). This is a tube that emits a constant amount of light all along its length. The strength of this light still falls off with distance, d , at a rate of 1/ d^2 as it does for any physically real light. a. Consider a surface located at the position (x,0,0), for x>1. Determine the amount of light that reaches this point from our tube of light. b. Explain why this lighting cannot be produced by a single point source of light whose strength drops at a rate of 1/ d^2. Show that it can be produced by a non-physically real point source of light whose strength attenuates at

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?