You are here

Objects

Table of Contents


  • A more dramatic scene

    • Comments
    • "Include" files
    • The camera
    • The light source
    • Defining a background
    • Defining another object: the plane
    • The reflective sphere

A more dramatic scene

With the preceding scene in mind, let's analyze a somewhat more dramatic scene -- one which has been done so many times by ray-tracers that it's become a cliche:

// Persistence Of Vision raytracer version 3.0 sample file.
// Use copies of this file for starting your own scenes.

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

camera {
   location  <0, 4,-20>
   look_at <0,1,10>
   angle 25
}

light_source {<0, 20, -30> color White}

background {color Blue}

// Floor
plane { <0,1,0>, 0
   pigment {checker color White, Red}
   finish {Dull}}

// Sphere object
sphere { <0, 2, 0>, 1
   pigment {color White}
   finish {Mirror}      
   }



Render this with width 320, height 240, and this is what you'll get:

cliche.jpg

Pretty impressive! Let's go through the POV-Ray code above and dissect it piece by piece:

Comments

// Persistence Of Vision raytracer version 3.0 sample file.
// Use copies of this file for starting your own scenes.


These are comments, remarks that are ignored by the POV-Ray program. Comments follow the usual style in the programming language C++. Use a double slash "//" to "comment" text on a single line, and the pair of symbols "/*" and "*/"to enclose two or more lines of commented text. As an example:

//This comment can only go on one line,

/* whereas this one
   can spread out over
   several lines, if 
   it feels like it.
*/


Comments are very useful for making notes in your scene files, and make it much easier to track down problems (and rest assured, you will run into problems regularly). Now, back to the scene file we've been examining:

"Include" files

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


These are common include files. Specify an include file by using #include before the filename. Included files are literally included in a POV-Ray scene file when POV-Ray loads it; they make it easy to use specific objects (or colors, or just about anything else) in many POV-Ray scene files. For example, we'll use some colors from colors.inc to simplify our code and make it more understandable.

The camera

camera {
   location  <0, 4,-20>
   look_at <0,1,10>
   angle 25
}


Here's the camera. The location and look_at keywords are familiar. There's also an angle, which specifies the amount of space the camera is looking at. Increasing the angle widens the field of view; you can go anywhere from fisheye-lens-like views to extremely narrow, microscopic fields of view.

You'll also note that I wrote the camera statement differently than in the "cube in space" scene. POV-Ray doesn't care about "white space" -- you can use as many, or as few, spaces as you like in your POV-Ray scene files. You could write the previous camera declaration as:

camera {location  <0, 4,-20> look_at <0,1,10> angle 25}


and POV-Ray will interpret it in exactly the same way. The only thing you mustn't do is break up individual keywords with spaces. Similarly, in the large majority of cases, the order of keywords makes no difference: we could also write this camera as:

camera {look_at <0,1,10> location  <0, 4,-20>  angle 25}


Play around with the format of POV-Ray declarations until you find one that works well for you.

The light source

light_source {<0, 20, -30> color White}


Here's the light source. Notice that I haven't specified a color using color rgb; instead, I've simply used a simple, descriptive word. Thank the include files for that! One line in the colors.inc file simply defines the word White to mean color rgb <1,1,1>.

A cautionary note:Although POV-Ray lets you use white space freely, all commands and attributes in POV-Ray are case-sensitive. Specifying

Light_source {<0, 20, -30> color White}


causes POV-Ray to stop with an error message, since POV-Ray doesn't recognize Light_source as a light source. Similarly, a color name like yellow is not the same as Yellow, and will not do anything useful unless yellow is defined somewhere.

Defining a background

background {color Blue}


The background keyword specifies the color of every part of the image that isn't occupied or otherwise affected by another object. In effect, it's the color of all the (simulated) light rays that don't interact with anything else in the scene. As in the light source, there's a predefined color name, from an include file, that's easier to remember than the rgb description.

Defining another object: the plane

// Floor
 plane { <0,1,0>, 0
  texture {
   pigment {checker color White, Red}
   finish {Dull}}


Here's something a little more complicated. POV-Ray can define not only finite objects, like box, but also objects that stretch infinitely far in certain directions. The plane is an example of this. Define a plane with two quantities: a vector representing the normal, or perpendicular, to the plane, and a number representing how far along the normal the plane is. In this case, the normal vector is <0,1,0> or, the positive y-axis, which is vertical in the typical POV-Ray scene. Therefore, the plane is horizontal. Additionally, the second number, 0, ensures that the plane passes through y = 0.

This plane also has something called a texture. You use the texture keyword to describe most of the physical attributes of an object -- e.g., its color, how its surface is shaped, and so on.

The first section of our texture is something called pigment. Pigments determine the intrinsic color of an object. In the simplest form, a pigment block contains just a color definition, e.g.,

pigment {color Green}

but more complicated pigments are possible. Here, I've used, instead of a single color, the pigment checker. checker creates a pattern of 1 x 1 squares on whatever object it's applied to, coloring the squares with the two colors specified after color.

There's also something called finish in the texture block. Where pigment defines the coloring pattern of an object, finish describes how it interacts with light. Here, I've used a pre-defined finish, defined in "finish.inc", called "Dull". The "Dull" finish gives the object a smooth, somewhat flat appearance with very broad, diffuse surface highlights -- sort of like smooth wood or paper. Other finishes are defined in finish.inc; we'll discuss this in more detail later.

The reflective sphere

// Sphere object
sphere { <0, 2, 0>, 1
   pigment {color White}
   finish {Mirror}      
   }


And here's the shiny sphere. Defining a sphere is simple -- give a vector specifying the position of the center of the sphere, and a number specifying its radius.

I've taken a couple of shortcuts here. There is no "texture" block here -- the pigment and finish statements stand by themselves. POV-Ray will let you use these by themselves. Similarly, many very common statements can be condensed. For example, a color can be used by itself, outside of a pigment statement -- in fact, I used this shortcut for the simple "cube in space" scene at the beginning. For fairly simple objects like this sphere, this isn't a problem, but with more co mplicated textures using the whole texture block is a good idea.

The "Mirror" finish makes the sphere metallic-looking and highly reflective. In fact, it effectively turns off the color of the sphere itself (we've specified "White" above"), since it's now only reflecting its surroundings.

Theme by Danetsoft and Danang Probo Sayekti inspired by Maksimer