/2k_raytracer

A raytracer in 2000 bytes of C++

Primary LanguageC++

"Pixar Ball" Raytracer in 2kB

Inspired by the famous "minimal raytracer challenge" by Paul S. Heckbert, I wrote this program as a challenge to myself to see how much I could cram into a raytracer that was at most 2kB of source code.

ray.cpp weighs exactly 2000 bytes. pretty.cpp is the same code, only properly formatted and commented.

Features

  • Textured yellow Pixar ball with blue stripe around the equator and red star on top, placed at an angle
  • Glossy effect on ball with blurred reflections
  • Ambient spherical light + cone spotlight
  • Phong highlights
  • Textured floor and walls
  • Reflective floor
  • Soft shadows
  • Depth of field blur

Output

You should get an output like this (click on image to see a larger version):

Sample output

Usage

Requires C++11/14. Compile with the GCC 6 or above with g++-6 -O3 -std=c++14 ray.cpp. File is output to stdout in the PPM file format. Run with ./a.out > img.ppm. It should complete in less than a minute on a modern machine. Open with a compatible viewer.

License

This work is in the public domain.

Public domain