CSS 451: Programming Assignment #3
RayTracer: Camera/Pixel locations and
Phong Illumination
Due Time: Refer to the course web-site
In this programming assignment we will reinforce our understanding visibility and illumination procedure by completing the implementation of a Maya Plug-In Renderer.
You can either work with the Maya software from our lab (Maya 6.5) or download a trial version (Maya 8.5, trial is only for 30 days) and work from your own machine. In either case, if you have never worked with a commercial animation system before, you should be prepared to work with a highly sophisticated, and often challenging to work with, piece of software. Here are some steps to help you familiarize with different components of this assignment:
1. Learn to use the software: launch the software and watch the “Learning Movies” under (the Help menu).
2. Try out the solution for this assignment (KelvinRayTracer, or krt):
a. Open a test scene, here are four test cases: TestScene0.ma, TestScene1.ma, TestScene2.ma, and TestScene3.ma.
i. TestScene0: simple cone with one light source, renders fast.
ii. TestScene1: 2 objects, when implementing your own ray tracer, when TestScene0 is working this scene is good for initial testing of shadow and reflection.
iii. TestScene2: above scene with two light sources. Renders even slower.
iv. TestScene3: reflective floor with 2 reflective spheres. Use this scene as your final test.
For now, load in TestScene1.
b. Load the plug-in:
i. Download the Maya-Load-Library (mll): either Maya6.5 (MyMaya.6.5.mll) or Maya8.5 (MyMaya.8.5.mll). Save this file to a known location.
ii. In Maya, launch the Plug-in Manager by: Window->Settings/Preferences->Plug-in Manager …
iii. Hit the Browse button and navigate to load in the mll file you just saved.
c. Run the krt, in Maya:
i. Open the ScriptEditor, refer to the following, pressing the button on the lower-right corner will launch the maya script editor for you. The upper-portion of the ScriptEditor is output, the lower portion is for entering script.

ii. In the input portion (lower-half) of the ScriptEditor enter: “krt” and type Enter. NOTICE: Enter is the Enter key on the keypad portion of your keyboard (not the Return key). On your laptop, this is typically: Fn-Return (where Fn is the blue-function key). You should see the image being computed in the upper left window (RenderView).
iii. Options of krt:
1. –s: shadow mode, you should see shadow
2. –r: reflection mode, you should see reflection
3. –w <width> -h <height>: resolution of the image being computed
4. –d: debug mode. You should run the debug mode with very low image resolution, e.g.: krt –w 30 –h 20 –d. Notice lines are drawn to represent the image plane, the viewing direction, and for each of the viewing rays!
iv. Limitation of krt:
1. Geometries: only work with Polygon objects (e.g., does not work with NURBS object)
2. Light Source: only support Direction light (e.g., does not work with point light, or any other lights)
3. Material: only support Phong shader (e.g., does not work with lambert, or PhongE, or Blinn, or anything else!).
4. You are welcome to fix any of this limitations (as extra credits).
d. Unload the plub-in: in Plug-in manager, uncheck the loaded check box. This will “release” the mll file such that you can delete/modify it (e.g., during development you will need to re-compile and override this file).
Maya API SDK
Now that we have some idea on how to load/run/unload a plug-in. Let’s try to compile our own SDK. Here are some steps to follow:
1. Configure your IDE: refer to this simple guide, use your knowledge when following this guide. This guide is written for Visual Studio 2005 with Maya8.5. Use your background and extrapolate this for your own environment. Let me know if you do not know how to follow this guide.
2. Download this started project and unzip.
3. Double click on the .sln file (either 6.5 or 8.5) and you should be able to build.
4. Check to find the result of your build is a .mll file in the main Debug folder.
5. You can load this plug-in by following the above plug-in load/run/unload procedure.
6. This plug-in is also called krt (change it!), try running this plug-in, nothing happens.
You job is to fix this plug-in such that it can render the ray-trace image.
The starter project:
There are 5 classes in the starter project with an additional DebugSupport.h/cpp:
· KRT: This is the main Plug-in class. The main ray tracer body is in:
o KelvinRayTracer::doIt() function. We will go over this in class.
o The rest of the functions are “self-explanatory”. Take a look at these, my advice to you is, you should read this, don’t know what they exactly do, yet, know what these exactly are, and most importantly: I expect you to know how to work with these function, including modify these functions when/if necessary!
·
CIntersectionRecord: a public
utility class for recording/passing/accessing information at intersection
position.
o Constructor:
initialize distance to “very large”.
· CAllObject: this is the class that encapsulates all the geometric objects in the scene. You will be a user of this class. There are only two public functions for you to work with.
o CAllObject::Intersect(): takes a origin and a direction (a ray) and returns a CIntersectionRecord that describes details of intersection.
o CAllObject::Visible(): takes two points and returns a true (for the points are visible to one another) or false (not visible).
· CAllLight: this is the class that encapsulates all the light sources in the scene. You will be a user of this class. For each visible geometry, we will need to:
o CAllLights::InitAllLightsForObject(
thisObject ) – gather all the
lights that will illuminate on this object
o while
( CAllLights::NextLight() ) – while
there are still lights shinning on this object
o get
current light information (position, color, direction) for illumination
purposes.
·
CCameraFilm: this class
encapsulates a finite resolution film on the camera where the image will be
computed. You need to modify the constructor and support one function:
o CCameraFilm::GetEyeRayDirection(x, y) – where
given pixel position (x,y), you need to compute the eyeRay direction!
·
CShadeEngine: this class supports
the computation of a color when given a CIntersectionRecord.
Your job is to complete the implementation of
o CShadeEngine::ComputeShading()
– to probably support reflection, you will call this function recursively!
You will implement a simple Phong illumination model:
I = AmbientComponent + Sum over All Lights{ DiffuseComponent + SpecularComponent] } +
ReflectionComponent
Where:
DiffuseComponent = IL * (N dot L) * DiffuseColor
* Kd
SpecularComponent = IL * (V dot R)n * SpecularColor
ReflectionComponent = Reflectivity * ReflectedColor
IL is the color of each light.
You have to compute the ReflectedColor by
recursively calling CShadeEngine::ComputeShade()
with appropriate parameters. Notice that Maya’s Phong shader does not have the Ks the term.
Here is how the credits are distributed in this assignment:
1. Proper CCameraFilm support: 25%
2. Simple Phong illumination: 20%
3. Shadow Support: 15%
4. Reflection Support: 35%
5. Proper submission + Misc. 5%
Extra Credit:
(10%) Support something extra (require working with Maya API): e.g. support NURBS, support another shader (e.g., Lambert), support another type of light (e.g., spot light).
(10%) Support transparency: do not worry about refraction (talk to me if you want to support this), simple straight-pass through will do.
There are about 100 million different things you can do/improve, if you have intense interests in this area and have nothing to do with your life, we can talk. We can design an entire 5 credit independent study based on improving this assignment. Other examples are: anti-aliasing, texture support, soft shadow, …
This programming assignment will count 14% towards your final grade for this class.
WARNING: The number of lines of code for this assignment is actually quite small. However, if you do not get CCameraFilm support working, you are basically stuck and will receive a zero for this assignment! In addition, working with Maya is intimidating and can be frustrating. PLEASE do start early!
Reference: Under the Maya-Help menu, under “Developer Resources”, the “API Guide” provides tons of information. You may wish to refer the “API Classes” when/if you need help on utility classes like MPoint and MVector. Otherwise, you really do not need to know much about Maya-internals. Read this only if you have time.
Debugging: After you have loaded in your plug-in, you can attach your IDE to the running Maya by:
Debug->attach to process
Now, you can stop and step in your code. Remember to unload
your plug-in in Maya before you try to build!