Raytracer

A "simple" raytracer was implemented as a project during a course at DTU (Danish Technical University). It is simple because it is designed for small scenes with very few objects. That means that no scene graph is built and every object is tested for collision with every ray. It is also simple because there are no soft shadows as well as no photon mapping. It is non-simple because of the textures and the CSG-implementation.



Geometrical shapes

Only spheres and planes are currently supported. You can define a plane by a point in the plane and its normal vector. A sphere is defined by a point and a radius.

Ordinary tracing

Phongs reflection model is implemented. There is light and shadow as well as refraction when the ray passes through a boundary with different index of refraction on either side.

Light sources

Only point lights are implemented. They can have different colors and intensities.

Colors

When the scene is calculated, a homemade class (RealColor) is used to allow the color intensities to be any real valued number. This is for hight dynamic range HDR rendering. When the result is then displayed on screen, different methods of conversion into the range 0..255 can be used. Clamping and scaling are among the methods. The examples are rendered using simple clamping.

Constructive Solid Geometry

CSG is implemented. This means that relatively complex models can be generated by the binary operators AND, OR and NOT. The classes are written to allow for operations such as Something=(sphereA+sphereB)-planeA AND sphereC. This makes it extremely easy to define new models. A CSG can be used resursively in such expressions again.

Textures

There is support for loading of textures, which can be bound to objects such as planes, spheres and CSG. Textures can be planar or spherical. All textures are projected onto the surface of the geometry and while planar textures project in parallel rays, the spherical texture project out from a point.
Textures can be used as both diffuse color and reflectivity. This way a globe can be textured to show the land and ocean while another reflectivity texture defines that only the oceans reflect other objects.

Anti aliasing

This is implemented through super sampling. Each pixel results in 4 rays rather than just one, and the average of the four is used as a final color.

Camera 

A flexible camera is defined. It allows for easy placement and resizing of the render area (number of pixels)

The demo program

The demo is just to show what the tracer can do, and what it cannot. It lets you select among eight predefined scenes and render them with and without anti aliasing. To actually play with the tracer, you might want to edit the code which defines the scenes, or just yank out the relevant classes.
If the program does not work on your windows(!) system with the .net 2.0 framework, then please let me know.

The source

The source could have used a little more time for cleaning, but there was a deadline, and after that deadline I didn't really want to bother with it. The code was written to prevent "side effects" in the code, which in short means that no method can change a class, only return a new class with the changes. This is often a good idea, but when you need optimal speed, it is not really the way to go.

Downloading

The project with textures can be downloaded here.


Some images from the raytracer. 

They are commented in Danish to point out things of special interest.









ċ
raytracerSmall.zip
(7343k)
Thomas Grønneløv,
Apr 12, 2011, 12:19 PM