SmallPT in Javascript

I recently found a very interesting project, called SmallPT. It is photorealistic 3D renderer, written in 99 lines. So I decided to rewrite it into JavaScript.

SmallPT

SmallPT is a photorealistic renderer. It uses Monte Carlo path tracing to render the scene. It contains 3 materials: diffuse material, mirror and glass, and one primitive: sphere. For more info, read the official Kevin Beason's webpage.

Rewriting C++ to JS was pretty simple. I just had to remove type identifiers ("var" instead of "int", "double", "Vec", ...). I also had to rewrite classes into JS constructors. In Javascript, you can not overload operators, so I had to rewrite all expressions with vector operations into function calls.

Try it yourself

Below is the official 99-line JS version of SmallPT. You can pass it 3 comma-separated parameters: width, height and number of iterations. E.g. smallpt.html#800,600,4 will produce a 800x600 image with 4 iterations of algorithm (more iterations = better image).

I also have written another version with explicit light sampling, also from Kevin Beason. I added several scenes and a simple UI with continuous updating of bitmap.