Raytracing with POVRay
Topics


This page has had 2121 views

Povray

POVRay is a freeware application that creates photo-realistic raytraced scenes from a text file containing lines of Scene Description Language (SDL).

Raytracing is a technique whereby a scene is simulated by using a computer to calculate what happens to rays of light as they travel from a light source to a camera, interacting with the objects in the scene on the way. There are numerous raytracing packages available, some are relatively easy to use as they have 'drag and drop' style user interfaces but you pay for these whereas POVRay is free. There is also an argument that the GUI approach to scene design is a limitation.

You can model objects which can be more or less complex and then give the objects a texture which can range from a simple single colour pigment to extremely complex textures which can model wood or stone for example, or can in fact be anything. It has to be said that what you can do is truly limited by your imagination.

If you are new to all of this, please read the section below which describes how a simple scene is made up.

Walkthrough of a simple scene

POVRay uses the concept of creating an image in 3-D space, so first you have to visualise this. At the start, it's empty, and dark. Before we can even see anything in it, we have to specify a camera, and a Light Source. Let's then create the Raytracing classic image- a mirrored ball with a checker floor and sky background.

camera {
   location <0,10,-20>
   look_at <0,0,0>
}

This specifies the camera. It's fairly self explanatory! Notice that the general syntax of the SDL is C-like. The location, and pointing of thecamera are specified as cartesian coordinates, in the x, y and z axes respectively. x is left -to-right, y is up-and-down, and z is negative towards you and positive away from you. I hope that makes sense...

We don't have an image yet!

light_source {
   <0,10,-20>
   color rgb <1,1,1>
}  

This specifies the location and colour of the light source. The color vector 1,1,1 is full white- the componenets are red, green and blue each of which can have a value between 0 and 1.

Getting there...

sphere {
 <0,0,0>,5
 pigment {
  color rgb <0,1,0>
 }
}

Now it starts to get interesting. This specifies the sphere. 0,0,0 is it's location, and its 5 units in radius. At first, we will give it a plain green pigment since we'd not see it if it was mirrored; without other things in the scene... We can now render the scene and see what we get.

plane {
 <0,1,0>, -5
 pigment {
  checker color rgb <1,1,1>
  color rgb<0,0,0>
  scale 10
 }
}

This specifies a plane, normal to the y axis and intersecting it at -5, so the bottom of the sphere just rests on it. We give it a checker pattern of black and white squares- scaled up by 10. It renders like this...

sky_sphere {
 pigment {
  Bright_Blue_Sky
   scale 0.2
  }
 }
}

This specifies a sky-sphere object. This is a hollow sphere that encloses the scene. It's inside surface is given the texture Bright_Blue_Sky which is defined in an include file elsewhere.

sphere {
 <0,0,0>,5
 pigment {
  color rgb<.1, .1, .1>
 }
 finish {
  reflection 1
 }
}

We can now make the changes to the sphere object that will make it look as though it were highly polished metal, and we can now render the completed scene.

Learning POVRay

The best way to learn POVRay is to download it and get stuck in. The application you download includes a powerful SDL editor, and the help file and documentation supplied is excellent- plus, there is always plenty more help and examples on the internet.

The official POVRay web site is www.povray.org.

In order to run the example above, you'll need to add the following lines at the top of the file:

#include "colors.inc"
#include "textures.inc"

This is to ensure that the sky texture will work.

Please also take a look at my galleries while you're here.




Last updated 10/2/08