Pathtracer – OpenCL

My Previous posts were about implementing a pathracer in Java. But the more features i implemented, the more time i had to wait, to check the resulting image, make changes, and again wait … in general 1-10 seconds.

So it was time, to move the whole thing to OpenCL.

At the beginning i had a lot of problems creating the buffers (got a lot of FATAL ERROR …). As soon i removed all the bugs it worked quite well, since i could almost 1:1 port the (already working) code from my java implementation to the OpenCL language.

Im still using a BVH-data-structure, but the flat version, using a stack pointer for traversing, since OpenCL doesnt allow recursion.

On the hostside, the obj-file gets imported, the BVH is created, and the buffers (mainly using structs) are created. The whole pathtracing (bvh-traversal, shading, etc.) happens on the device then.

The change in performance was quite impressive. On the same System (CPU: Q6600, GPU: GeForce GTX 550 Ti) it got a huge performance hit (factor 20 – 30) on the GPU versus the CPU implementation. So now i can render a scene, containing a hundreds of thousands of triangles and always having a at least a framerate of 1, … of course thats far from realtime, but allready very promising.

Also added some new Features, as Sunlight/Skylight (diffuse Lightning, Ambient Occlusion) and transparent materials (refraction).

The following videos/images show the current state of my Pathtracing-experiment ( the videos are a bit laggy due to the screen-capturing, while rendering).


my Setup is …

the demo application can be downloaded here:


Get the Flash Player to see this content.





First testscene

… working on transparency and refraction.

Get the Flash Player to see this content.