Found at: http://publish.ez.no/article/articleprint/71/

Free Multiplatform raytracing with POV-Ray



The Persistence of Vision Raytracer, or POV-Ray among friends, is a high-quality freeware tool for rendering photorealistic three-dimensional graphics. This is a "getting-started" tutorial for those completely unfamiliar with POV-Ray.


Warm Up
POV-Ray is not free as in free speech, but free as in free beer, meaning that it is not open source but freely available. Still, the source code is available for those wanting to do their own ports. Check out the license if you are curious.

As an example of the top-quality output that POV-Ray is capable of, check out the Internet Raytracing Competition (IRTC), particularly Warm Up (rendered with a POV derivative) and First Strike at Pearl. You can see thumbnails of these images on this page, click the links at the bottom of this page for the full version.


First Strike at Pearl
If you are unfamiliar with the concept of raytracing, check this link: What is Ray Tracing? Basically, raytracing is a way of creating photorealistic images of an imaginary world by calculating how light rays travel from a light source, reflect on objects and hit a camera. This is computationally intensive work, and complex scenes may take hours or even days to render. Your first scenes will only take a few seconds, though.

POV-Ray in its original form is not a modeler, like 3D Studio Max or LightWave. (There are, however, many different modelers available for POV-Ray.) You use a special scene description language that is similar in syntax to C/C++, to place your light sources, objects and camera. Because of this it has a steep learning curve, but in return it is extremely flexible.

POV-Ray is available in official versions for Windows 95/98/NT, DOS, the Macintosh, i86 Linux, SunOS, and Amiga. Download a version for your favorite OS from www.povray.org. Refer to the download for installation instructions. The rest of this article assumes that you have installed POV-Ray. The examples show how to run it on a Unix system, but the scene files are valid on all platforms supported by POV-Ray.

Warm Up: Link to original image
First Strike at Pearl: Link to original image

To infinity... and beyond!



A plane
We start with the most basic of basics: A camera, a light, and a yellow and green checkered plane that stretches out into infinity. The scene code is included below: (save it as scene1.pov)

#include "colors.inc"

// Monitor brightness
global_settings { assumed_gamma 2.2 }

// Background color
background { color LightBlue }

// The camera
camera {
    location <6, 3, -4>
    look_at <2.5, 2, 0>
}

// A light
light_source { <8, 7, -7> color White }

// An infinite checkered plane
plane {
    <0, 1, 0>,
    0
    pigment {
 checker color Yellow, color Green
    }
    finish {
 ambient 0.3
 diffuse 0.6
    }
}


A short explanation of the contents: Lines starting with two slashes are comments, and are not evaluated by POV-Ray. The first statements includes the file colors.inc from your POV-Ray library. This file specifies the RGB values of some named colors. The next statement adjusts the brightness of the image according to the gamma value of your monitor, 2.2 is usually a sensible value on PC monitors. The background statement simply sets the background to a pale blue color.

The camera statement contains the first two three-dimensional coordinates, one for the camera location and one for the point in space the camera is looking at. Such coordinates are always written on the form . The coordinate <0, 0, 0> is "the center of the universe", or origo. Negative values of x are points to the left of origo, positive values are to the right. Negative values of y are points below origo, positive values are above origo. Negative values of z are points in front of origo, positive values are behind it. A scene must have one camera, no more, no less.

The next item is a light source, which has a location in space and a color. A scene must have at least one light source, or else you won't be able to see any objects.

Finally, we add a plane. A plane is a two-dimensional surface whose area is infinite. It can be used to model the sky or a completely flat ground, as we do here. The value <0, 1, 0> is not a coordinate in this case, it is a vector that describes the surface normal of the plane. The second value describes the distance between the plane and origo, if you want to lower the plane, try to set this to a negative value. The plane has two statements describing its appearance, pigment that describes the checker pattern and finish that in this case describes the lighting of the plane.

To render this scene yourself, run

povray +Iscene1.pov

and open the resulting file scene1.png in your favorite image viewer.

Alternately, if you want to see the image as it renders, save the following text to the file standard.ini

; POV-Ray 3.1 Standard INI file
Antialias=on
Display=on
Pause_When_Done=on
Preview_Start_Size=32
Preview_End_Size=4

and run

x-povray standard.ini +Iscene1.pov

If you want to render at a different resolution, add the +W and +H arguments, for example +W640 +H480 for 640x480 resolution.

A fallen column



A plane and a cylinder
In the second scene we add a stone cylinder lying on its side.

#include "colors.inc"
#include "stones1.inc"

// Monitor brightness
global_settings { assumed_gamma 2.2 }

// Background color
background { color LightBlue }

// The camera
camera {
    location <6, 3, -4>
    look_at <2.5, 2, 0>
}

// Two lights
light_source { <8, 7, 0> color White }
light_source { <2, 3, -20> color White }

// An infinite checkered plane
plane {
    <0, 1, 0>,
    0
    pigment {
 checker color Yellow, color Green
    }
    finish {
 ambient 0.3
 diffuse 0.6
    }
}

// A stone cylinder
cylinder {
    <-4, 2, 3>,
    <4, 2, 3>,
    2
    texture { T_Stone23 scale 4 }
    finish {
 ambient 0.3
 diffuse 0.6
    }
}


The cylinder statement starts with two coordinates which describe the end points of the cylinder. The next value is the radius of the cylinder. It has a stone texture, which requires a second include, stones1.inc. The finish is changed in the same way as we did with the plane. There is also a second light source at the front of the cylinder.

A closer look



A plane, a cylinder and a lens
In the third and final scene we add a glass lens.

#include "colors.inc"
#include "stones1.inc"
#include "glass.inc"

// Monitor brightness
global_settings { assumed_gamma 2.2 }

// Background color
background { color LightBlue }

// The camera
camera {
    location <6, 3, -4>
    look_at <2.5, 2, 0>
}

// Two lights
light_source { <8, 7, 0> color White }
light_source { <2, 3, -20> color White }

// An infinite checkered plane
plane {
    <0, 1, 0>,
    0
    pigment {
 checker color Yellow, color Green
    }
    finish {
 ambient 0.3
 diffuse 0.6
    }
}

// A stone cylinder
cylinder {
    <-4, 2, 3>,
    <4, 2, 3>,
    2
    texture { T_Stone23 scale 4 }
    finish {
 ambient 0.3
 diffuse 0.6
    }
}

// An intersection between two speres makes a lens
intersection {
    sphere {
 <2, 3, -1>
 2
    }
    sphere {
 <2, 3, 2>
 2
    }
    material {
 texture { T_Glass3 }
 interior { I_Glass }
    }
}


The lens is made using Constructive Solid Geometry (CSG). CSG is a way to build complex shapes by connecting several primitive shapes. In this case, we have built a lens by making two spheres, positioned so that they overlap slightly. The intersection keyword means that we want the shape of the space that are occupied by both spheres, in other words, a lens. Other ways of doing CSG are union, difference and merge.

The glass nature of the lens is achieved by the use of material. The texture describes the surface, and interior describes what's inside. The glass requires a third include, glass.inc.

You should try rendering this scene at a higher resolution, to better see the effects of the glass lens. Then you'll notice that it both magnifies the stone pattern, and reflects light comming from the sides.

What else can you do?


To get used to POV-Ray, try moving the objects, change colors, and move the camera. And when you are tired of this simple scene, fear not: Included with the POV-Ray distribution are loads of scene files. If you do a standard unix installation you'll find them in /usr/local/lib/povray31/scenes.

There is documentation too (and you will need it). Start with /usr/local/lib/povray31/html/povuser.htm. The configuration and tuning options in POV-Ray are endless. You can do reflection, refraction, bump mapping, fogs, custom lights and cameras, layered textures, metals, iridescence and animation, and use more complex shapes such as bicubic patch objects, blobs, height fields and fractals. It's all there.

The last images are a few examples from the advanced folder in the scenes collection. Click the images for larger versions.


chess2.png

diffract.png

fish13.png

quilt1.png

sunsethf.png

woodbox.png


| Back to normal page view |