Aravind's Rayperl

Home
Bio
Publications
Astrophotography
Photography
Tutorials
Reviews

AK Imagery
Photo Blog

What the heck is rayperl?  As the name says its a simple ray tracer written in Perl.

Why write a ray tracer in perl?  I know ray tracers, I don't know Perl.  That and I needed a little project to keep me on my toes.

What kind of nifty things does it do?  It ray traces spheres, thats it, no other primitives.  It antialiases by sampling each pixel 16 times using an N-Rooks kernel which is generated at run time.  There's diffuse lighting, shadows, multiple colored lighting, and reflections.  Thats about it.  Adding more stuff is pretty trivial, its written to be extensible (that doesn't mean I'm going to do it though :) )

How long did it take to write ?  A few days on and off, I'd say about 15 hours overall.  

How fast is it ?  Its god awful slow, but I was surprised to find that it wasn't as slow as one would expect.  For each of the scenes, the time it took to render is shown below.

What now ?  I was somewhat inspired by this project.  I want to see how many different languages and platforms we can write ray tracers in.  In particular I'm interested in a post script ray tracer, a ray tracer for the Palm (should be trivial since you can do it C).

Where's the source ?  Gimme source !  You can download the source right here. rayperl.txt.  A couple things.  All the scenes are defined as functions.  To render a scene, just uncomment the function call (at the bottom of the file).  Also the resolution, samples / pixel, the camera's location, the camera's field of view are all set as variables near the bottom.  It always outputs to a file called rayperl.ppm.  If you need a PPM viewer and are running Windows, try this one, ifranview.  It also has the ability to output to an interim file, which is rayperl_interim.ppm.  WARNING:  Do not run this under Windows with ActivePerl.  I found that it writes out funky data, and so the image might look all gibbered.  I have run it just fine on two different Linux boxes and a Solaris machine.  

I have a small gallery of images that I have generated with rayperl.

Comments are most welcome.

 

This is a really simple scene.  One light at top, one at the camera.  512 x 512 with 16 samples / pixel.  It took about 3 hours on a P2-400.  21 spheres in total.  
Another simple test scene.  The two rows are supposed to form some kind of helix.  This one was 720 x 480 with 16 samples / pixel.  40 spheres in total.  It took about 5 hours on a P3-550.
Test for colored lights.  There are three lights just above the 'surface' of spheres.  There are a total of 100 spheres in that scene.  This was rendered at 512 x 512 with 16 samples / pixel.  It took about 13 hours on a P3-550
A set of randomly generated spheres (supposed organized as rings), thier sizes also vary randomly, as does their color.  There are a total of 1000 spheres generated.  It took almost 24 hours to render on a P3-550.  This was rendered at 512 x 512 with 1 sample / pixel.  
Two rings of spheres.  Each has 20 spheres.  All the spheres are reflective.  There are two lights, one near the viewer, and one at the top.  We can see reflection working in this image.  This image rendered at 512 x 512 with 16 samples / pixels took 38 hours to render on a P2-400.  


Hosted by theorem.ca

All text and images (c) 2000-2012 Aravind Krishnaswamy. All rights reserved.