A real time raytracer

I began playing with ray tracing. Unlike some geeks who almost started programming by writing raytracers, I never thought it would be of any interest, since it generally could not lead to real time animation. Then, the PS3 arrived.

My first prototype even does not run on the PS3. It has been developed on a PC, with the ps3 in mind :

  • It is multithreaded.
  • it uses vector intrinsics (SSE and SSE2 on PC).

Currently, it just handles simple objects : spheres and planes. Reflection and specular lighting are supported.

This following picture has been generated by my prototype raytracer:

A real time raytracer

This 640x480 picture was generated in 0.05 seconds, using a 2.4 GHz Core 2 Duo dual core processor, with two threads. Each processor core traces 4 rays in parallel, thanks to vector programming, so the processor can compute 8 pixels simultaneously. On the 6 SPEs of the PS3 processor, 24 pixels can be computed simultaneously, and I strongly beleive the raytracing process would run much faster on the SPEs than on the Core2 cores.

Next steps in the raytracer development would consist in supporting new primitives like boxes, cylinders, toruses, blobs, unions and intersections. Obviously, I have to start the conversion to PS3 aswell.

All computations are done with real-time in mind: the floating point format used is single precision, for performance reasons. Also, I use approximations : my power function error rate can under some conditions be more than 50% for instance. I also make heavy use of the vector fast inverse square root estimate intrinsics.

All the basic raytracing techniques were all derived from the excellent raytracing tutorial by Gregory Massal (original in French) (translated English version).

Specular lighting uses a power function approximation routine, inspired on the one described on this page, but developed using single precision floating-point format. It was fully implemented using vector intrinsics.

As usual, it is done during my spare time. So the progress can be long. Wait and see !


1. On 07/02/2012, 11:59 by hinchy

Awesome stuff. Have you looked into a divide and conquer approach of using both gpu and cpu to render seperate parts of the image or even alternate frames?