Core S2 Software Solutions

Multi-Threaded Ray Tracer

Ray tracing is an approach to rendering a scene in computer graphics. Rather than trying to create real-time graphics (graphics that can quickly change based on user interactions), ray-tracing is a high end slow-speed rendering system. Though it is computationally costly, ray-tracing is a great way to create complex reflections, refractions, soft shadows, dept-of-field blurs, and plenty of other visual effects.

For a course assignment here at Penn State, I had to develop a basic ray-tracer. Not content with simple triangle collision detection and diffuse shading, I added a few special features that make things more fun. I included good anti-aliasing using jittering; anti-aliasing sends out multiple rays from the observing source to super-sample a region in the scene. By doing this, edges of objects aren’t too “sharp” but are neither over-blurred. A common mistake when it comes to implementing anti-aliasing is to average out adjacent resulting pixels, which is wrong. By doing this, the image blurs rather than smooths out edges. There are some computer-vision algorithms that can actively seek image edges and blur them to give a simplified and performant anti-aliasing, but are a “cheat” and might give unintended blurring on the edges of textures even if they are on the same object surface. It is important to note that anti-aliasing adds exponential time to the computation cycle of each ray. A 2x anti-alias setting requires 2×2 = 4 times more rays to be sent out from the observing point. A 4x anti-alias setting requires 4×4 = 16 times more rays.

Soft shadows were created by having each light define a self-radius of 1-unit in length and have 64 randomly selected points act as individual lights on the sphere surface. These sum of shadows casted from all of these points are averaged to create a “smooth” edge. Another fun feature to speed up my rendering cycle was to make this system multi-threaded, using the pthreads library. I split the scene into uniform 64 by 64 squares and span a certain number of threads to compute them in parallel. When all sub-scene components are done, I write the scene as a whole to an output file.

Check out some sample images I rendered, each taking about an hour. I can clearly see where optimizations could be implemented and certain chunks of code that can be cleaned up. The largest issue is that I need to make fast matrix multiplications and summations, but have yet to provide a decent open-source library that can do this. I’ve been told that Intel processors can do vector math, and will be looking into this for future optimizations.

This entry was posted in Programming. Bookmark the permalink.

One Response to Multi-Threaded Ray Tracer

Leave a Reply

Your email address will not be published. Required fields are marked *


Sites map