Monday, December 27, 2010

Holiday Update

Now that it is the holidays and I am not at work for a whole week I have no excuse to not update this blog with the work I have done on the ray tracer. The updates since the last time I posted have not been huge visually but they have been helpful in keeping me working on this project, which at times can be the hardest part.

What I have done is a few things. First, I went through my render pipeline and used Intel's Threading Building Blocks to easily multi-thread my rendering. I did this mostly as a quick test to see what kind of performance gains I would see while running this on my laptop. The starting speed of the ray tracer before adding in TBB was about 1400-1500ms per frame. That is running at 1280x720 resolution, not a very respectable time. After (sloppily) throwing in TBB my frame time dropped to around 400-500ms per frame, just adding in TBB (which was not much work) brought me out of the realm of Seconds Per Frame and into the wonderful world of Frames Per Second! Also if I drop the resolution down to 800x600 my frame time dropped to around 140ms per frame, that's nearly interactive!

Another change that I made as you can see in the picture is that my triangles are properly casting shadows now. The first iteration of the triangles did not cast shadows because the back faces were being culled, and to properly have a shadow be cast I need a ray to hit the back face of the triangle. The big problem with having a triangle be able to cast shadows properly is that you essentially have to check against the triangle twice per ray, once for the clockwise winding and again for counter-clockwise. Adding support for this allowed me to add support for being able to choose your triangle winding though, now you can choose clockwise, counter clockwise or both. Also the single triangle shadow issue wont be an issue at all if you have a closed mesh since the ray would always intersect with a triangle in the mesh when checking for shadows.

The final update I made was actually a bug fix rather than an "update". I had anti-aliasing in place since it is very easy to do edge detection with a ray tracer, but it never quite looked right. I just passed this issue by and moved on to bigger and better things, but after talking with a friend of mine he convinced me to go back and fix this issue before the bugs started to pile up. There were actually two issues I had, one was that I was not storing off the original colors from the first ray trace that detected the edge properly, the second issue was that I screwed up some very simple math and was doing six samples when my math assumed four. I fixed those two simple problems and now my anti-aliasing looks smooth and nice around those edges.

Future work that needs to be done is that I still need to get model loading in and working, I may start with some third party library for loading models and roll my own when I see fit. Also there is one more known issue that I want to take care of which had to do with floating point precision errors I was seeing back when I was using floats for everything. I want to move back to floats because I find doubles to be a waste of memory and a potential performance sink since if I use floats ( or to be more clear, 32 bit single precision floating point values) I could optimize a lot of my vector math with SSE.