Scene files with POV-Ray
A Scene File describes the objects in a scene. The are generally the output from a modeling tool. They include a description of the model's geometery and often material and texture information as well. The are the input to a renderer.
Blender scene file format
- Blender uses a custom *.blend format by default. It is documented here: http://www.atmind.nl/blender/mystery_ot_blend.html
- Blender also exports scene information to the following formats: (Note - this list is not testable)
- *.dae (Collada - An open standard XML schema for exchanging digital assets among various graphics software applications.)
- *.ply (Known as the "Polygon File Format" or the "Stanford Triangle Format". This format was principally designed to store 3d data from digital scanners.)
- *.stl (A file format native to the stereolithography CAD software from 3D Systems. Also known as the "Standard Tesselation Language". STL describes surface geometry without any color or texture.)
- *.3ds (3D Studio - an early file format used by Autodesk 3ds Max for 3D modeling. Laregely outdated.)
- *.fbx (Autodesk FBX - Allows the storage of an object model, along with motion data, audio, and video.)
- *.obj (Wavefront - Open file format that represents 3D geometry.)
- *.x3d (X3D Extensible 3D - Open standard file format for 3d Graphics. Supports modeling, lighting, texturing, and shading.)
We are going to focus on POV-Ray, since it lets us build a scene file by hand.
POV-Ray is an open-source raytracer. You can find samples of POV-Ray images here: POV-Ray images on Google
POV-Ray Installation
POV-Ray cannot be installed by system administrators. The users must each install it themselves.
- In Mi300: There is an install icon on your desktop. Double-click it to install a copy of POV-Ray. You will have to install it once on each lab machine you use.
- Everywhere else: Download the installer from the manufacturer's website here.
POV-Ray scene files
Scene files generally contain at least four elements:
- Location and properties of camera
- Location and properties of lights
- Description of the modeled geometry
- Description of materials on the geometry
POV-Ray - Getting Started
The program starts with two samples: biscuit.pov and woodbox.pov
Here is an additional program to play with. It is the classic "Hello World" for working with a raytracer. It has a single reflective sphere hovering over a checkboard. In POV-Ray, click 'New', copy this text into the file editor, and save it as "Hello.pov".
// ------------------------------------------------------------------------
// The classic raytracer HelloWorld - a sphere hovering over a checkerboard
// (1) Camera
camera {
location <0, 8, -15>
look_at <0, 5, 0>
}
// (2) Lighting
global_settings { ambient_light 1.0 }
light_source {
<10, 15, -20> // Location
color rgb <1.0, 1.0, 1.0> // Color
}
light_source {
<-5, 12, -20> // Location
color rgb <0.5, 0.5, 0.5> // Color
}
// (3) Modeled Objects
plane {
y, -1 // Plane at y == -1
// (4) Material of plane
pigment {
checker // Checkerboard pigment
color rgbf <0.0, 0.0, 0.0, 0.0> // Opaque Black
color rgbf <1.0, 1.0, 1.0, 0.0> // Opaque White
}
finish {
diffuse 0.7
phong 0.1
reflection 0.0
}
scale 5 // Set size of checkers
}
sphere {
<0, 5, 0>, 4.0 // Center, radius
// (4) Material of sphere
pigment { color rgbf <0.0, 0.0, 1.0, .1>} // Opaque blue
finish {
diffuse 0.65 // Increases amount object is lit from light source
phong 0.6 // Increases specular highlights
reflection 0.5 // Increases amount of reflected light
}
}
// ------------------------------------------------------------------------
POV-Ray controls
Know these:
- Click "Run" to render the current scene.
- Turn off sound - click "Render->Sound Settings...", uncheck all three checkboxes, then hit "OK".
- Render settings - Use the droplist under the "New" and "Open" buttons. For fast renders, select a small image size with "No AA". For clean renders, select a larger size with "AA 0.3".
POV-Ray Coordinate System
The usual coordinate system for POV-Ray has the positive y-axis pointing up, the positive x-axis to the right, and the positive z-axis pointing into the screen.
Best described here.
POV-Ray Camera
You can maintain the proper coordinate orientation by putting the camera at a -Z coordinate and looking towards the origin:
camera {
location <0, 5, -10>
look_at <0, 5, 0>
}
Place an object at the origin and render. You can adjust your camera from here to frame the image.
Full documentation of the camera controls is here.
POV-Ray Objects
Raytracers can render the polygon mesh objects that we have seen in Blender, but they work more efficiently with basic objects that can be defined mathematically: spheres, cubes, planes, cylinders, etc. POV-Ray also includes such oddities as "Surface of Revolution" and "Blob" objects.
A full listing of object types in POV-Ray is here. In general - try to model with simple primitives before going to more complex primitives.
POV-Ray Lighting
In the real world, lighting is incredibly complex. Light arrives from multiple light sources and reflects off every surface in the room. We simplify this with a Global Illumination Model, which reduces the real-world complexities to a manageable algorithm.
One of the most popular lighting models is known as the "Phong Shading Model" or the "Phong Reflection Model". It is made up of the elements below (Image courtesy of the Wikipedia Foundation, http://en.wikipedia.org/wiki/Phong_shading)
The illumination model that POV-Ray uses includes the elements in the Phong Shading Model, plus reflection:
- Ambient - The general light that fills a scene but it not generated from any particular light source. It simulates the nth-level reflections that prevent shadows from getting too dark in the real world. In POV-Ray, this command controls ambient light: global_settings { ambient_light 1.0 }. Reducing this number makes the shadows darker.
- Diffuse - The effect that makes the side of objects facing a light source brighter, but without light reflecting off the object. This effect is especially pronounced on rough objects, like the sides of a stone building. In POV-Ray, the diffuse level is set from 0.0-1.0 in the finish properties of materials.
- Specular - The effect that gives an object shiny highlights. It is caused by the light reflecting off a smooth object and hitting your eye. This is especially pronounced on smooth, metallic objects like cars. In POV-Ray, this is controlled with the phong level in the finish properties of materials.
- Reflection - The effect that mirrors give. This effect does not add new light to the scene, but it does change the apparent color of existing objects.
Material properties
Objects in POV-Ray can be assigned a pigment and a finish.
A Pigment describes the color, and optionally the pattern and transparency of an object.
Pigment colors can be described with one of three commands:
- rgb: 3-vector term that describes red, green, and blue levels in the color. rgb <0,0,0> is black. rgb <1,1,1> is white. rgb <.3,0,0> is dark red, etc.
- rgbf: 4-vector term that includes RGB levels plus the amount of light that is filtered in passing through the object. This filtering changes the color of the light as it passes through the object. This is the effect from stained-glass windows. rgbf <0,0,1,.8> is a blue object that is highly translucent and only allows blue light to pass through it. It casts a blue shadow.
- rgbt: 4-vector term that includes RGB levels plus the amount of light that is transmitted through the object. This filtering does not change the color of the light as it passes through the object. This is the effect of clear glass bottles. rgbt <0,0,1,.8> is a slightly-blue object that is highly translucent and allows white light to pass through it.
The full documentation of rgb, rgbf, and rgbt is here.
More information on pigments, including the available patterns, is here.
A Finish describes the surface properties of an object. These are often the tactile properties of the material that you can feel with your fingers. For example, you can touch a surface and know whether it is glassy-smooth or rough like sandpaper, even if you cannot see the material.
The three finish properties we use most often are: diffuse, phong, and reflection. More properties are listed here.
Materials can be reused for multiple objects by using the #declare statement.
// ---------------------------------------------------------------
camera {
location <0, 5, -10>
look_at <0, 2, 0>
}
global_settings { ambient_light 1.0 }
light_source {
<10, 15, -20> // Location
color rgb <1.0, 1.0, 1.0> // Color
}
light_source {
<-5, 12, -20> // Location
color rgb <0.5, 0.5, 0.5> // Color
}
#declare legoRed = pigment { color rgb <1.0, 0.0, 0.0> }
#declare legoBlue = pigment { color rgb <0.0, 0.0, 1.0> }
#declare glossPlastic =
finish {
diffuse 0.7
phong 0.6
reflection 0.2
}
#declare legocyl = cylinder { <0,-.2,0> <0,0.17,0> 0.3 }
#declare HT = 1.2;
#declare TRIM = .01;
//Build in practical units: (1x, 1y)== a 1x1 lego
#declare lego_1x1 =
union {
box { <0+TRIM,0+TRIM,0+TRIM> <1-TRIM, 1.2-TRIM, 1-TRIM> }
object { legocyl translate <0.5,HT,0.5> }
}
#declare lego_2x1 =
union {
box { <0+TRIM,0+TRIM,0+TRIM> <2-TRIM, 1.2-TRIM, 1-TRIM> }
object { legocyl translate <0.5,HT,0.5> }
object { legocyl translate <1.5,HT,0.5> }
}
#declare lego_4x2 =
union {
box { <0+TRIM,0+TRIM,0+TRIM> <4-TRIM, 1.2-TRIM, 2-TRIM> }
object { legocyl translate <0.5,HT,0.5> }
object { legocyl translate <1.5,HT,0.5> }
object { legocyl translate <2.5,HT,0.5> }
object { legocyl translate <3.5,HT,0.5> }
object { legocyl translate <0.5,HT,1.5> }
object { legocyl translate <1.5,HT,1.5> }
object { legocyl translate <2.5,HT,1.5> }
object { legocyl translate <3.5,HT,1.5> }
}
object { lego_1x1 texture { legoRed glossPlastic } translate <-3, 0, 0> }
object { lego_2x1 texture { legoRed glossPlastic } translate <-2, 0, 0> }
object { lego_2x1 texture { legoRed glossPlastic } translate <-1, HT, 0> }
object { lego_4x2 texture { legoBlue glossPlastic } translate < 3, 0, -2> }
// ---------------------------------------------------------------