File: pov30012.htm

package info (click to toggle)
povray-manual 3.0.20-1
  • links: PTS
  • area: main
  • in suites: hamm, potato, slink
  • size: 2,724 kB
  • ctags: 1,285
  • sloc: makefile: 31
file content (222 lines) | stat: -rw-r--r-- 21,863 bytes parent folder | download
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
<html>
<body text="#000000" bgcolor="#C0C0C0" background="backgrnd.gif">
<a name="ref 521 pri 0"><a name="ref 522 pri 0"><center><h3><a name="section 4.10.3.7">
Section 4.10.3.7<br>Fog and Hollow Objects</h3></center>
Whenever you use the fog feature and the camera is inside a non-hollow object you won't get any fog effects. For a detailed explanation why this happens see <a href="pov3001f.htm#ref 374 pri 0">&quot;Empty and Solid Objects&quot;</a>.<p>
In order to avoid this problem you have to make all those objects hollow by either making sure the camera is outside these objects (using the <a name="ref 523 pri 2"><strong>inverse</strong> keyword) or by adding the <a name="ref 384 pri 7"><strong>hollow</strong> to them (which is much easier).<hr>
<a name="ref 524 pri 0"><a name="ref 441 pri 0"><center><h3><a name="section 4.10.4">
Section 4.10.4<br>The Atmosphere</h3></center>
<b>Important notice</b>: The atmosphere feature in POV-Ray 3.0 are somewhat experimental. There is a high probability that the design and implementation of these features will be changed in future versions. We cannot guarantee that scenes using these features in 3.0 will render identically in future releases or that full backwards compatibility of language syntax can be maintained.<p>
<a name="ref 268 pri 2">The atmosphere feature can be used to model the interaction of light with particles in the air. Beams of light will become visible and objects will cast shadows <strong>into</strong> the fog or dust that's filling the air.<p>
The atmosphere model used in POV-Ray assumes a constant particle density everywhere except solid objects. If you want to create cloud like fogs or smoke you'll have to use the halo texturing feature described in section <a href="pov3000d.htm#ref 256 pri 0">&quot;Halos&quot;</a>.<hr>
<a name="ref 525 pri 0"><a name="ref 526 pri 0"><center><h3><a name="section 4.10.4.1">
Section 4.10.4.1<br>Starting With an Empty Room</h3></center>
We want to create a simple scene to explain how the atmosphere feature works and how you'll get good results.<p>
Imagine a simple room with a window. Light falls through the window and is scattered by the dust particles in the air. You'll see beams of light coming from the window and shining on the floor.<p>
We want to model this scene step by step. The following examples start with the room, the window and a spotlight somewhere outside the room. Currently there's no atmosphere to be able to verify if the lighting is correct (<b>atmos1.pov</b>).<p>
<listing>
  camera {
    location &lt;-10, 8, -19&gt;
    look_at &lt;0, 5, 0&gt;
    angle 75
  }

  background { color rgb &lt;0.2, 0.4, 0.8&gt; }

  light_source { &lt;0, 19, 0&gt; color rgb 0.5 atmosphere off }

  light_source {
    &lt;40, 25, 0&gt; color rgb &lt;1, 1, 1&gt;
    spotlight
    point_at &lt;0, 5, 0&gt;
    radius 20
    falloff 20
    atmospheric_attenuation on
  }

  union {
    difference {
      box { &lt;-21, -1, -21&gt;, &lt;21, 21, 21&gt; }
      box { &lt;-20, 0, -20&gt;, &lt;20, 20, 20&gt; }
      box { &lt;19.9, 5, -3&gt;, &lt;21.1, 15, 3&gt; }
    }
    box { &lt;20, 5, -0.25&gt;, &lt;21, 15, 0.25&gt; }
    box { &lt;20, 9.775, -3&gt;, &lt;21, 10.25, 3&gt; }
    pigment { color red 1 green 1 blue 1 }
    finish { ambient 0.2 diffuse 0.5 }
  }
</listing>
<p>
<center><img src="pov30033.gif" border=0 width=320 height=240><br><cite>The empty room we want to start with.</cite></center><br> <p>
The point light source is used to illuminate the room from inside without any interaction with the atmosphere. This is done by adding <strong>atmosphere off</strong> . We don't have to care about this light when we add the atmosphere later.<p>
The spotlight is used with the <a name="ref 527 pri 1"><strong>atmospheric_attenuation</strong> keyword. This means that light coming from the spotlight will be diminished by the atmosphere.<p>
The union object is used to model the room and the window. Since we use the difference between two boxes to model the room (the first two boxes in the difference statement) there is no need for setting the union hollow. If we are inside this room we actually will be outside the object (see also <a href="pov30012.htm#ref 528 pri 0">&quot;Using Hollow Objects and Atmosphere&quot;</a>).<hr>
<a name="ref 529 pri 0"><a name="ref 530 pri 0"><center><h3><a name="section 4.10.4.2">
Section 4.10.4.2<br>Adding Dust to the Room</h3></center>
The next step is to add an atmosphere to the room. This is done by the following few lines (<b>atmos2.pov</b>).<p>
<listing>
  atmosphere {
    type 1
    samples 10
    distance 40
    scattering 0.2
  }
</listing>
<p>
The <a name="ref 531 pri 0"><strong>type</strong> keyword selects the type of atmospheric scattering we want to use. In this case we use the isotropic scattering that equally scatters light in all directions (see <a href="pov3002c.htm#ref 268 pri 0">&quot;Atmosphere&quot;</a> for more details about the different scattering types).<p>
The <a name="ref 392 pri 2"><strong>samples</strong> keyword determines the number of samples used in accumulating the atmospheric effect. For every ray samples are taken along the ray to determine whether a sample is lit by a light source or not. If the sample is lit the amount of light scattered into the direction of the viewer is determined and added to the total intensity.<p>
You can always start with an arbitrary number of samples. If the results do not fit your ideas you can increase the sampling rate to get better results. The problem of choosing a good sampling rate is the trade-off between a satisfying image and a fast rendering. A high sampling rate will almost always work but the rendering will also take a very long time. That's something to experiment with.<p>
The <a name="ref 269 pri 4"><strong>distance</strong> keyword specifies the density of the atmosphere. It works in the same way as the distance parameter of the fog feature.<p>
Last but not least will the <a name="ref 532 pri 4"><strong>scattering</strong> value determine the amount of light that is scattered by the particles (the remaining light is absorbed). As you'll later see this parameter is very useful in adjusting the overall brightness of the atmosphere.<p>
<center><img src="pov30034.gif" border=0 width=320 height=240><br><cite>After adding some dust beams of light become visible.</cite></center><br> <p>
Looking at the image created from the above scene you'll notice some very ugly anti-aliasing artifacts known as mach-bands. They are the result of a low sampling rate.<p>
How this effect can be avoid is described in the following section.<hr>
<a name="ref 533 pri 0"><a name="ref 534 pri 0"><center><h3><a name="section 4.10.4.3">
Section 4.10.4.3<br>Choosing a Good Sampling Rate</h3></center>
As you've seen a too low sampling rate can cause some ugly results. There are some ways of reducing or even avoiding those problems.<p>
The brute force approach is to increase the sampling rate until the artifacts vanish and you get a satisfying image. Though this will always work it is a bad idea because it is very time consuming. A better approach is to use jittering and anti-aliasing first. If both features don't help you'll have to increase the sampling rate.<p>
Jittering moves each sample point by a small, random amount along the sampling direction. This helps to reduce regular features resulting from aliasing. There is (hardly) nothing more annoying to the human visual system than the regular features resulting from a low sampling rate. It's much better to add some extra noise to the image by jittering the sample positions. The human eye is much more forgiving to that.<p>
Use the <a name="ref 251 pri 3"><strong>jitter</strong> keyword followed by the amount of jittering you want to use. Good jittering values are up to 0.5, higher values result in too much noise.<p>
You should be aware that jittering can not fix the artifacts introduced by a too low sampling rate. It can only make them less visible.<p>
An additional and better way of reducing aliasing artifacts is to use (adaptive) super-sampling. This method casts additional samples where it is likely that they are needed. If the intensity between two adjacent samples differs too much additional samples are taken in-between. This step is done recursively until a specified recursion level is reached or the sample get close to each other.<p>
The <a name="ref 440 pri 4"><strong>aa_level</strong> and <a name="ref 439 pri 5"><strong>aa_threshold</strong> keywords give full control over the super-sampling process. The <a name="ref 440 pri 7"><strong>aa_level</strong> keyword determines the maximum recursion level while <a name="ref 439 pri 9"><strong>aa_threshold</strong> specifies the maximum allowed difference between two sample before the super-sampling is done.<p>
After all this theory we get back to our sample scene and add the appropriate keywords to use both jittering and super-sampling (<b>atmos3.pov</b>).<p>
<listing>
  atmosphere {
    type 1
    samples 50
    distance 40
    scattering 0.2
    aa_level 4
    aa_threshold 0.1
    jitter 0.2
  }
</listing>
<p>
A very low threshold value was chosen to super-sample even between adjacent points with a very similar intensity. The maximum recursion level of 4 will lead to a maximum of fifteen super-samples.<p>
If you are looking at the results that you get after adding jittering and super-sampling you won't be satisfied. The only way of reducing the still visible artifacts is to increase the sampling rate by choosing a higher number of samples.<p>
<center><img src="pov30035.gif" border=0 width=320 height=240><br><cite>A high sampling rate leads to a satisfying image.</cite></center><br> <p>
Doing this you'll get a good result showing (almost) no artifacts. BTW, the amount of dust floating around in this room may be a little bit exaggerated but it's just an example. And examples tend to be exaggerated.<hr>
<a name="ref 535 pri 0"><a name="ref 536 pri 0"><center><h3><a name="section 4.10.4.4">
Section 4.10.4.4<br>Using a Coloured Atmosphere</h3></center>
You can assign a color to the atmosphere that gives you more control over the atmosphere's appearance. First of all the color is used to filter all light passing through it, whether it comes from light sources, reflected and refracted rays, or the background. The amount by which the passing light is filtered by the atmosphere's color is determined by the color's filter value. A value of 0 means that the light is not influenced by the atmosphere's color while a value of 1 means that all light will be filtered by the color.<p>
If you want to create a reddish atmosphere for example, you can add the following line to the atmosphere statement used in the above example.<p>
<listing>
  color rgbf &lt;1, 0, 0, 0.25&gt;
</listing>
<p>
Just using <strong>rgb &lt;1,0,0&gt;</strong> does not work because the color's filter value will be zero and thus no light will be filtered by the color, i. e. no light will be multiplied with the color's RGB components.<p>
The filter value of 0.25 means that 25% of the light passing through the atmosphere will be filtered by the red color and 75% will pass unfiltered.<p>
The transmittance channel of the atmosphere's color is used to specify a minimum translucency. By default the transmittance channel is zero and thus there is no such minimum translucency. Using a positive value lets you determine the amount of background light that will always pass through the atmosphere, regardless of its thickness set by the <a name="ref 269 pri 3"><strong>distance</strong> keyword.<p>
If you use e.g. a color of <strong>rgbt &lt;0,0,0,0.3&gt;</strong> with our room example you can make the blue background become visible. Until now it was hidden by the atmosphere.<hr>
<a name="ref 537 pri 0"><a name="ref 538 pri 0"><center><h3><a name="section 4.10.4.5">
Section 4.10.4.5<br>Atmosphere Tips</h3></center>
It is very difficult to get satisfying results when using the atmosphere feature. Some of the more common problems will be discussed in the next sections to help you to solve them (see also the FAQ section about the atmosphere in <a href="pov30031.htm#ref 539 pri 0">&quot;Atmosphere Questions&quot;</a>).<hr>
<a name="ref 540 pri 0"><a name="ref 541 pri 0"><center><h3><a name="section 4.10.4.5.1">
Section 4.10.4.5.1<br>Choosing the Distance and Scattering Parameters</h3></center>
The first difficult step is to choose a good distance and scattering value. You need to be able to control the visibility of the objects in the scene and the atmospheric effects.<p>
The best approach is to choose the distance value first. This value determines the visibility of the objects in the scene regardless of atmospheric light scattering. It works in the same way as the distance value of the fog feature.<p>
Since fog is very similar to the unlit atmosphere you can use a fog instead of an atmosphere to quickly choose a working distance value. If you do this with room scene we used earlier you would use the following fog statement instead of the atmosphere (<b>atmos4.pov</b>).<p>
<listing>
  fog {
    distance 40
    color rgb &lt;0, 0, 0&gt;
  }
</listing>
<p>
<center><img src="pov30036.gif" border=0 width=320 height=240><br><cite>A black fog can be used to get a working distance value for the atmosphere.</cite></center><br> <p>
The black color is used to simulate the attenuation you'll get in those parts of the atmosphere scene lying in shadow.<p>
If you want to use a colored atmosphere you'll have to use the same color for the fog as you want to use for the atmosphere, including the filter and transmittance channel values (see <a href="pov30012.htm#ref 536 pri 0">&quot;Using a Coloured Atmosphere&quot;</a> and <a href="pov3002c.htm#ref 268 pri 0">&quot;Atmosphere&quot;</a> for an explanation of the atmosphere's color).<p>
If you (roughly) want to simulate the appearance of those parts lit by a light source you can use the color of the atmosphere inside the fog statement instead.<p>
After you are satisfied with the distance value you'll have to choose a scattering value. This value lets you fit the atmosphere's intensity to your needs. Starting with a value of one you have to increase the value if the atmosphere effects are hardly visible. If you don't see anything in the lit parts of the atmosphere you'll have to decrease the value.<p>
You should be aware that you may have to use very small or very large values to get the desired results.<hr>
<a name="ref 542 pri 0"><a name="ref 543 pri 0"><center><h3><a name="section 4.10.4.5.2">
Section 4.10.4.5.2<br>Atmosphere and Light Sources</h3></center>
The best results are generated with spotlights and cylindrical light sources. They create nice beams of light and are fast to render because the atmospheric sampling takes only place inside the light cone of the spotlight or light cylinder of the cylindrical light.<p>
If you want to add a light source that does not interact with the atmosphere you can use the <a name="ref 268 pri 3"><strong>atmosphere</strong> keyword inside the light source statement (see <a href="pov30024.htm#ref 544 pri 0">&quot;Atmosphere Interaction&quot;</a>). Just add <strong>atmosphere off</strong>.<p>
By default the light coming from any light source will not be diminished by the atmosphere. Thus the highlights in your scene will normally be too bright. This can be changed with <strong>atmospheric_attenuation on</strong>.<hr>
<a name="ref 545 pri 0"><a name="ref 546 pri 0"><center><h3><a name="section 4.10.4.5.3">
Section 4.10.4.5.3<br>Atmosphere Scattering Types</h3></center>
The different scattering types listed in <a href="pov3002c.htm#ref 268 pri 0">&quot;Atmosphere&quot;</a> can be used to model different types of particles. This is something for you to experiment with.<p>
The Rayleigh scattering is used for small particles like dust and smoke while the Mie scattering is used for fog.<p>
If you ever saw the lighthouse scene in the movie <strong>Casper</strong> you'll know what effect the scattering type has. In this scene the beam of light coming from the lighthouse becomes visible while it points nearly towards the viewer. As it starts to point away from the viewer it vanishes. This behaviour is typical for minuscule water droplets as modeled by the Mie scattering.<hr>
<a name="ref 547 pri 0"><a name="ref 548 pri 0"><center><h3><a name="section 4.10.4.5.4">
Section 4.10.4.5.4<br>Increasing the Image Resolution</h3></center>
You have to be aware that you may have to increase the atmosphere sampling rate if you increase the resolution of the image. Otherwise some aliasing artifacts that were no visible at the lower resolution may become visible.<hr>
<a name="ref 549 pri 0"><a name="ref 528 pri 0"><center><h3><a name="section 4.10.4.5.5">
Section 4.10.4.5.5<br>Using Hollow Objects and Atmosphere</h3></center>
Whenever you use the atmosphere feature you have to make sure that all objects that ought to be filled with atmosphere are set to hollow using the <a name="ref 384 pri 6"><strong>hollow</strong> keyword.<p>
Even though this is not obvious this holds for infinite and patch objects like quadrics, quartics, triangles, polygons, etc. Whenever you add one of those objects you should add the hollow keyword as long as you are not absolutely sure you don't need it. You also have to make sure that all objects the camera is inside are set to be hollow.<p>
Whenever you get unexpected results you should check for solid objects and set them to be hollow.<hr>
<a name="ref 550 pri 0"><a name="ref 551 pri 0"><a name="ref 552 pri 1"><center><h3><a name="section 4.10.5">
Section 4.10.5<br>The Rainbow</h3></center>
The rainbow feature can be used to create rainbows and maybe other more strange effects. The rainbow is a fog like effect that is restricted to a cone-like volume.<hr>
<a name="ref 553 pri 0"><a name="ref 554 pri 0"><center><h3><a name="section 4.10.5.1">
Section 4.10.5.1<br>Starting With a Simple Rainbow</h3></center>
The rainbow is specified with a lot of parameters: the angle under which it is visible, the width of the color band, the direction of the incoming light, the fog-like distance based particle density and last not least the color map to be used.<p>
The size and shape of the rainbow are determined by the <a name="ref 555 pri 2"><strong>angle</strong> and <a name="ref 556 pri 2"><strong>width</strong> keywords. The <a name="ref 557 pri 3"><strong>direction</strong> keyword is used to set the direction of the incoming light, thus setting the rainbow's position. The rainbow is visible when the angle between the direction vector and the incident light direction is larger than angle-width/2 and smaller than angle+width/2.<p>
The incoming light is the virtual light source that is responsible for the rainbow. There needn't be a real light source to create the rainbow effect.<p>
The rainbow is a fog-like effect, i.e. the rainbow's color is mixed with the background color based on the distance to the intersection point. If you choose small distance values the rainbow will be visible on objects, not just in the background. You can avoid this by using a very large distance value.<p>
The color map is the crucial part of the rainbow since it contains all the colors that normally can be seen in a rainbow. The color of the innermost color band is taken from the color map entry 0 while the outermost band is take from entry 1. You should note that due to the limited color range any monitor can display it is impossible to create a real rainbow. There are just some colors that you cannot display.<p>
The filter channel of the rainbow's color map is used in the same way as with fogs. It determines how much of the light passing through the rainbow is filtered by the color.<p>
The following example shows a simple scene with a ground plane, three spheres and a somewhat exaggerated rainbow (<b>rainbow1.pov</b>).<p>
<listing>
  #include &quot;colors.inc&quot;

  camera {
    location &lt;0, 20, -100&gt;
    look_at &lt;0, 25, 0&gt;
    angle 80
  }

  background { color SkyBlue }

  plane { y, -10 pigment { colour Green } }

  light_source {&lt;100, 120, 40&gt; colour White}

  // declare rainbow's colours

  #declare r_violet1 = colour rgbf&lt;1.0, 0.5, 1.0, 1.0&gt;
  #declare r_violet2 = colour rgbf&lt;1.0, 0.5, 1.0, 0.8&gt;
  #declare r_indigo  = colour rgbf&lt;0.5, 0.5, 1.0, 0.8&gt;
  #declare r_blue    = colour rgbf&lt;0.2, 0.2, 1.0, 0.8&gt;
  #declare r_cyan    = colour rgbf&lt;0.2, 1.0, 1.0, 0.8&gt;
  #declare r_green   = colour rgbf&lt;0.2, 1.0, 0.2, 0.8&gt;
  #declare r_yellow  = colour rgbf&lt;1.0, 1.0, 0.2, 0.8&gt;
  #declare r_orange  = colour rgbf&lt;1.0, 0.5, 0.2, 0.8&gt;
  #declare r_red1    = colour rgbf&lt;1.0, 0.2, 0.2, 0.8&gt;
  #declare r_red2    = colour rgbf&lt;1.0, 0.2, 0.2, 1.0&gt;

  // create the rainbow

  rainbow {
    angle 42.5
    width 5
    distance 1.0e7
    direction &lt;-0.2, -0.2, 1&gt;
    jitter 0.01
    colour_map {
      [0.000  colour r_violet1]
      [0.100  colour r_violet2]
      [0.214  colour r_indigo]
      [0.328  colour r_blue]
      [0.442  colour r_cyan]
      [0.556  colour r_green]
      [0.670  colour r_yellow]
      [0.784  colour r_orange]
      [0.900  colour r_red1]
    }
  }
</listing>
<p>
Some irregularity is added to the color bands using the <a name="ref 251 pri 7"><strong>jitter</strong> keyword.<p>
<center><img src="pov30037.gif" border=0 width=320 height=240><br><cite>A colorful rainbow.</cite></center><br> <p>
The rainbow in our sample is much too bright. You'll never see a rainbow like this in reality. You can decrease the rainbow's colors by decreasing the RGB values in the color map.<hr>

<center>
<a href="pov30013.htm">Next Section</a><br>
<a href="povray.htm#Table of Contents">Table Of Contents</a><br>
</center>
</body>
</html>