Raytracer written in Python

Within the scope of a school project I have written a yet very simple raytracer in python. The reason why I have done this is, that I like the idea of describing a scene in the same language the raytracer itself is written in. In other words I'd like to change the raytracer itself so it fits the needs of every special rendering task. Such things you'd better do in interpreted languages. So I have chosen python. And as you might know you can do really nice things with python. You'll see what I mean when I'll give you an example. And so I do:

from pyray import *

res = XGA
sun = Sun(dir = v(-1,-1,-0.5))
cam = Camera(pos = v(60), aspectRatio = res.aspectRatio)
scene = Scene(sun = sun)

for x in range(-2, 3):
       for y in range(-2, 3):
              for z in range(-2, 3):
                     pos = v(x*10, y*10, z*10)
                     col = v((x+2)*255/5, (y+2)*255/5, (z+2)*255/5)

                     sph = Sphere(pos = pos, radius = 2.5)

                     scene.addObjects(obj(sph, col))

scene.render(cam, res.res)

This few lines of code would produce such an image:

no image ...

Unfortunately the raytracer lacks performance. Simple pictures like this one can take up to 20 minutes.

Features

  • Lambert's cosine law (only one "sun")
  • cast shadow
  • spheres
  • intersections of any objects
  • python as scene description language
  • high configurable, but uses reasoneable default values
  • free and open-source
  • and very very slow ;)

Motivation and Future Prospects

There are of course better raytracers than mine, but rather than creating a POV-Ray challeging raytracer it allways has been the aim of this project to gain expirence in writing python programs and understanding basic ideas of raytracings. Although I am not planing to go on devloping this raytracer, I published it here in the hope someone will find it usefull as either a (bad) example of software or inspiration. If so ever just let me know.

Architecture

License

At the moment the raytracer is published under the terms and conditions of GPLv2

Sourcecode

Here you can download the latest public version: pyray-8.11_alpha1.tar.gz

Some more Pictures

no image ...