Sophie

Sophie

distrib > Mandriva > 2010.2 > i586 > by-pkgid > 8c84ab5fe0ecd5f81b4e4e07120af05b > files > 1032

povray-3.6.1-8mdv2010.1.i586.rpm


<!--  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 &lt;3,4,-5&gt;*.8 look_at 0 angle 35 }
 light_source { &lt;20,40,10&gt;, 1 }

 box // floor
 { &lt;-1.5,-1.01,-1.5&gt;, &lt;1.5,-1.2,1.5&gt;
   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 &lt;1,0,0&gt;]
           [0.8 rgb &lt;1,1,0&gt;]
           [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>&lt;0,0,0&gt;</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 &lt;0,0.5,1&gt;]
          [1 rgb &lt;0,1,1&gt;]
        }
      }
    }
</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>&lt;1,1,1&gt;</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
 { &lt;0.9, -1, 0.7&gt;, &lt;0.9, 0.9, 0.7&gt;, 0.5
   pigment { rgb &lt;1, 0.8, 0.5&gt; }
 }
</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 &lt;1,0,0&gt;]
           [0.8 rgb &lt;1,1,0&gt;]
           [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 &lt;1.5,6,1.5&gt; 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 &lt;14.9, 1, -8&gt; look_at -z angle 70 }
 light_source { &lt;10,100,150&gt;, 1 }
 background { rgb &lt;0.3, 0.6, 0.9&gt; }

 // A dim light source inside the room which does not
 // interact with media so that we can see the room:
 light_source { &lt;14, -5, 2&gt;, 0.5 media_interaction off }

 // Room
 union
 { difference
   { box { &lt;-11, -7, -11&gt;, &lt;16, 7, 10.5&gt; }
     box { &lt;-10, -6, -10&gt;, &lt;15, 6, 10&gt; }
     box { &lt;-4, -2, 9.9&gt;, &lt;2, 3, 10.6&gt; }
   }
   box { &lt;-1.25, -2, 10&gt;, &lt;-0.75, 3, 10.5&gt; }
   box { &lt;-4, 0.25, 10&gt;, &lt;2, 0.75, 10.5&gt; }
   pigment { rgb 1 }
 }
 
 // Scattering media box:
 box
 { &lt;-5, -6.5, -10.5&gt;, &lt;3, 6.5, 10.25&gt;
   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
 { &lt;-10, -5.99, -10&gt;, &lt;15, -6, 10&gt;
   pigment { rgb 1 }
   finish { reflection &lt;0.5, 0.4, 0.2&gt; }
   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>