/fast-and-tiny

A basic Monte Carlo raytracer in python

Primary LanguagePython

Fast and tiny: raytracing in python

Who said that the code in this repository is fast and tiny? :)

Here are two versions: tiny.py in 62 lines of code, very easy to read, but pretty slow. The other one, fast.py is a bit harder to read, but it is orders of magnitude faster.

tiny.py: how it works (writing in progress)

for each pixel
  compute color

for each pixel
  emit a ray from the origin trough the pixel
  if the ray intersects the sphere
    paint sphere color
  else
    paint background

for each pixel
  emit a ray from the origin trough the pixel
  for all objects in the scene
    select the frontmost intersection point
  if the ray intersects the scene
    paint intersection point color
  else
    paint background

for each pixel
  emit a ray from the origin trough the pixel
  for all objects in the scene
    select the frontmost intersection point
  if the ray intersects the scene
    recursively emit a reflected ray
    cumulate colors through reflexions
  else
    paint background

fast.py: how it works (writing in progress)