A while a ago I posted about my attempt to implement the ray trace challenge in a webgl shader. I recently picked it up again and added a physics engine just to try to punish my computer some more. It has a few flaws still but the first test is pretty promising!
I tried to program my GPU with CUDA (some very basic things) and I was pretty sure that a GPU could not be very efficient to do ray tracing because in the main algorithms, there are a lot of "if/else" statements and kernel functions don't like branches.
Obviously I'm wrong and I will have to go deeper into GPU programming.
Ya there were a few places that resulted in deep nested branches that I had to put a limit on, like patterns of patterns of patterns etc. And the perlin pattern was a total no go. But the GPU can totally do it. I was suprised also. I never did CUPA though. Is that like cross compiling?
CUDA is the NVidia platorm / API to program their GPU. I tried it with native C++ (the hard way) but there is a very nice C# project (http://www.ilgpu.net/) that will transform some .Net "bytecode" into GPU program.
I made some tests to compute triangle intersections: send the triangles data to the GPU memory and program a kernel function to compute all intersections for a given ray. The GPU can compute a lot of things in parallel so I expected a good speedup for scenes with a lot of triangles.
But it was a failure because the time spent to send and retrieve data between CPU / GPU is not 0 and the final rendering time was higher than without the GPU !