|
|

|
I programmed a simple little raytracer in Amiga Basic in my last year at high school. While reading about vectors, it suddenly dawned on me that the stuff I was learning could be used to create 3D images similar to the software I had on my Amiga. However, if I programmed a renderer myself, I might add some new features that I wanted to try out! I dropped out of math and failed my exam because of the time I spent doing this, but it has been vital for my later 3D work. Knowing how 3D software works "under the hood" is a real advantage when you are solving problems or trying to come up with a new effect.
|



The math behind a raytracer is beautifully simple, and you just need some basic vector and programming skills to make a simple raytracer. For anyone interested (and if you work in 3D you should be!) let me spend a couple of lines to explain how a raytracer works.
Raytracing, as its name suggests, is a way of drawing an image by collecting pixel data from shooting rays inside a virtual space. Here's how that works. You shoot a ray (or a vector) from the position of the camera to the first pixel on your screen. You then check if the continuation of that vector hits an object, for example a sphere. If it hits, you trace another vector to the position of the light source, and with some more math you figure out the light intensity at the surface point. Extremely simple and very elegant. See the illustration below:

You have to figure out the normal vector at the intersection point. For a sphere that's simply a line running from the center of the sphere to the point you hit the sphere. For a plane it's just a simple formula using the edges of the plane. And by calculating the angle between the normal vector and the light vector, you know how much light is hitting the surface. And starting with this, you can calculate the reflections, refractions, speculars, shadows and the rest of the information you need for a realistic image.
|

After having prototyped the formulas on paper, I sat down a monday afternoon in february 1993 in front of the Amiga. First I wrote a program with just text output, just to check if my math formulas was returning the same values as they did on paper. The following friday, with a little help from my brother (who helped me get graphics on the screen), I managed to write a small program that rendered a shaded red sphere on a blue gradient background. I was stunned, and immensely proud! This was magic!
Just for fun, here's a screenshot of the source code for my simple raytracer. If you skip all the comments and empty lines, there's just 39 lines of actual code in there. So that's how easy it can be to write a thing like this :)

Later that year Øyvind Bakksjø, a friend of mine, and I wrote a second raytracer in Pascal. I figured out the math and he did the programming. All the images on this page are from this second, deluxe-style raytracer. Although quite limited in what it could render, we had a couple of features I had not seen in any renderers at that time; such as fresnel reflections, and boolean solid primitives.
The picture on the top of this page was the second image we rendered. Notice how the drops of water (or dielectric spheroids if you like) actually create a refracting effect like real water would. Also, we made the highlights look like they were overexposed, another effect not present in any of the software packages I was using at the time.
|





             | All the images on this website are (c) copyrighted Rune Spaans and their respective owners. Any use of the materials on this site other than for private, non-commercial viewing purposes is strictly prohibited. If you want to use some of these images for promotional or editorial reasons, please contact me. | |