1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401
|
<!-- This file copyright Persistence of Vision Raytracer Pty. Ltd. 2003-2004 -->
<html>
<head>
<!-- NOTE: In order to users to help find information about POV-Ray using -->
<!-- web search engines, we ask you to *not* let them index documentation -->
<!-- mirrors because effectively, when searching, users will get hundreds -->
<!-- of results containing the same information! For this reason, the two -->
<!-- meta tags below disable archiving and indexing of this page by all -->
<!-- search engines that support these meta tags. -->
<meta content="noarchive" name="robots">
<meta content="noindex" name="robots">
<meta content="no-cache" http-equiv="Pragma">
<meta content="0" http-equiv="expires">
<title>2.2.1 Our First Image</title>
<link href="povray35.css" rel="stylesheet" type="text/css">
</head>
<body>
<table class="NavBar" width="100%">
<tr>
<td align="left" nowrap="" valign="middle" width="32">
<a href="s_56.html"><img alt="previous" border="0" src="prev.png"></a>
</td>
<td align="left" valign="middle" width="30%">
<a href="s_56.html">2.2 Getting Started</a>
</td>
<td align="center" valign="middle">
<strong class="NavBar">POV-Ray 3.6 for UNIX documentation</strong><br> <strong>2.2.1
Our First Image</strong>
</td>
<td align="right" valign="middle" width="30%">
<a href="s_58.html">2.2.2 Basic Shapes</a>
</td>
<td align="right" nowrap="" valign="middle" width="32">
<a href="s_58.html"><img alt="next" border="0" src="next.png"></a>
</td>
</tr>
</table>
<h3><a name="s02_02_01">2.2.1 </a>Our First Image</h3>
<dl class="famousquote">
<dt>
<em>You know you have been raytracing too long when ...<br> ... You have gone full circle and find your self
writing a scene that contains only a shiny sphere hovering over a green and yellow checkered plane ...</em>
<dd>
<em>-- Ken Tyler</em>
</dl>
<p>
We will create the scene file for a simple picture. Since ray-tracers thrive on spheres, that is what we will
render first.
</p>
<h4><a name="s02_02_01_01">2.2.1.1 </a>Understanding POV-Ray's Coordinate System</h4>
<a name="s02_02_01_01_i1">
<p>
First, we have to tell POV-Ray where our camera is and where it is looking. To do this, we use 3D coordinates. The
usual coordinate system for POV-Ray has the positive y-axis pointing up, the positive x-axis pointing to the right,
and the positive z-axis pointing into the screen as follows:<a name="s02_02_01_01_i2"><a name="s02_02_01_01_i3">
</p>
<p>
<br><center><img alt="The left-handed coordinate system" src="images/tutorial/handed.png"></center>
</p>
<p>
This kind of coordinate system is called a left-handed coordinate system. If we use our left hand's fingers we can
easily see why it is called left-handed. We just point our thumb in the direction of the positive x-axis (to the
right), the index finger in the direction of the positive y-axis (straight up) and the middle finger in the positive
z-axis direction (forward). We can only do this with our left hand. If we had used our right hand we would not have
been able to point the middle finger in the correct direction.
</p>
<p>
The left hand can also be used to determine rotation directions. To do this we must perform the famous "<em>Computer
Graphics Aerobics</em>" exercise. We hold up our left hand and point our thumb in the positive direction of the
axis of rotation. Our fingers will curl in the positive direction of rotation. Similarly if we point our thumb in the
negative direction of the axis our fingers will curl in the negative direction of rotation.
</p>
<p>
<img alt="Computer Graphics Aerobics" src="images/tutorial/aerobics.png">
</p>
<p>
In the above illustration, the left hand is curling around the x-axis. The thumb points in the positive x direction
and the fingers curl over in the positive rotation direction.
</p>
<p>
<a name="s02_02_01_01_i4"> If we want to use a right-handed system, as some CAD systems and modelers do, the <code>right</code>
vector in the camera specification needs to be changed. See the detailed description in "<a href="s_100.html#s03_03_01_01_07">Handedness</a>".
In a right-handed system we use our right hand for the "Aerobics".
</p>
<p>
There is some controversy over whether POV-Ray's method of doing a right-handed system is really proper. To avoid
problems we stick with the left-handed system which is not in dispute.
</p>
<h4><a name="s02_02_01_02">2.2.1.2 </a>Adding Standard Include Files</h4>
<a name="s02_02_01_02_i1"><a name="s02_02_01_02_i2">
<dl class="famousquote">
<dt>
<em>You know you have been raytracing too long when ...<br> ... you've just seen Monsters.Inc at the movies, and
you are wondering when they will release Monsters.Pov.</em>
<dd>
<em>-- Fabien Mosen</em>
</dl>
<p>
Using our personal favorite text editor, we create a file called <code>demo.pov</code>. Some versions of POV-Ray
come with their own built-in text editor which may be easier to use. We then type in the following text. The input is
case sensitive, so we have to be sure to get capital and lowercase letters correct.
</p>
<pre>
#include "colors.inc" // The include files contain
#include "stones.inc" // pre-defined scene elements
</pre>
<p>
The first include statement reads in definitions for various useful colors. The second include statement reads in a
collection of stone textures. POV-Ray comes with many standard include files. Others of interest are:
</p>
<pre>
#include "textures.inc" // pre-defined scene elements
#include "shapes.inc"
#include "glass.inc"
#include "metals.inc"
#include "woods.inc"
</pre>
<p>
They read pre-defined textures, shapes, glass, metal, and wood textures. It is a good idea to have a look through
them to see a few of the many possible shapes and textures available.
</p>
<p>
We should only include files we really need in our scene. Some of the include files coming with POV-Ray are quite
large and we should better save the parsing time and memory if we do not need them. In the following examples we will
only use the <code>colors.inc</code>, and <code>stones.inc</code> include files.
</p>
<p>
We may have as many include files as needed in a scene file. Include files may themselves contain include files,
but we are limited to declaring includes nested only ten levels deep.
</p>
<p>
Filenames specified in the include statements will be searched for in the current directory first. If it fails to
find your .Inc files in the current directory, POV-Ray searches any "<a href="s_95.html#s03_01_02_05_04">library
paths</a>" that you have specified. Library paths are options set by the <code>+L</code> <a href="s_64.html#s02_02_08_01">command-line
switch</a> or <code><a href="s_95.html#s03_01_02_05_04">Library_Path</a></code> option. See the chapter "<a href="s_64.html#s02_02_08">Setting
POV-Ray Options</a>" for more information on library paths.
</p>
<p>
Because it is more useful to keep include files in a separate directory, standard installations of POV-Ray place
these files in the c:\povray3\include directory (replace 'c:\povray3' with the actual directory that you installed
POV-Ray in). If you get an error message saying that POV-Ray cannot open "<code>colors.inc</code>" or other
include files, make sure that you specify the library path properly.
</p>
<h4><a name="s02_02_01_03">2.2.1.3 </a>Adding a Camera</h4>
<a name="s02_02_01_03_i1">
<p>
The <code>camera</code> statement describes where and how the camera sees the scene. It gives x-, y- and
z-coordinates to indicate the position of the camera and what part of the scene it is pointing at. We describe the
coordinates using a three-part <em>vector</em>. A vector is specified by putting three numeric values between a pair
of angle brackets and separating the values with commas. We add the following camera statement to the scene.
</p>
<pre>
camera {
location <0, 2, -3>
look_at <0, 1, 2>
}
</pre>
<p>
Briefly, <code>location <0,2,-3></code> places the camera up two units and back three units from the center
of the ray-tracing universe which is at <0,0,0>. By default +z is into the screen and -z is back out of the
screen.
</p>
<p>
Also <code>look_at <0,1,2></code> rotates the camera to point at the coordinates <0,1,2>. A point 1
unit up from the origin and 2 units away from the origin. This makes it 5 units in front of and 1 unit lower than the
camera. The <code>look_at</code> point should be the center of attention of our image.
</p>
<h4><a name="s02_02_01_04">2.2.1.4 </a>Describing an Object</h4>
<a name="s02_02_01_04_i1">
<p>
Now that the camera is set up to record the scene, let's place a yellow sphere into the scene. We add the following
to our scene file:
</p>
<pre>
sphere {
<0, 1, 2>, 2
texture {
pigment { color Yellow }
}
}
</pre>
<p>
The first vector specifies the center of the sphere. In this example the x coordinate is zero so it is centered
left and right. It is also at y=1 or one unit up from the origin. The z coordinate is 2 which is five units in front
of the camera, which is at z=-3. After the center vector is a comma followed by the radius which in this case is two
units. Since the radius is half the width of a sphere, the sphere is four units wide.
</p>
<h4><a name="s02_02_01_05">2.2.1.5 </a>Adding Texture to an Object</h4>
<a name="s02_02_01_05_i1">
<p>
After we have defined the location and size of the sphere, we need to describe the appearance of the surface. The <code>texture</code>
statement specifies these parameters. Texture blocks describe the color, bumpiness and finish properties of an object.
In this example we will specify the color only. This is the minimum we must do. All other texture options except color
will use default values.
</p>
<p>
The color we define is the way we want an object to look if fully illuminated. If we were painting a picture of a
sphere we would use dark shades of a color to indicate the shadowed side and bright shades on the illuminated side.
However ray-tracing takes care of that for you. We only need to pick the basic color inherent in the object and
POV-Ray brightens or darkens it depending on the lighting in the scene. Because we are defining the basic color the
object actually <strong> has</strong> rather than how it <strong>looks</strong> the parameter is called <code>pigment</code>.
</p>
<p>
Many types of color patterns are available for use in a pigment statement. The keyword <code>color</code> specifies
that the whole object is to be one solid color rather than some pattern of colors. We can use one of the color
identifiers previously defined in the standard include file <code> colors.inc</code>.
</p>
<p>
If no standard color is available for our needs, we may define our own color by using the <a href="#l20">color</a>
keyword followed by <code>red</code>, <code>green</code>, and <code> blue</code> keywords specifying the amount of
red, green and blue to be mixed. For example a nice shade of pink can be specified by:
</p>
<pre>
color red 1.0 green 0.8 blue 0.8
</pre>
<p class="Note">
<strong>Note:</strong> the international - rather than American - form "colour" is also
acceptable and may be used anywhere that "color" may be used.
</p>
<p>
The values after each keyword should be in the range from 0.0 to 1.0. Any of the three components not specified
will default to 0. A shortcut notation may also be used. The following produces the same shade of pink:
</p>
<pre>
color rgb <1.0, 0.8, 0.8>
</pre>
<p>
In many cases the <code>color</code> keyword is superfluous, so the shortest way to specify the pink color is:
</p>
<pre>
rgb <1.0, 0.8, 0.8>
</pre>
<p>
Colors are explained in more detail in section "<a href="s_97.html#s03_02_01_05">Specifying Colors</a>".
</p>
<h4><a name="s02_02_01_06">2.2.1.6 </a>Defining a Light Source</h4>
<a name="s02_02_01_06_i1">
<p>
One more detail is needed for our scene. We need a light source. Until we create one, there is no light in this
virtual world. Thus we add the line
</p>
<pre>
light_source { <2, 4, -3> color White}
</pre>
<p>
to the scene file to get our first complete POV-Ray scene file as shown below.
</p>
<pre>
#include "colors.inc"
background { color Cyan }
camera {
location <0, 2, -3>
look_at <0, 1, 2>
}
sphere {
<0, 1, 2>, 2
texture {
pigment { color Yellow }
}
}
light_source { <2, 4, -3> color White}
</pre>
<p>
The vector in the <code>light_source</code> statement specifies the location of the light as two units to our
right, four units above the origin and three units back from the origin. The light source is an invisible tiny point
that emits light. It has no physical shape, so no texture is needed.
</p>
<p>
That's it! We close the file and render a small picture of it using whatever methods you used for your particular
platform. If you specified a preview display it will appear on your screen. If you specified an output file (the
default is file output on), then POV-Ray also created a file.
</p>
<p class="Note">
<strong>Note:</strong> if you do not have high color or true color display hardware then the preview
image may look poor but the full detail is written to the image file regardless of the type of display.
</p>
<p>
The scene we just traced is not quite state of the art but we will have to start with the basics before we soon get
to much more fascinating features and scenes.
</p>
<p>
<a name="l20">
<small><strong>More about "color"</strong></small>
</a>
<ul>
<li><small>
<a href="s_155.html#s03_08_03_03">3.8.3.3 Colors</a> in 3.8.3 Language Basics
</small>
<li><small>
<a href="s_97.html#s03_02_01_05">3.2.1.5 Specifying Colors</a> in 3.2.1 Language Basics
</small>
</ul>
</p>
<br>
<table class="NavBar" width="100%">
<tr>
<td align="left" nowrap="" valign="middle" width="32">
<a href="s_56.html"><img alt="previous" border="0" src="prev.png"></a>
</td>
<td align="left" valign="middle" width="30%">
<a href="s_56.html">2.2 Getting Started</a>
</td>
<td align="center" valign="middle">
<strong>2.2.1 Our First Image</strong>
</td>
<td align="right" valign="middle" width="30%">
<a href="s_58.html">2.2.2 Basic Shapes</a>
</td>
<td align="right" nowrap="" valign="middle" width="32">
<a href="s_58.html"><img alt="next" border="0" src="next.png"></a>
</td>
</tr>
</table>
</body> </html>
|