Ray Tracer
For CIS 560, I implemented a ray tracer with several rendering effects:
The ray traced scene is created using an architectural floor plan editor. The user designs a floor plan in the 2D window. Then the user can walk around the floor plan in the real time 3D window.
![]() |
![]() |
The user can then create a ray traced image based on the current 3D view.
|
|
The 11,000 lines of C++ code are distributed over 90 source files. The real time engine and ray tracer are encapsulated and not coupled with the floor plan application code. OpenGL is abstracted by use of the IRender interface. The CCamera, CLight, and CMaterial provide abstractions for the camera, light sources and material properties. Of course, these are built by calling IRender
The application code rarely interacts with IRender. Instead it builds primitives such as triangle meshes and spheres, then adds them to the scene. All primitives implement IPrimitive. Primitives that can be ray traced also implement IIntersectable.
CScene owns the primitives, camera and render. It is responsible for drawing the scene and coordinating picking. CScene does some optimizations such as trying to minimize material and texture changes. Though it certainty isn't optimized. In particular it doesn't do any culling or LOD. The public interface for CScene is shown below:
CRayTracer implements the ray tracer. When it is constructed, it is passed the CScene to ray trace, the lighting model to use and the effects (i.e. texture mapping, etc) to perform. IRayTracerEffect helps decouple rendering effects from the ray tracing algorithm itself. The lighting model is also decoupled by use the ILightModel interface. The Phong Lighting Model, CPhongLightModel implements ILightModel:
Images in raw RGB format are read by CRawImageRead, which implements the IImageRead interface. The ray tracer mapping effects interact with the IImageRead interface:
At the lowest level of the engine is the Math namespace. This provides vector classes, intersection tests and other math functions such as computing barycentric coordinates.
Reflective surfaces, translucent surfaces and shadows are classic ray tracer effects. This image demonstrates all three. The sphere is a reflective surface and thus reflects the room surrounding it. The windows are translucent. A positional light is located above the far, right corner. This light creates the shadows.
Mapping effects are also easy with ray tracing. This next image demonstrates texture mapping and reflection mapping.
The maps for this image are:
![]() |
![]() |
![]() |
| Wall Texture Map | Floor Texture Map | Floor Reflection Map |
Using the same exact geometry as the above image, we can apply a different texture and reflection map to come up with this image:
Where the maps for this image are:
![]() |
![]() |
![]() |
| Wall Texture Map | Floor Texture Map | Floor Reflection Map |
The next image uses the above maps plus a bump and translucence map. The bump map creates the holes in the ground without actually changing the geometry and the translucence map creates the effect of the red windows.
The bump and translucence maps used by this image are:
![]() |
![]() |
| Ground Bump Map | Window Translucence Map |
The stone texture is from here and the grass texture is from here. I created the other textures and maps using Paint Shop Pro.
Back - to the main page
Last Updated: 12-25-06