A GLSL version of smallpt

smallpt is a bare minimum path tracer written under 100 lines of C++, featuring diffuse, and specular reflection, and refraction. Using the detailed explanation slides by David Cline, I experimented porting it to GLSL on Shadertoy.

This proved to be an interesting experiment that brought a few lessons.

You can see the shader and tweak it here. By default it uses 6 samples per pixel, and 3 bounces, which allows it to run smoothly on average hardware. I found 40 samples per pixel and 5 bounces to give nice results while maintaining interactive framerate.

Path tracing, 40 samples per pixel, 5 bounces

Path tracing, 40 samples per pixel, 5 bounces

Update: since GLSL Sandbox has a feature, reading from the previous frame buffer, that Shadertoy is missing at the moment, I thought it’d be interesting try it to have the image converging over time. A little hacking later, a minute or so worth of rendering got me this kind of result: Given the effort, I am really pleased by the result.

Path tracing, 40 samples per pixel, 5 bounces

Path tracing, unknown number of samples per pixel, 7 bounces

A raytracer under a hundred lines of C++

On his website Kevin Beason presents a Monte Carlo ray tracer written with 99 lines of C++, generating a picture of a Cornell box with global illumination. Beyond the interesting experiment and the fact it can generate a binary of 4kB, I find very valuable the fact there are slides explaining all the code.

Octree-Based Sparse Voxelization for Real-Time Global Illumination

Last year Cyril Crassin presented a voxel based approach for interactively computing indirect diffuse and specular lighting, along with a couple of demonstration videos, and kept working on the matter since then.

In this talk given in May at the NVIDIA GPU Technology Conference, he briefly explains the technique:

Interestingly enough, as he points out, the technique has been implemented in the Unreal Engine 4 already.