Monte Carlo Path Tracer


To simulate the wide range of lighting conditions that are seen in nature, we implement a system that simulates light transport by tracing paths through the scene. Rather than consider all possible paths of light, we use the Monte Carlo technique to randomly sample important paths, and use the results of sampling these paths as an approximation.

We have seen some very good results from our implementation. In any Monte Carlo method, the result will become more accurate, and less noisy, in proportion to the square root of the number of samples taken. Therefore, even with very simple methods, good results can be acheived with enough samples, but convergence will be very slow (since it is less than linear).

Instead, we can speed up convergence by sampling the most important (largest) areas, and get much faster convergence. Below, we show some images rendered with our system. Note that the quality of the images improves as the samples increase, but even with low sampling, the image is still recognizable. In the following images, we see a weak reflection of the scene in each ball. Notice also the slight indirect illumination of the roof by each wall.

1 sample per pixel 16 samples/pass, 3 passes
64 samples/pass, 3 passes

In this rendering of the classic Cornell Box (64 samples/pass, 3 passes), we can see the indirect illumination of the sphere from the light reflecting off the walls. Even though the walls are not emitting their own light, and neither they nor the ball are mirrors, the ball appears colored. This is one of the major results of global illumination techniques.

In the following scene, provided by Diego Nehab, we can see the reflection of the lights off the spheres, as well as the subtle reflection of the boxes against the reflective back wall. We also see the interaction of various lights and their effect on shadows. These results are implemented automatically for a Monte Carlo path tracer, without having to resort to the sort of tricks required for scanline rendering.

16 samples/pass, 1 pass 16 samples/pass, 100 passes

In this scene, we can see the interreflections between each balls. This tended to take a very long time per pass, because each reflected ray maintains a large amount of energy (the mirrored surfaces do not absorb energy). To ensure an unbiased result, we used the Russian Roulette techinque that probabilistically culls rays whose energy is less than some threshold, rather than after some set number of bounces. We also importance sample the specular lobe of the bidirectional reflectance distribution function, allowing the mirrored surfaces to converge quicker.

16 samples/pass, 1 pass 16 samples/pass, 100 passes

I've provided the code for this project here. This was a class project over 4 years ago; it is quite old and inflexible, and somewhat hard to use, but a number of people have asked me for it, so I've posted it. The output image size is hardcoded in (can be easily changed though by recompiling). It supports multi-pass rendering, but this seems to currently give funny results (so just increase the samples per pixel with the -g option). It also is rather slow. The output file name will always be in the form 'Output%d.bmp'. It requires libjpeg, GLUT, and GLUI (it doesnt have a userinterface anymore, but I dont have time to figure out where the dependencies are and how to remove them). The makefile is designed for Linux, but it should work under windows as well (I just dont have ready access to a development machine to test it). Anyways, after all that, if you still want it, here it is!

montecarlo.tar.gz Source and Model files for the Monte Carlo Path Tracer

You may use this code for either commercial or non-commercial projects. If you would like to redistribute it or a modified form, please give attribution to me and this URL. (and if you find it useful, please drop me a line, I'd love to hear about it.).