Real-time Ray Tracer

Here you can find some info + screenshots + a demo of my hi-res real time ray tracer.
It runs at a decent fps at 1024 x 768 in 24 bit colour on my p3-450 + geForce2.

Journal

April 15 2004: If u want some src for a raytracer that can actually compile, check out my Simple ray tracer.

Jan 22: I hinted I would release the src code earlier.. so here it is. Fuck you capitalism! :)
Also I have posted an updated demo which the source code is for. The demo includes realtime raytraced metaballs, CSG and water ripples.

Hopefully the source code will be useful to lots of people. One thing about it is that there are a LOT of lines of code relative to a typical raytracer. This is beacuse there are a lot of optimisations, some of which required a fair bit of code. Accordingly this may make it difficult to understand, and perhaps not so useful for someone new to raytracing who just wants to see the basic algorithms implemented. However hopefully people will find the optimisation code useful as well.

Scroll down to the download section to grab the demo and the src.

Here are a couple of pics from the demo:


Dec 12: Well this journal is going pretty lamely :). I've been coding like a maniac however. Here are some nice pics I took tonite:



The water in these pics is done with an animated normal-map over a plane. The bottom pic orange thing is of course demonstrating CSG (constructive solid geometry) - it is a sphere minus a couple of other spheres.

Both these features were pleasantly simple to code, although I haven't done CSG self shadowing yet.

Hehe this is starting to look like heaven7 :)

Other stuff I have done:

* Metaballs: these look damn nice, and they are self-reflecting.

* Proper additive specular lighting and texture lighting.

* Made a material class, so u can specify stuff like reflectance ratio, colour etc.. easily.

Till next time see yup!


Nov 21: OK, I'm now going to write a development journal type thing.

I have updated the demo to v1.1, which fixes a few small and not so small bugs, like the fps counter/clock code, flares when looking away from the lights, and hopefully the black squares instead of nicely blended flares that some people are getting.

The deal with the source code is that I would release it, as it is my philosophy to release src code in general, but it will take quite an effort as there are header file dependencies all around my programming directory. Damn software reuse :). So it will be released when I can be bothered to do it :)

I have some WICKED stuff planned for this raytracer, I'm having a lot of fun coding it, so be prepared + stay tuned...

peace.

Features

* subdivision subsampling: this is one of the main optimisations which allows it to run in hi-res and realtime. This allows detail to be calculated only where needed.

* Hardware acceleration using OpenGL: The image is divided up into small squares, each of which is drawn as a textured quad in OpenGL, with the colour at each vertex determined by the ray-tracer lighting calculations. This is the other main optimisation.

* Phong lighting: The lighting model is a simple ambient + diffuse + specular thing.

* Geometry: Objects currently included are spheres, planes, rectangles, and cuboids.

* Light flares: Somewhat gimmicky flares around the light sources, and around primary reflections of the light off objects in the scene. Done with an additive blended OpenGl quad sprite of course :). The positions of the flares are solved analytically.

* Quick approximate Sphere intersect test: This is my own invention, an approximate test for primary ray/sphere intersection that requires only one dot product and then a scalar compare.

Another optimisation is that not all objects need to cast shadows. In this way the ground plane does not need to be involved in shadow checks.

* Nice code: Code still uses operator overloading on my Vec3 class in most places and uses object-orientated polymorphism on the different types of primitives. == readable code. Of course this is slower but it shows that high-level algorithmic optimisations are sufficient to acheive hi-res realtime raytracing.


In the images below you can see the subdivision scheme at work. The parts of the image that cause subdivision are when the rays at each square corner hit a different sequence of objects, or the presence of shadow changes. The scene is originally tesselated at a res of 40 * 40. The quads are rendered with an orthographic projection, eventually tesselating a flat plane in front of the camera.

Most of the optimisation ideas that made this possible I got from a fantastic article by a guy called Lycium. I originally read the article (called Real Time Ray Tracing) in Hugi 23, but its up on the web here:

Real time ray tracing

Thanks Lycium!

ALso if u are interested check out

The Realtime Raytracing Realm

Demo

Demo version 1.2: CSG, metaballs, water ripples, 5 scenes and more :)

v1.2 demo(1.2 MB)


Source code for demo v1.2: includes MSVC++ 6.0 workspace. Does not include library files and thus won't compile :(

source code for demo v1.2(116 KB)


Demo version 1.1: Two spheres, textured plane etc..

v1.1 demo(550KB)

More screens

Click on thumbnail 2 view pic + see description.

Future enhancements

Written by Ono-Sendai, 2001.

Shout out to all NZ coders!
Peace all!

(Back to home page)