CPSC 4050 / 6050
Spring 2014
Textured OBJ Viewer
Homework
Assignment 5
Due: Tuesday, April
1, 2014
Problem
Description:
This time you
will upgrade your raytracer so that it can handle more complex
polygonal models from a model description (obj) file, and render
the models as shaded solids. Your program should be able to read a
simplified .obj
file describing the model to be rendered, and any
corresponding .mtl
file. You should be able to render the model from various
points of view using your movable camera, and you should be able
to light the scene with various lights. Use your aesthetic
judgement and experimentation to choose a good lighting setup. Try
to make some good looking images to turn in with your code.
To assist you with this assignment, I have provided an obj/mtl file loader that you
can use as a starting point for your work.
Basic
Requirements:
Your program
should be named objtrace.
The program should have the following command line format:
objtrace model.obj
[nrays] [imagefilename]
The first required command line parameter is the path
to an object (.obj) file which contains a description of the
model to be rendered. The nrays
parameter is optional. It should specify the number of rays
per pixel to use for antialising, with a default value of 1
if the parameter is not included. The
imagefilename is also optional, but if it is present, pressing
the w key should cause the currently rendered image to be saved.
I have supplied models of a cube,
a tetrahedron, a
mug and a skeleton that you can
use. No doubt you can find lots of other models on the web,
or ask your friends in the DPA program or anyone who uses Blender, 3DS Max or Maya to save a model
for you in .obj format.
Your .obj file
reader must be able to minimally handle the following .obj line
types:
v x y z
vn dx dy dz
vt u v
f v1 v2 .... vn
f v1/t1 v2/t2 .... vn/tn
f v1//n1
v2//n2 .... vn//nn
f v1/t1/n1 v2/t2/n2 .... vn/tn/nn
mtllib materiallibname.mtl
usemtl
materialname
When reading the .mtl file to define materials, your reader must
be able to handle the following .mtl line types:
newmtl materialname
Ka r g b
Kd r g b
Ks r g b
Ns exponent
d alpha
map_Kd imagefilename
Your program
can simply ignore any other line type encountered in the .obj or
.mtl files.
The minimal
requirements for the program are to:
- read
any .obj and .mtl files that are correctly formatted, and
build a complete data structure representing the polygonal
object that was loaded (note, you can use my code, which
already does all of this for you)
- be
capable of using either orthographic or perspective viewing (a
"camera.txt" file should specifiy all the camera parameters,
including which projection system to use)
- display
the model properly lit and shaded, using the material
properties from the .mtl file
- if
surface normals are provided for the vertices of a model, use
the Phong approach to normal interpolation to produce a
smoothly shaded image
- display
the model using any texture maps that were provided with the
.mtl file
- use an
axis aligned bounding box to accelerate rendering of your
polygonal model.
Advanced
Extensions:
- Build
and use a BIH Tree acceleration structure to render your
polygonal model.
General:
Please write
the program in C++ , using OpenGL and GLUT graphics routines for
the display. Make sure to put a header in each file of your code
that gives a description of the program or object, your name, the
date, and instructions on how it is used. Please turn in at least
two different images you have made with your renderer.