This ray tracer was written in C++ in visual studio 2010. It uses no libraries except for the STL to render out scenes. The program reads in povray scene files that give it the properties of primitives. For example, a primitive might be a sphere located at the origin with a radius of 2. It may then go further and give information on the objects material properties (roughness, reflectiveness, reflectiveness, pigment color, etc) or transform information (such as scale it in the y direction by a certain amount).
After implementing the basic features of the ray tracer I decided to implement texture mapping and normal mapping to objects in the scene. Texture mapping is applying an image file to the surface of a three dimensional object. An example might be applying a texture to a sphere.
This image shows the process taking 2D texture and applying it to the shape based on the current polar coordinates of the sphere. Normal mapping goes a step further by reading a texture file and using the data stored in a particular pixel (RGB) to alter the current normal vector at that point on the object. By altering the normal at each point on the object it allows us to create the illusion of highly detailed geometry. A brick wall (rendered below) will no longer appear as a flat image. When we change the normal we change the way the object is shaded, producing a very real optical illusion of depth to the surface of an object.
A Bounding Volume Hierarchy (BVH) was also implemented. The BVH tree allows us to store all the primitives in a scene into a tree structure. When a ray is searching the scene for an object to hit it no longer has to test every object in the scene. We can eliminate “branches” of the tree as we traverse towards the shape we are looking for. The BVH tree has around a 40x speed up for large scenes.
435 "Planets" in the shape of a bunny. Each is texture and normal maped as a planet.
Close up of planet used in bunny.
Brick texture and normal maped sphere.
Wooden barrel normal and texture maped.
Example of the diffuse brick texture.
Example of the normal map brick texture.
The sphere with only a diffiuse texture. See the difference?.