Tuesday, July 20, 2010

A C++ Port for Optimization

I was disappointed with the speed I was getting from C#, so I ported the code over to C++ to take advantage of the SSE instructions and other optimizations. At first, I didn't notice a major improvement, which suggests some slowness in my algorithm. I tracked it down to the BSpline intersection method.

The problem on there is that it involves bisection over the parameter space of the spline, which results in doing a lot of calculating. And in fact, a lot of points, particularly the endpoints, were being calculated once for each pixel in the image, which doesn't really work well, especially because I am going to want to sample with multiple rays later on.

To solve the problem, I noticed that I could precalculate a large table of points on the spline over the parameter space, say with a delta-t of dt=0.0001. Instead of calculating stuff over and over again, I could just compute the table once and simply reference the table in my intersection method. This solution was a huge win, because on a 500x500 image with a single aurora spline, I was able to do the optimized rendering in 0.48 seconds instead of the 6.00 seconds it was running before: the improvement is about 1200% for that situation alone!

No comments:

Post a Comment