an unbaised raytracer in under 1k of javascript
Switch branches/tags
Nothing to show
Clone or download
Failed to load latest commit information.
.gitignore switched to uglifyjs to turn 0.xxxx to .xxxx Oct 4, 2013 coffee gruntfile Oct 5, 2013
index.html moved to git Oct 4, 2013
package.json switched to grunt and more recent uglifyjs Oct 5, 2013

javascript raytracer in 901 bytes

Made for js1k 2012 - "love"

See it in action here:

render 3

It takes several render passes before it looks any good, and it's quite slow.

But, because it's simulating the behavior of photons (reverse photon mapping), lots of cool features fall out of it:

  • Global illumination
  • Atmospheric effects (rays have a slight chance to deflect while travelling through air)
  • Antialiasing (each photon is slightly randomized within the pixel it originated from)

Because it fits in under 1024 bytes of javascript, sacrifices had to be made:

  • Photons are steped through space in small increments, then check for collisions. Actual sphere-line intersection and reflection would have taken up way too many bytes!
  • No support for glossy materials, for above reason. When a photon finds itself within a sphere / heart shape, it changes it's direction randomly, and continues on it's way. Thus, diffuse surfaces.
  • Fairly slow. Code length was the only thing optimized for.

It uses uglifyjs for the final minification step. To get dependencies:

npm install

If you don't already have grunt installed globally, npm install -g grunt-cli

To minify:


Pull requests are very welcome!