Realtime Raytracing

This is the big gun for anybody talking about raytracing and games.  If theoretically you could get raytracing to run in realtime then you could make a game using the technology without needing to tap the GPU.  Since each ray is distinct and independent, raytracers lend themselves very well to multithreading.  As such, they scale very nicely across multiple processors.  Multi-core processors have brought this concept back to the fore, but it's certainly not a new one.

Anybody who doesn't know what demoscene means should probably hit up Wikipedia real quick.   Suffice it to say, a lot of really great programmers have thrown their best up against the wall and produced some darned good results, but despite their efforts it's just not in the cards yet.

Transgression 2 by MFX

Made in 1996, Transgression 2 is one of the first realtime raytracers on a PC, and easily the oldest one I know of.  It's so old that since there were no more than 256 colors available to them, they split the screen into rows of red, green, and blue and mixed the colors together manually.

Transgression 2 set the bar as far as expectations from realtime raytracers.  There was no way the thing could actually trace a full screen every frame.  So MFX came up with a brilliant solution: trace as many rays as you can per frame (dependent on processor speed), and instead of filling pixels, use those colors to put splotches of virtual paint on the screen and turn the whole thing into a sort of impressionist painting in motion.

The results are indistinct and fuzzy images, but raytraced and in-motion.  It was very impressive in 1996.  It's unlikely you'll get it running outside of DosBox, so enjoy the YouTube video instead.

Nature Suxx by Federation Against Nature

This was perhaps the first realtime raytracer to have scenes consisting of more than 3 or 4 objects.  It also drew distinct shapes instead of indistinct splotches.

While it looks like a solid image, this tracer also gets away with only tracing a fraction of the pixels on the screen.  It uses a method called "adaptive sampling" that I'll detail after this history lesson.

Nature Still Suxx by Federation Against Nature

Nature Still Suxx is essentially more of the same.  The engine has numerous speed improvements, they used sharper textures, and added a few features like CSG intersections.

The scene above shows object borders so that you can see there are no polygons.

Still Sucking Nature by Federation Against Nature

The last big production by FAN before they went commercial.  This is arguably the first realtime raytracer that made real strives at recreating real world scenes.

Heaven 7 by Exceed

This is probably the most widely liked realtime raytracing demo.  It's almost always in Pouet's top 10 productions of all time.  It's fluid, it's pretty, and most of all it includes a sphereflake.

Going Under the Hood: Adaptive Sampling

This little concept is one of those strokes of genius that takes computer science nerds like me for a loop.  It's so simple, and yet so effective.  It's hard not to like it.  The idea is to use more rays where you need them: the edges of the objects and the shadows.  Consider the two renderings below:

This image shows a finished realtime raytraced scene.

This image shows the same scene, but only shows the rays that have actually been traced.  Here's how it works:

Instead of handling the screen one pixel at a time, we go at it with 8x8 blocks.  We trace a ray at the corner of each 8x8 block, but instead of storing the final color we store: an ID representing what object we hit, the amount of light hitting that point, and the texture coordinates at that point.  With that block, check to see if the 4 corners (a) all hit the same object, and (b) are pretty close in the amount of light hitting them.

If the block meets the requirements (a) and (b), then we go through all the remaining pixels and interpolate the texture coordinates and light amount.  Then, for each, we get the final color using the formula: col = light*texture[tx, ty];.  As you can imagine, this simple calculation is far faster than tracing a ray.

If the block doesn't meet requirements (a) and (b), then we break it into 4 blocks, each 4x4, and trace the rays at the corner.  We repeat our check.  If needed we go down to 2x2, and then from there just trace individual pixels.

This image shows the adaptive sampling at work.  Off the bat, the bottom-right pixel hits a sphere and the other 3 corners hit a plane.  You can then see the adaptive sampling go to work and find the object edge without tracing any unnecessary rays.

When the camera pans out, you can see how even though most of the plane is interpolated, there's very little noticeable loss in quality.

What's the Cutting Edge in Realtime Raytracing?

The absolute cutting edge is OpenRT.

This realtime tracer takes a different tackle.  Instead of reducing the number of rays, they increase the number of processors.  The scenes above are realtime, sure, but only because they're being rendered on a 24 processor render farm.  The results are impressive, but so are the costs.

OpenRT started as a university project at Saarland University in Germany and while the realtime aspects get the most attention, the most exciting part of it is that they're developing an open and universal language for raytracing.  This leads into SaarCOR and its successor RPU -- a hardware accelerator for realtime rendering OpenRT scenes.

And if you thought that was expensive, how about 599 US DOLLARS?  Using the PS3 version of Linux, some guys have gotten a networked realtime raytracer running (assumedly they just downloaded and compiled the Linux version of OpenRT)  It sounds promising until you realize that you need 3 PS3s to render one car.

What Alternative Is There For a Guy With Just One CPU and No RPU

There's really just one group that's still kicking ass with this single-workstation adaptive sampling engine, and it shouldn't be too surprising that it's Federation Against Nature.  They've created a "benchmarking" program called RealStorm that has a wide range of capabilities including radiosity.

They've even used the engine to throw together a game demo: Bowl X-Treme.

Though, given how poorly Bowl X-Treme runs, it's almost a test case to show why games can't be done with raytracing right now.

Raytracing Is Completely Useless For Games Then .... Isn't It?

Not necessarily.  While you can't raytrace in realtime for gaming, there's all sorts of things from raytracing that have made their way into forward rendering.  The next installment will cover various types of hybrid rendering techniques.