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 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557
|
<!-- 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.3.6 Simple Media Tutorial</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_70.html"><img alt="previous" border="0" src="prev.png"></a>
</td>
<td align="left" valign="middle" width="30%">
<a href="s_70.html">2.3.5 Using Atmospheric Effects</a>
</td>
<td align="center" valign="middle">
<strong class="NavBar">POV-Ray 3.6 for UNIX documentation</strong><br> <strong>2.3.6
Simple Media Tutorial</strong>
</td>
<td align="right" valign="middle" width="30%">
<a href="s_72.html">2.3.7 Radiosity</a>
</td>
<td align="right" nowrap="" valign="middle" width="32">
<a href="s_72.html"><img alt="next" border="0" src="next.png"></a>
</td>
</tr>
</table>
<h3><a name="s02_03_06">2.3.6 </a>Simple Media Tutorial</h3>
<a name="s02_03_06_i1">
<p>
Media in POV-Ray is a very versatile feature and can be used for a very diverse set of special effects such as
glows, smoke, dust, fog, etc. However, due to its versatility, media is not one of the easiest and simplest features
of POV-Ray and often requires experience for getting things to look good.
</p>
<h4><a name="s02_03_06_01">2.3.6.1 </a>Types of media</h4>
<p>
There are three types of media in POV-Ray: Emitting, absorbing and scattering. They have the following properties:
</p>
<ul>
<li>
Emitting: This is an additive media, which is handled as if it only emits light (note: it does not emit light to
its surroundings like a <code>light_source</code> does; this just describes how it affects the rays going through
it). That is, the color of the media is added to the color of the ray passing through it. Light sources do not have
any effect at all in it (ie. it does not affect shadows in any way).
</li>
<li>
Absorbing: This is a substractive media. This media substracts (absorbs) its coloration from the ray passing
through it. Light sources are taken into account only in the shadow of the media (that is, absorbing media casts a
shadow).
</li>
<li>
Scattering: This is the most advanced media type as it fully takes into account light passing through it. That
is, this media is lit by light sources (and thus, for example, nearby objects can cast shadows into the scattering
media).
</li>
</ul>
<p>
Emitting and absorbing medias are the simplest and thus fastest ones. Emitting media can be used for things like
glows, lasers, sparkles and similar light-emitting effects. Absorbing media can be used for things like smoke and fog
(the difference between the <code>fog</code> feature of POV-Ray is that the density of an absorbing media can be
modified by a pattern and the media can be contained inside an object).
</p>
<p>
Scattering media is the more advanced and slower type. It is somewhat similar to absorbing media except that it is
fully lit by light sources. This can be used for smoke or fog with visible lightbeams and shadows.
</p>
<h4><a name="s02_03_06_02">2.3.6.2 </a>Some media concepts</h4>
<p>
Media can be global to the whole universe, or it can be contained by an object. In the latter case the media is
defined in the <code>interior</code> block of the object definition.
</p>
<p>
For an object to be able to contain media (or to allow media from other objects or the global media inside itself)
it has to be defined as <code>hollow</code> (a common mistake is to forget adding this keyword). If an object with no
media should not allow media inside itself (eg. a solid glass ball), then <code>hollow</code> should not be defined
for that object.
</p>
<p>
If media is defined in the <code>interior</code> of an object or as a global media it will have a constant density
throughout the object/universe. However, a density pattern can be specified for non-uniform media. Also all kinds of
transformations can be applied to the media. This is specially useful for various effects (such as smoke with certain
shape).
</p>
<h4><a name="s02_03_06_03">2.3.6.3 </a>Simple media examples</h4>
<h5><a name="s02_03_06_03_01">2.3.6.3.1 </a>Emitting media</h5>
<p>
Let's start with a very simple scene showing an emitting media using a spherical density map. Emitting media is
used with the <code>emission</code> keyword followed by a color value. This color value tells the overall color of the
media:
</p>
<pre>
global_settings { assumed_gamma 1 }
background { rgb 1 }
camera { location <3,4,-5>*.8 look_at 0 angle 35 }
light_source { <20,40,10>, 1 }
box // floor
{ <-1.5,-1.01,-1.5>, <1.5,-1.2,1.5>
pigment { checker rgb 0.75, rgb 0.25 scale 0.2 }
}
sphere // transparent sphere containing media
{ 0,1 pigment { rgbt 1 } hollow
interior
{ media
{ emission 1
density
{ spherical density_map
{ [0 rgb 0]
[0.4 rgb <1,0,0>]
[0.8 rgb <1,1,0>]
[1 rgb 1]
}
}
}
}
}
</pre>
<p>
Note that the <code>spherical</code> pattern gets values from 0 in the outer surface of a unit sphere to 1 in the
origin (that is, the density with the index value 1 will be the density at the center of the media).
</p>
<p>
The color values in the density map tell what color the media is emitting at a certain point in the pattern. That
is, for example when the pattern gets the value 0.4, the media will be completely red at that place. If the color is <code><0,0,0></code>,
it means that the media does not emit any light at all in that location.
</p>
<p>
Note that the density map colors are multiplied by the color given with the <code>emission</code> keyword; since 1
is used in this case, the density map colors are not affected.
</p>
<p>
Thus, this will give us a media with a bright white center which fades to yellow and red at the outer limits of the
unit sphere:
</p>
<p>
<img alt="Simple emitting media example" src="images/tutorial/mediatut1.png">
</p>
<p>
As you can see from the image, the emitting media is invisible against white background. This is due to its
additive nature (any color added to pure white gives pure white). In fact, emitting media gives usually best results
for dark backgrounds.
</p>
<h5><a name="s02_03_06_03_02">2.3.6.3.2 </a>Absorbing media</h5>
<p>
Modifying the previous example to use absorbing media is rather simple: Simply change the <code>emission</code>
keyword for <code>absorption</code>. However, the colors we used above are not very illustrative for absorbing media,
so let's change them a bit like this:
</p>
<pre>
media
{ absorption 1
density
{ spherical density_map
{ [0 rgb 0]
[0.4 rgb 0]
[0.5 rgb <0,0.5,1>]
[1 rgb <0,1,1>]
}
}
}
</pre>
<p>
<img alt="Simple absorbing media example" src="images/tutorial/mediatut2.png">
</p>
<p>
The feature which we immediately notice in the image is that the media seems to be inverted from the colors
specified in the density map: Blueish colors were specified in the map, but the image shows a reddish media. This is
perfectly normal and to be expected from the substractive nature of absorbing media: The media actually absorbs the
colors we specified in the density map. This means that for example specifying a white color (<code><1,1,1></code>)
in the density map will absorb all colors, thus resulting in a dark media.
</p>
<p>
Note how this media has a shadow: light rays passing through the media are absorbed.
</p>
<p>
Because of its substractive nature, absorbing media works well with light backgrounds and not very well with dark
ones.
</p>
<h5><a name="s02_03_06_03_03">2.3.6.3.3 </a>Scattering media</h5>
<p>
Since scattering media fully takes light sources into account we need to make a slightly more complex scene to see
this. Let's modify the above example by replacing the sphere with a box containing evenly distributed scattering
media, and a cylinder which will cast a shadow onto the media:
</p>
<pre>
box
{ -1,1 pigment { rgbt 1 } hollow
interior
{ media
{ scattering { 1, 0.5 }
}
}
}
cylinder
{ <0.9, -1, 0.7>, <0.9, 0.9, 0.7>, 0.5
pigment { rgb <1, 0.8, 0.5> }
}
</pre>
<p>
<img alt="Simple scattering media example" src="images/tutorial/mediatut3.png">
</p>
<p>
(The effect may look a bit unnatural for a fog effect because the media is contained inside a box and the cylinder
is partially out of this box, but this is done to better visualize what is happening.)
</p>
<p>
The <code>scattering</code> keyword takes more parameters than the other two. The first number inside the curly
brackets is the scattering media type. In this example we used scattering media type 1. A full list of scattering
media types is given in the section <code><a href="s_129.html#s03_06_02_01_03"> scattering </a></code> of the Media
reference.
</p>
<p>
The second parameter is the overall color of the media, similar to the parameter of the other two media types.
</p>
<p>
An optional third parameter can be given with the <code>extinction</code> keyword inside the curly brackets. This
keyword controls how fast the scattering media absorbs light and has to be used sometimes to get the desired effect,
such as when the media absorbs too much light.
</p>
<p>
Tip: If you are getting a really dense or dark scattering media, try different values for the color and the
extinction value (usually values between 0 and 1). It is usually enough to play with these two values to get the
desired effect.
</p>
<h4><a name="s02_03_06_04">2.3.6.4 </a>Multiple medias inside the same object</h4>
<p>
Emitting media works well with dark backgrounds. Absorbing media works well for light backgrounds. But what if we
want a media which works with both type of backgrounds?
</p>
<p>
One solution for this is to use both types of medias inside the same object. This is possible in POV-Ray.
</p>
<p>
Let's take the very first example, which did not work well with the white background, and add a slightly absorbing
media to the sphere:
</p>
<pre>
sphere
{ 0,1 pigment { rgbt 1 } hollow
interior
{ media
{ emission 1
density
{ spherical density_map
{ [0 rgb 0]
[0.4 rgb <1,0,0>]
[0.8 rgb <1,1,0>]
[1 rgb 1]
}
}
}
media
{ absorption 0.2
}
}
}
</pre>
<p>
This will make the sphere not only add light to the rays passing through it, but also substract.
</p>
<p>
<img alt="Emitting and absorbing media example" src="images/tutorial/mediatut4.png">
</p>
<p>
Multiple medias in the same object can be used for several other effects as well.
</p>
<h4><a name="s02_03_06_05">2.3.6.5 </a>Media and transformations</h4>
<p>
The density of a media can be modified with any pattern modifier, such as turbulence, scale, etc. This is a very
powerful tool for making diverse effects.
</p>
<p>
As an example, let's make an absorbing media which looks like smoke. For this we take the absorbing media example
and modify the sphere like this:
</p>
<pre>
sphere
{ 0,1.5 pigment { rgbt 1 } hollow
interior
{ media
{ absorption 7
density
{ spherical density_map
{ [0 rgb 0]
[0.5 rgb 0]
[0.7 rgb .5]
[1 rgb 1]
}
scale 1/2
warp { turbulence 0.5 }
scale 2
}
}
}
scale <1.5,6,1.5> translate y
}
</pre>
<p>
<img alt="Media transformation example" src="images/tutorial/mediatut5.png">
</p>
<p>
A couple of notes:
</p>
<p>
The radius of the sphere is now a bit bigger than 1 because the turbulented pattern tends to take more space.
</p>
<p>
The absorption color can be larger than 1, making the absorption stronger and the smoke darker.
</p>
<p class="Note">
<strong>Note:</strong> When you scale an object containing media the media density is not scaled
accordingly. This means that if you for example scale a container object larger the rays will pass through more media
than before, giving a stronger result. If you want to keep the same media effect with the larger object, you will need
to divide the color of the media by the scaling amount.
</p>
<p>
The question of whether the program should scale the density of the media with the object is a question of
interpretation: For example, if you have a glass of colored water, a larger glass of colored water will be more
colored because the light travels a larger distance. This is how POV-Ray behaves. Sometimes, however, the object needs
to be scaled so that the media does not change; in this case the media color needs to be scaled inversely.
</p>
<h4><a name="s02_03_06_06">2.3.6.6 </a>A more advanced example of scattering media</h4>
<p>
For a bit more advanced example of scattering media, let's make a room with a window and a light source
illuminating from outside the room. The room contains scattering media, thus making the light beam coming through the
window visible.
</p>
<pre>
global_settings { assumed_gamma 1 }
camera { location <14.9, 1, -8> look_at -z angle 70 }
light_source { <10,100,150>, 1 }
background { rgb <0.3, 0.6, 0.9> }
// A dim light source inside the room which does not
// interact with media so that we can see the room:
light_source { <14, -5, 2>, 0.5 media_interaction off }
// Room
union
{ difference
{ box { <-11, -7, -11>, <16, 7, 10.5> }
box { <-10, -6, -10>, <15, 6, 10> }
box { <-4, -2, 9.9>, <2, 3, 10.6> }
}
box { <-1.25, -2, 10>, <-0.75, 3, 10.5> }
box { <-4, 0.25, 10>, <2, 0.75, 10.5> }
pigment { rgb 1 }
}
// Scattering media box:
box
{ <-5, -6.5, -10.5>, <3, 6.5, 10.25>
pigment { rgbt 1 } hollow
interior
{ media
{ scattering { 1, 0.07 extinction 0.01 }
samples 30,100
}
}
}
</pre>
<p>
<img alt="More advanced scattering media example" src="images/tutorial/mediatut6.png">
</p>
<p>
As suggested previously, the scattering color and extinction values were adjusted until the image looked good. In
this kind of scene usually very small values are needed.
</p>
<p>
Note how the container box is quite smaller than the room itself. Container boxes should always be sized as
minimally as possible. If the box were as big as the room much higher values for <code>samples</code> would be needed
for a good result, thus resulting in a much slower rendering.
</p>
<h4><a name="s02_03_06_07">2.3.6.7 </a>Media and photons</h4>
<p>
The photon mapping technique can be used in POV-Ray for making stunningly beautiful images with light reflecting
and refracting from objects. By default, however, reflected and refracted light does not affect media. Making photons
interact with media can be turned on with the <code>media</code> keyword in the <code>photons</code> block inside <code>global_settings</code>.
</p>
<p>
To visualize this, let's make the floor of our room reflective so that it will reflect the beam of light coming
from the window.
</p>
<p>
Firstly, due to how photons work, we need to specify <code>photons { pass_through }</code> in our scattering media
container box so that photons will pass through its surfaces.
</p>
<p>
Secondly, we will want to turn photons off for our fill-light since it's there only for us to see the interior of
the room and not for the actual lighting effect. This can be done by specifying <code>photons { reflection off }</code>
in that light source.
</p>
<p>
Thirdly, we need to set up the photons and add a reflective floor to the room. Let's make the reflection colored
for extra effect:
</p>
<pre>
global_settings
{ photons
{ count 20000
media 100
}
}
// Reflective floor:
box
{ <-10, -5.99, -10>, <15, -6, 10>
pigment { rgb 1 }
finish { reflection <0.5, 0.4, 0.2> }
photons { target reflection on }
}
</pre>
<p>
<img alt="Scattering media with photons example" src="images/tutorial/mediatut7.png">
</p>
<p>
With all these fancy effects the render times start becoming quite high, but unfortunately this is a price which
has to be paid for such effects.
</p>
<br>
<table class="NavBar" width="100%">
<tr>
<td align="left" nowrap="" valign="middle" width="32">
<a href="s_70.html"><img alt="previous" border="0" src="prev.png"></a>
</td>
<td align="left" valign="middle" width="30%">
<a href="s_70.html">2.3.5 Using Atmospheric Effects</a>
</td>
<td align="center" valign="middle">
<strong>2.3.6 Simple Media Tutorial</strong>
</td>
<td align="right" valign="middle" width="30%">
<a href="s_72.html">2.3.7 Radiosity</a>
</td>
<td align="right" nowrap="" valign="middle" width="32">
<a href="s_72.html"><img alt="next" border="0" src="next.png"></a>
</td>
</tr>
</table>
</body> </html>
|