You are here

A simple scene

Table of Contents

  • Lights, Camera, Objects! The three essentials
  • The Camera
  • The Light Source
  • The Box Object

All right. You're probably tired of reading and want to create something. Let's start with a couple of demonstrations that illustrate the abilities of POV-Ray, while also providing examples of its language's syntax.

Lights, Camera, Objects! The three essentials

For our first example, let's create a cube hanging in space. The following POV-Ray code will do this -- try opening an editor, then cutting and pasting this in from your browser:

camera {location <5,5,5>  look_at <0,0,0> }

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

box { <-1,-1,-1>, <1,1,1> 
      color rgb <1,0,0> }

Let's render this at 320x240 pixels, and see the result:


Voila! Now, what have we done exactly? Let's go through it step by step.

The Camera

The first line in this sample file:

camera {location <5,5,5>  look_at <0,0,0> }

defines the camera. A camera declaration in POV-Ray defines where the scene -- the collection of objects being rendered -- is being viewed from, how much of it is being viewed, and so on.

You can tell the camera to have many "features", but the two most important are the location and the look_at attributes. These determine the orientation of the camera -- the location in space it occupies, and the direction in which it points, respectively.

Since positions and directions are easily represented by vectors, that's what we use. POV-Ray represents a vector with numbers inside angle brackets, like <1,2,3>. In the example above, the camera is 5 units along +x, 5 along +y, and 5 along +z, and it looks towards <0,0,0>, i.e., the origin. You will routinely use vectors like these any time you want to specify a position or a direction.

In this example, I've used integers for the three distances, but most of the time, decimal (or "floating-point") quantities are acceptable. There are a couple of times where they aren't -- I'll discuss those as they arise.

Warning for engineers, scientists, and other geeks: For historical reasons, the default coordinate system has a potentially irritating quirk: it's left-handed. Moreover, the x-y plane, in the default orientation, lies in the plane of the screen, making it vertical rather than horizontal. Here's the POV-Ray coordinate system:

POV-Ray's coordinate system

The Light Source

We can't see very much without some light to light things up. You use the light_source declaration to specify a light, as well as its various attributes. The code fragment from above:

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

specifies something called a point light. A point light source is just that -- a single point in space that radiates in all directions. Since it has no dimensions, it won't show up in your scene, even as a dot (so don't bother trying to look for it). POV-Ray can simulate "extended" light sources, but point lights work well for many simple scenes, so we'll stick to them for now.

The first vector in the light_source specifies the location of the light, much as the location keyword in a camera does. The second is a color. The color attribute is conventionally represented by a red/green/blue (RGB) triplet of numbers. Each number represents the saturation ("amount") of each of these colors, and the whole set is treated as a vector (i.e., it's in angle brackets). Thus

color rgb <1,0,0>

indicates "pure" red, whereas something like

color rgb <1,1,0>

gives a red-green combination (i.e., yellow), and

color rgb <0.1,0.1,0.1>

indicates equal amounts of all three primary colors, but at low saturations -- i.e., a very dark gray, or, in the case of a light source, a very feeble white light.

You'll be using color a lot, so familiarize yourself with the syntax.

The Box Object

POV-Ray is capable of creating huge numbers of exotic shapes and objects, simply by taking a mathematical description of them and drawing the result. The "box" object is a simple example. The third line in the scene file:

box { <-1,-1,-1>, <1,1,1> 
      color rgb <1,0,0> }

draws a box -- a solid with rectangular sides, all perpendicular to each other. The size and location of the box are specified by two vectors, which represent the positions of two diagonally opposite corners. Here, all the side lengths are the same -- 2 units -- so we get a cube.

To make sure the corners chosen are unique, you must pick one to contain the lowest values of x,y, and z, and the other to contain the highest. This can be a bit difficult to visualize. Here's a rendition of this cube with two little white markers indicating the relevant corners:


Finally, this box has a color. Specify it in exactly the same way as the color for a light source: i.e., as a vector representing the red, green, and blue components of the color. Here, we've used color rgb <1,0,0>, which gives a pure red color.

Theme by Danetsoft and Danang Probo Sayekti inspired by Maksimer