
Spring 2007
22C:251 Advanced Computer Graphics (Image Synthesis)
Assignment 2
Due: Before class on Tuesday, February 27th
Goal: Implement basic ray packets to improve ray tracing performance. To improve realism, implement a basic naive
path tracing algorithm for diffuse surfaces.
Problem 1: (25 points) Implement packets in your ray tracer. You must profile your code before and after to see
where the speedups come from. Make sure to post profiling data on your web page. Everyone must do the following:
1. For each function or method that takes a “Ray &” or “Ray *” or “Ray” must be duplicated and implemented
with a “RayPacket &” or “RayPacket *” or “RayPacket”.
•This is a good time to replace any pass-by-value methods with a pass-by-reference method. You do not want to pass
a RayPacket by value.
•If you don’t know where all these methods are, do a search for “Ray” inside all the header files.
•If you cannot think of a good way to implement a particular function using packets, you may trivially degenerate the
packet into individual rays.
•I’m curious what the overhead cost of a completely naive packet implementation (i.e., that degenerates to individual
rays for all functions). Kudos for those who profile and benchmark such an implementation.
2. Particular functions that may not degenerate to single rays include:
•PinholeCamera::GenerateRay() (Note: You may rename the packet version, if you wish.)
•Scene::TraceRay()
•Scene::TraceShadowRay()
•Group::Intersect()
•BVH::Intersect() (Only the “best” BVH is required, if you have more than one.)
•LambertianMaterial::Shade()
3. Encouraged, but not required: Do not degenerate for Triangle::Intersect(). At least copy/paste the code from
Triangle::Intersect( Ray &r ) into a for loop inside Triangle::Intersect( RayPacket & r ).
Groups must also do the following:
1. Implement a command-line parameter and/or a scene file command that allows a user to run your ray tracer in
either single-ray or ray-packet mode. Also implement a key binding in the the OpenGL mode to switch back
and forth between the two modes. (I suggest you have two display() routines, one of which implements each
mode. Then your keystroke can just call glutDisplayFunc() to switch.)
2. None of your primitive (e.g., Triangle, Sphere, InfinitePlane) intersection or normal computation methods for
packets may degenerate by calling their single-ray counterparts.
3. Test performance using a variety of packet sizes. Post speeds and profiles on your web page.
•If you are using masking, test packets of the following sizes: 1, 4, 16, and 32 (i.e., 1×1,2×2,4×4, and 8×4).
•If you are not using masking, test packets of the following sizes: 1, 4, 16, and 64 (i.e., 1×1,2×2,4×4, and 8×8).
•A single #define should allow you to switch between different packet sizes.