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.
Path tracing is fun, easy to implement, and good looking.
GLSL support in WebGL is still nowhere near robust: valid code will or will not work depending on the platform, the browser, and whether the OpenGL layer is native or not. The statements “break” and “continue” in particular seem often to break everything.
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
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, unknown number of samples per pixel, 7 bounces
I mentioned already (here and here) that one problem with gamma correct rendering is how we lose prevision for small values, and may run out of it if we didn’t have enough of it. I wrote a quick shader to demonstrate this problem and see how severe it is depending on the number of bits.
Thanks to BeautyPi‘s fantastic tool, ShaderToy, I could put it on line. Here is the live demo with an absurdly low precision format (R5G6B5) so you cannot miss the banding; just press the play button. It displays colors with maximum and low precision, in linear space and gamma space. The lighter vertical line shows the 50% intensity position. You can see the shader and play with the values here.
Back in 2009, Iñigo Quilez was leaving everyone in awe by releasing the milestone 4kB intro, Elevated, in cooperation with the group TBC. If you haven’t seen this masterpiece, watch it, and keep in mind this was generated from only 4096 bytes worth of data (just the text of this article is already more than a third of that).
After that, news were that he was hired by Pixar, and besides some in progress screenshots from time to time and some live coding experiments, not much was heard from him.
Then a couple of months ago this interview was published, and more recently this praising article of CGW, where we could read he had been in charge of the vegetation rendering in Pixar’s Brave. Needless to say, many people were looking forward to seeing what he would do next, especially in the real-time domain.
Today the group he’s part of, BeautyPi, which seems to be focusing on interactive animations (they presented their work earlier this year at SIGGRAPH), has published the following video. Being a showcase of their last experiments, it is not entertaining like an animation, a clip or a demo are. You could even say it’s boring. But it is visually very impressive, both technically and artistically. Although this is some real-time material, the quality is not that far from movie standards. Regarding the interaction, I am suspecting they are only scratching the surface and they may come up with some very interesting things. What these folks are doing is definitely worth following.