Make your own free website on
These are raytraced images. The first image shows ambient, diffuse and specular lighting and shadow. Specular is 32nd power and uses true reflection vector not half-angle vector. The floor is also lit diffusely and the light isn't attenuated. The sphere has 10% yellow ambient in it. The shadow is darkened by 50%. The second image is only diffusely lit but I played with the math a bit and was able to create the nice gradient background. Both of these images were drawn directly into a raw image file instead of using 3D api to draw them. Drawing of the 640x480 image took about 2 seconds on 1ghz cpu and in debug mode. The code isn't optimized. Raytracing is easy and fun to do.

I rewrote the raytracer so that it now uses recursive reflections and OpenGL lighting equation except for attenuated lighting, spotlights and directional lights. The pic shows a hollow box with a red floor and mirror walls and ceiling. The two balls are blue and they reflect the scene around them. The shadows are attenuated. The raytracer is not realtime but it's pretty fast. I used a mix of procedural and object oriented techniques. OO made it more intuitive but there is also a possibility for an overhead especially with operator overloads. So those parts are done in procedural eventhough OO would make code writing easier because the syntax is more straight forward. All the calculations are done in software on the cpu even color conversions to rgb. The calcs. are done in float then during conversion if any color value is above 1 all the rest are scaled by it to prevent color oversaturation. Then the final rgb color is passed to opengl for rendering. I use single frame buffer, no stencil nor depth. After each pixel is written to the screen I glflush the pipeline otherwise some scanlines might not become visible. There are some tricky parts in the code like epsilons to monitor closeness of objects to each other and for the shadows so they don't leak from under the object when it's touching the floor for example. The rest of the code is pretty straight forward and it's like 1,000 lines total. It took me about four days from knowing nothing about raytracing to the final result you see here. I have one more feature I like to implement which are refractions or light bending as it passes thru a medium like water or glass. I've seen some pics of this at and it looks great.