Not logged in, Join Here! or Log In Below:  
News Articles Search    

Submitted by Thomas Mølhave, posted on January 26, 2005

Image Description, by Thomas Mølhave

I have just finished the construction of a ray tracer running almost completely on the GPU of my GeForce GX 5650 with a NV3X GPU (That is, no shader model 3.0). OpenGL along with RenderTexture[1] is used to interface with the graphics card. Cg is used to control the GPU.

To make a ray tracer on the GPU it needs to fit into the computational model used by the GPU. This can be done by mapping the algorithm to the stream programming model. The mapping used was described and also implemented by Timothy Purcell in his Ph.d. dissertation[2].

The ray tracer reads scenes in my own format, usually exported from 3D Studio MAX using a custom exporter, and builds a uniform grid on the CPU. The grid is then uploaded to the graphics card as textures along with other geometry information and processing is handed over to the graphics processor.

The GPU generate eye rays which are traversed through the grid until they hit a triangle or leave the grid. When a triangle is hit, the hit point is shaded according to material and normal parameters. To keep track on how far each ray is in the pipeline, state vectors are kept for each ray. The state vector, among other things, indicates whether the ray is traversing the grid or is ray to be shaded of checked for intersection with triangles.

The ray tracer was written in a span of two weeks and are therefore simpler than it could have been, but it nevertheless demonstrates the technique explained by Purcell. It would be simple to add levels of recursion, producing a path tracer and it could also be extended with a photon mapper[3].

It is also very slow compared to what the CPU would manage, this is partly due to the lack of multi render targets on my GPU (causing me to make _many_ context switches between texture render targets) and partly due to the fact that no early-z culling technique is used. Speed was never really achieved and the implementation should be looked as something interesting to play with rather than something new (after all I just implemented what was described in [2], which has been done before) and exiting.

The document at gives an extensive overview of the implementation. For others thinking about implementing the algorithm, it might prove useful (or a complete waste of time, what do I know? :) )

Thomas Mølhave (


Image of the Day Gallery


Message Center / Reader Comments: ( To Participate in the Discussion, Join the Community )
Archive Notice: This thread is old and no longer active. It is here for reference purposes. This thread was created on an older version of the flipcode forums, before the site closed in 2005. Please keep that in mind as you view this thread, as many of the topics and opinions may be outdated.

January 26, 2005, 11:35 AM

What the hell, your raytracer looks like regular vertex lighting.

Thomas Mølhave

January 26, 2005, 11:47 AM

I'm sure you mean regular per-pixel lighting. This is no suprise since it only traces eye rays, you can think of it as the most clumsy rasterizer with per pixel lighting in the world :)
Nevertheless, it would be simple to extend to a general path tracer. The point of the project for me was to get to know the principle of the streaming algorithm, which succeded. With the simplicity of the ray tracing algorithm the document descibing it might also be easier for beginners in GPU programming to read.


January 26, 2005, 12:11 PM

Gee Wee! I love this stuff!
Very cool, congratulations.

Victor Widell

January 26, 2005, 02:49 PM

Hardware abuse.

Andrew Lauritzen

January 26, 2005, 03:06 PM

Contrary to some of the replies here, stream processing is a huge new topic related to GPUs. It has the potential to allow computation that goes far beyond the (rather narrow) field of computer graphics. Also with the increasing tendancy towards multicore CPUs, and vector processors (like the PS3), there is really becoming a need for a more generic stream processing system that can operate on arbitrary hardware. Moreover, with the adoption of PCI-E, more general computation on the GPU becomes reasonable, while in the past simply reading the results back to the host was a serious bottleneck.

Anyways with that said, I'm impressed with how quickly you were able to throw this demo together. I'm looking forward to continued research in this area.


January 26, 2005, 03:41 PM

Looks like it's just not tracing shadow or reflection rays yet. That would be the next step, after getting the basics going.

This thread contains 6 messages.
Hosting by Solid Eight Studios, maker of PhotoTangler Collage Maker.