In the first assignment, you wrote a code to read and manipulate a 3D model from a file in obj format. For this assignment, you will take the first step in rendering a scene with multiple objects and a light sources. More precisely, you will write a program that reads 3D camera specifications and one or more spheres defined in a driver file. To render a colorful scene, you will also read light source specifications and material properties of the objects. You will be asked to demonstrate that your ray casting system is capable of rendering the scenes described in the driver files given to you.
Your illumination model in this assignment will only include ambient and diffuse components. Also, you are explicitly not being asked to perform recursive ray tracing nor are you being asked to handle semi-transparent objects. In other words, no light refracting through spheres. You may anticipate these as additions later in the semester. You will also not be expected to calculate ray-triangle intersections, so there will only be spheres in the driver files with no .obj models.
Your program will take in two command line arguments. The first argument is a driver file containing the camera description and a list of spheres along with their material properties. The second argument is the name of the image your program will write back to the disk in the same folder where your executable is located. A C++ example is:
$./raytracer driver00.txt driver00.ppm
Your program will implement the camera model by throwing a ray from each camera pixel on the near clipping (image) plane and determining the closest surface, if any, which lies in the path of the ray. Presuming the ray intersects a surface, then the pixel should be set to a color value determined by the material properties and lighting specifications in the scene. Should a ray fail to intersect any polygon then it is given a default background color; for this assignment set this default to black, (0, 0, 0). Your program will then write out the resulting image as an ASCII PPM color image (P3 format, details provided below) to the filename in the second argument passed to your executable.
The driver file, as you may have figured out, is specific to this class and this semester of CS 410. Modifications have been made to the driver file for this assignment to support camera specifications, scene lighting, and spheres. Here is an example of a driver file for this assignment.
# you may include comments here
camera 25 25 60 25 25 10 0 1
0 -10
bounds -1 1 -1 1
res 256 256
ambient 0.2
0.2 0.2
light 5 32 30 1 0.5 1.0 0.5
light 45 32 30 1
1.0 0.5 0.5
sphere 25 25 10 4 0.2 0.2 0.2 0.7 0.7 0.7 0.5 0.5
0.5 1.0 1.0 1.0
camera ex
ey ez lx ly lz ux uy uz a
. Note the first 9 arguments are
logically grouped into triplets, where triplet 1 ex ey ez
represents the location of the focal point (the eye) with ex, ey,
and ez coordinates. The next triplet lx ly lz
represents location of the look at point with lx, ly, and lz
coordinates. Finally, the triplet ux uy uz
is the
direction of the up vector with ux, uy, and uz coordinates. The
tenth argument, a
, is the position of the near
clipping plane in camera coordinates. Pay close attention to that
last bit of wording. In keeping with our approach to camera
modeling in CS410, a
will always be entered as a
negative number.
bounds left right bottom top
The minimum and
maximum extent of the bounded image rectangle in the horizontal and
vertical directions (i.e. the near clipping plane bounds) res width height
The resolution of the image in
pixels. One feature of this specification format is that you can
generate intermediate cameras with low resolution, say 8 by 8 or
even 4 by 4, when developing and debugging code. This speeds
development considerably. Do note that the dimensions of your
output image must match the resolution specification exactly; no
off by one errors allowed.
ambient e_r e_g e_b
Ambient light with red
(e_r), green (e_g), and blue (e_b) levels.
light x y z w e_r e_g e_b
This specifies the
location of the light (x, y, z) and the emittance in red, green,
and blue (e_r, e_g, e_b) of the light. The emittance values are
between 0 and 1. The fourth value, w, is generally one, but a zero
indicates a light source at infinity in the direction specified by
x, y, and z. Implementing behavior for a zero w is not necessary
for this assignment (but may be for future assignments). There
will be one or more of these lights
sphere x y z r Ka_r Ka_g Ka_b Kd_r Kd_g Kd_b Ks_r Ks_g
Ks_b Kr_r Kr_g Kr_b
This specifies the location of the
sphere (x, y, z) and its radius (r). The K values correspond to
different kinds of reflectivity. Ka values are the amount that
ambient light is reflected. Kd values are the amount that diffuse
light is reflected. Ks values relate to specular lighting. Kr
values relate to attenuation. For this assignment, specular and
attenuation (Ks and Kr) values will not be used.
In this assignment, you will not encounter any polygonal models. Later assignments will include the creation of code to display models based on their material properties.
Images should be written as legal ASCII PPM files. Although some variations are permissible, I recommend the following. The first line contains the characters P3 and nothing else. The next line contains the image width, the image height, and the number 255 (the maximum possible pixel value), all integers. Pixel values begin on the next line, and contain 3 values per pixel (a red value, a green value, and a blue value, in that order). Since the total number of pixels in an image is width times height, the number of values in the file (after the two header lines) must be 3 times width times height. To make images “readable” by humans (when they are small), you will want to put a newline at the end of each row. The image generated from this driver file might therefore begin with:
P3
256 256 255
239 239 239 239 239 ...
In this assignment you will construct code to render scenes as specified in the format laid out above. You may write your renderer in either C++ or Java. You may not build your rendering program in Python. You are being provided two driver files to get you started.
Your code should work properly for these two driver files. It should also handle additional cases. In all cases the camera view, lighting, and model transformations and placement should result in a well rendered final image. The image should be written in PPM format as described above. The example output may be downloaded here.
Here are three additional examples you may use to test your code (10/20/2020)
Submit a tar file via the CANVAS assignment page that includes:
If you are using C++, your executable should be named 'raytracer'. If your are using java, the main executable class should be named 'Raytracer'. Notice the change in case for the first letter between C++ and Java. It is must for this assignment to take exactly two arguments as described above.