Wednesday, July 25th, 2012...9:09 pm

Become your own Pixar

Jump to Comments

Computer generated images are created, as clearly indicated by their name, on computers. How do computers generate such lovely pictures? A key is math modeling – underneath such programs are models of the physical world that determine the color of a pixel on the screen based on the light and the physical characteristics of the objects in the scene.

This is the first of a series of blog postings in which we will learn to use POV-Ray, which is free software package that creates ray-traced images. You will need to download the software to create the images in this posting. Note, at the time of this posting, there is only a version that works on Windows.

This blog follows how I’ve taught POV-Ray in 50 minutes to my students semester after semester, with many noting it as one of their favorite topics. I dare say this is not simply because this isn’t going to be on any of their tests! This particular posting takes about 15 minutes in class.

In this posting, we’ll learn to construct the image below.

Can you imagine your making this, with your own artistic decisions, moments from now? If you hesitate as you may struggle with drawing, keep in mind that a great advantage of ray-tracing is that the burden of drawing is put on the computer! Ray-tracing can require millions and even billions of complex mathematical calculations. All you do is create a source file that is simply a text file.

For example, the code below created the picture we saw above:


// Filename: spheres_color.pov

// Point straight ahead at the yellow sphere's center
camera {
location <0, 1, -6>
look_at <0, 1, 2>
}

// yellow sphere
sphere {
<0, 2, 2>, 1
texture {
pigment { color red 1 green 1 }
finish { phong 1 }
}
}

// A magenta sphere on the right of the yellow sphere
sphere {
<3, 1, 2>, 1
texture {
pigment { color red 1 blue 1 }
finish { phong 1 }
}
}

// A cyan sphere on the left of the yellow sphere
sphere {
<-3, 1, 2>, 1
texture {
pigment { color green 1 blue 1 }
finish { phong 1 }
}
}

// The checkered floor
plane {
<0, 1, 0>, 0
texture{
pigment {checker color red 1 green .5 color blue .8 red .5 green .5}
}
}

// A white light in front of the camera to the right
// and above.
light_source {
<3, 3, -3> color red 1 green 1 blue 1
}

First, consider the code:

camera {
location <0, 1, -6>
look_at <0, 1, 2>
}

This puts the camera at the coordinates (0,1,-6). Regardless of where you place the camera, it will be pointed at the point (0,1,2). In order to create our first POV image, we need to understand the coordinate system used by the program. You will place many objects into 3D space using POV. Looking at your display, the x-axis is horizontal and the y-axis is vertical with positive x and y running to the right and up, respectively. Finally, positive z goes into the display and away from the viewer.

Now, let’s change the location of the camera. Let’s change

location <0, 1, -6>

to read

location <0, 10, -6>

What just happened? We moved the camera up to y = 10. Here is the resulting image:

Now, let’s change this line to read

location <10, 1, -6>

which results in the image

Let’s return the line above to read:

location <0, 1, -6>

and find the following code:

sphere {
<0, 2, 2>, 1
texture {
pigment { color red 1 green 1 }
finish { phong 1 }
}
}

This places a sphere of radius 1 with its center at (0,2,2). It is colored with the full intensity possible in red and of green. This creates the yellow sphere in the image. Let’s change the radius of the sphere to be 2 which involves making the second line of code to read:

<0, 2, 2>, 2

This results in the image:

Now, let’s return to a sphere of radius 1 but change the center to be at (0,0,2) by writing the line:

<0, 0, 2>, 1

This creates the image:

Now, let’s move the center to (0,2,2). Can you do this? It should create the following image:

Finally, let’s change the color of the sphere. We change the code:

texture {
pigment { color red 1 green 1 }
finish { phong 1 }
}

to read

texture {
pigment { color red 0.5 green 1 }
finish { phong 1 }
}

which reduces the amount of red intensity in the color to half its possible intensity.

With these tools, you can begin to create your own images. Here are some exercises, although you may find more interesting directions!

Exercises:

  • Experiment with other positions for the camera.
  • Change the position and even radius (there is documentation in the code) of one of the other spheres.
  • Alter the coloring and phong (keep the numbers between 0 and 1) of the objects. See what happens as you alter these attributes. What does phong control?
  • Experiment with the light_source command. What happens if you remove it entirely?
  • Try adding more spheres and see what you can create.
  • Try stacking the spheres on each other.

Have fun creating images with math and computing!



Leave a Reply