The purpose of this assignment is to become familiar with some of the key aspects of ray tracing without yet introducing the full complexity of the task. Here is one way to think about the way ray tracing is being divided up.
From this outline, this first programming assignment deals with the first item and leaves the rest for subsequent assignments.
There are additional notes regarding how to approch this project.
In this assignment you will be asked to implement a simple ray casting algorithm. You will be provided with two input files as:
Your code will generate two .ppm files per camera specification. The first is a color image that for this first assignment will simply color a pixel with the color associated with the object - a sphere. The second is a depth image which encodes the relative distance from the camera image plane to the object.
The object file format entry for a sphere is defined as follows:
s sphere_name X Y Z radius R G B
So, for example, s globe 1.0 2.0 -6.0 2.0 255 0 0
specifies a sphere named globe
at 3D position 1.0,
2.0, -6.0 of diameter 4.0 with a red surface.
As the semester develops other allowable entries will be defined for
other objects. For example, a line in the file beginning with v
will be followed by vertices, a line beginning with f
will
enumerate the vertices defining a face.
The command file entry specifying a camera is:
c camera_name prp_x prp_y prp_z vpn_x vpn_y vpn_z near farThis is more general than what you will be needing in assignment one, and in fact for assignment one you will be given camera specifications such as:
c camera1 0 0 0 0 0 1 4 8The meaning of the terms in this specification will be explained in class as part of our lectures on camera modeling. As will become clear after that lecture, several decisions have been made and are now fixed by this convention. Most important, the focal point of the camera is to be thought of as being placed at the perspective reference point (prp). In this assignmnet the prp will always be at the world origin 0,0,0. Further, the the image plane is a bounded square lying at z=-near and running from -1 to 1 in the horizontal and vertical (x-y) dimensions.
The world to be viewed is actually placed at negative values of z. This at first will seem odd, but it is in fact a very common graphics convention. Note also that objects with positive z values lie on the incorrect side of the image plane to be viewed and so should never be rendered. More specifically, only objects between the near and far clipping planes are rendered.
This specification will be expanded in the next assignment to provide information needed to place a camera at an arbitrary position and orientation relative to a world. For this assignment, the object being viewed is required to exist in the same global reference frame as the camera.
Another command in the command file will actually invoke ray casting:
r scene_name image_width image_height recursion_depthSo, for example,
r scene01 256 256 1specifies image size to be 256 pixels on a side. There is no recuresion in this assignment so recursion_depth doesn’t signify anything for this assignment and is simply set to 1 indicating no recursion.
For each invokation of ray tracing through a command in the command file two output files will be generated for each camera specified.
PPM is an easy format to write: everything is in ASCII, and many image display programs (including xv and gimp, both of which are available on the department machines) read it. It is not as compact as compressed binary formats, but it is convenient for our purposes. Here is an example ppm format image:
P3 2 2 256Every PPM image begins with P3. This tells any reading application to expect an ASCII color image. The next two values (2 and 2 in this example) are the width and height of the image, measured in pixels. The next value (256) tells the system to expect 8-‐bit pixel values. This value should always be 256 for the purposes of CS 410.
What remains it to give three values for every pixel. In the example, a 2x2 image has only 4 pixels, which means the system is expecting 4x3 = 12 values. The three values are the red, green and blue color values for a pixel. Note that in ppm, the first three values will be displayed as the pixel in the upper left of the image. If the image is w pixels wide, the first w pixels form the top most row of the image, running left to right.
You should create the code required to intersect a ray emanating from camera position, passing through image plane, with every spheres in the scene model you have loaded from .obj file. You should consider only nearest intersection and assign color_value of that surface to that pixel for color image and depth_value of that surface to that pixel for depth image.
Here color value RGB is given for each sphere. To calculate depth value you need to find the distance of intersection point from near and far clipping point. And simply put the value of R,G,B as:
R,G,B= 255 - (min(255,255*(Distance between pixel point and point of intersection)/(far_value-near_value)) )The depth image will be a gray scale image. For simplicity, this will still be stored in PPM format with R=G=B.
The camera is looking in the negative z direction. The center of the image plane is at the 3D point 0, 0, -near in camera coordinates - which for this assignment is the same as world coordinates. The bounded image plane goes from (-1, -1, -near) to (1, 1, -near). You need to interpret this canonical viewport in terms of actual pixels. It means you should map your (row_pixel, column_pixel) in between (-1,-1) and (1,1). (More details will be provided in lecture).
Camera sees object only between near clipping plane and far clipping plane for the depth image. This constraint will be maintained for both the color and the depth image.
Here is an example pair of object and comannd files.
Generated output Images are attached here for example01.
Your code will be evaluated on similar but different input files.
Use the RamCT to submit your work for this assignment. Here are further instructions:
All grading is done on department Linux machines. When your tar file is unpacked into a clear directory and the GTA types make your code should compile an be ready to run. You must inlcude a README file with full instructions for running your program. If you forsee a problem meeting this requirement due perhaps to your choice of language you must make prior arrangements with the instructor and GTA.