File: s_77.html

package info (click to toggle)
povray 1%3A3.6.1-6
  • links: PTS
  • area: non-free
  • in suites: etch, etch-m68k
  • size: 31,052 kB
  • ctags: 20,305
  • sloc: ansic: 110,032; cpp: 86,573; sh: 13,595; pascal: 5,942; asm: 2,994; makefile: 1,747; ada: 1,637
file content (518 lines) | stat: -rw-r--r-- 18,462 bytes parent folder | download | duplicates (2)
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

<!--  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.4.1 Language Tips and tricks to achieve useful things</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_76.html"><img alt="previous" border="0" src="prev.png"></a> 
   
  </td>
   
  <td align="left" valign="middle" width="30%">
    <a href="s_76.html">2.4 Questions and Tips</a> 
  </td>
   
  <td align="center" valign="middle">
    <strong class="NavBar">POV-Ray 3.6 for UNIX documentation</strong><br> <strong>2.4.1 
   Language Tips and tricks to achieve useful things</strong> 
  </td>
   
  <td align="right" valign="middle" width="30%">
    <a href="s_78.html">2.4.2 Language Things that don't work as one 
   expects</a> 
  </td>
   
  <td align="right" nowrap="" valign="middle" width="32">
    <a href="s_78.html"><img alt="next" border="0" src="next.png"></a> 
   
  </td>
   
 </tr>
  
</table>
 
<h3><a name="s02_04_01">2.4.1 </a>Language Tips and tricks to achieve useful things</h3>

<h4><a name="s02_04_01_01">2.4.1.1 </a>How do I make a visible light source?</h4>

<p>
  <em>&quot;How do I make a visible light source?&quot;</em> or: <em>&quot;Although I put the camera just in front of 
 my light source, I cannot see anything. What am I doing wrong?&quot;</em> 
</p>

<p>
  A light source in POV-Ray is only a concept. When you add a light source to the scene, you are actually saying to 
 POV-Ray &quot;hey, there is light coming from this point&quot;. As the name says, it is a light <strong>source</strong>, 
 not a physical light (like a light bulb or a bright spot like a star). POV-Ray does not add anything to that place 
 where the light is coming, ie. there is nothing there, only empty space. It is just a kind of mathematical point 
 POV-Ray uses to make shading calculations. 
</p>

<p>
  To make the light source visible, you have to put something there. There is a <code>looks_like</code> keyword in 
 the <code>light_source</code> block which allows to easily attach an object to the light source. This object 
 implicitly does not cast any shadows. You can make something like this: 
</p>

<pre>
light_source
{ &lt;0,0,0&gt; color 1
  looks_like
  { sphere
    { &lt;0,0,0&gt;,0.1
      color { rgb 1 }
      finish { ambient 1 }
    }
  }
  translate &lt;10,20,30&gt;
}
</pre>

<p>
  It is a good idea to define both things, the light source and the looks_like object, at the origin, and then 
 translate them to their right place. 
</p>

<p>
  Note also the '<code>finish { ambient 1 }</code>' which makes the sphere to apparently glow (see also the next 
 question). 
</p>

<p>
  You can also get visible light sources using other techniques: Media, lens flare (available as 3rd party include 
 file), glow patch, etc. 
</p>

<h4><a name="s02_04_01_02">2.4.1.2 </a>How do I make bright objects?</h4>

<p>
  <em>&quot;How do I make bright objects, which look like they are emitting light?&quot; </em> 
</p>

<p>
  There is a simple trick to achieve this: Set the ambient value of the object to 1 or higher. This makes POV-Ray to 
 add a very bright illumination value to the object so the color of the object is in practice taken as is, without 
 darkening it due to shadows and shading. This results in an object which seems to glow light by itself even if it is 
 in full darkness (useful to make visible light sources, or small lights like leds which do not cast any considerable 
 light to their surroundings but can be easily seen even in the darkness). 
</p>

<p>
  A more sophisticated method would be using an emitting media inside the object (and making the object itself 
 transparent or semi-transparent). 
</p>

<h4><a name="s02_04_01_03">2.4.1.3 </a>How do I move the camera in a circular path?</h4>

<p>
  <em>&quot;How do I move the camera in a circular path while looking at the origin?&quot; </em> 
</p>

<p>
  There are two ways to make this: The easy (and limited) way, and the more mathematical way. 
</p>

<p>
  The easy way: 
</p>

<pre>
camera
{ location &lt;0,0,-10&gt;
  look_at 0
  rotate &lt;0,clock*360,0&gt;
}
</pre>

<p>
  This puts the camera at 10 units in the negative Z-axis and then rotates it around the Y-axis while looking at the 
 origin (it makes a circle of radius 10). 
</p>

<p>
  The mathematical way: 
</p>

<pre>
camera
{ location &lt;10*sin(2*pi*clock),0,-10*cos(2*pi*clock)&gt;
  look_at 0
}
</pre>

<p>
  This makes exactly the same thing as the first code, but this way you can control more precisely the path of the 
 camera. For example you can make the path elliptical instead of circular by changing the factors of the sine and the 
 cosine (for example instead of 10 and 10 you can use 10 and 5 which makes an ellipse with the major radius 10 and 
 minor radius 5). 
</p>

<p>
  An easier way to do the above is to use the vrotate() function, which handles the sin() and cos() stuff for you, as 
 well as allowing you to use more complex rotations. 
</p>

<pre>
camera
{ location vrotate(x*10, y*360*clock)
  look_at 0
}
</pre>

<p>
  To get an ellipse with this method, you can just multiply the result from vrotate by a vector, scaling the 
 resulting circle. With the last two methods you can also control the look_at vector (if you do not want it looking 
 just at the origin). 
</p>

<p>
  You could also do more complex transformations combining translate, scale, rotate, and matrix transforms by 
 replacing the vrotate() call with a call of the vtransform() function found in <code>functions.inc</code> (new in 
 POV-Ray 3.5). 
</p>

<h4><a name="s02_04_01_04">2.4.1.4 </a>How do I use an image to texture my object?</h4>

<p>
  The answer to this question can be easily found in the POV-Ray documentation, so I will just quote the syntax: 
</p>

<pre>
pigment
{ image_map
  { gif &quot;image.gif&quot;
    map_type 1
  }
}
</pre>

<p>
  (Note that in order for the image to be aligned properly, either the object has to be located at the origin when 
 applying the pigment or the pigment has to be transformed to align with the object. It is generally easiest to create 
 the object at the origin, apply the texture, then move it to wherever you want it.) 
</p>

<p>
  Substitute the keyword <code>gif</code> with the type of image you are using (if it is not a GIF): <code>tga, iff, 
 ppm, pgm, png or sys</code>. 
</p>

<p>
  A <code>map_type 0</code> gives the default planar mapping.<br> A <code>map_type 1</code> gives a spherical mapping 
 (maps the image onto a sphere).<br> With <code>map_type 2</code> you get a cylindrical mapping (maps the image onto a 
 cylinder).<br> Finally <code>map_type 5</code> is a torus or donut shaped mapping (maps the image onto a torus). 
</p>

<p>
  See the documentation for more details. 
</p>

<h4><a name="s02_04_01_05">2.4.1.5 </a>How can I generate a spline?</h4>

<p>
  <em>&quot;How can I generate a spline, for example for a camera path for an animation?&quot;</em> 
</p>

<p>
  POV-Ray 3.6 has a splines feature that allows you to create splines. This is covered in the documentation and there 
 are demo files showing examples of use. There exist also third party include files for spline generation that have 
 greater flexibility than the internal splines, for example the <a href="http://www.geocities.com/ccolefax/spline/index.html" target="new">spline 
 macros by Chris Colefax</a>. 
</p>

<h4><a name="s02_04_01_06">2.4.1.6 </a>How can I simulate motion blur?</h4>

<p>
  The official POV-Ray 3.6 does not support motion blur calculations, but there are some patched versions which do. 
</p>

<p>
  You can also use other tools to make this. One way to simulate motion blur is calculating a small animation and 
 then averaging the images together. This averaging of several images can be made with third party programs, such as 
 the <a href="http://iki.fi/warp/PovUtils/average/" target="new">Targa Averager program</a>. 
</p>

<h4><a name="s02_04_01_07">2.4.1.7 </a>How can I find the size of a text object?</h4>

<p>
  <em>&quot;How can I find the size of a text object / center text / justify text?&quot; </em> 
</p>

<p>
  You can use the <code>min_extent()</code> and <code>max_extent()</code> functions to get the corners of the 
 bounding box of any object. While this is sometimes not the actual size of the object, for text objects this should be 
 fairly accurate, enough to do alignment of the text object. 
</p>

<h4><a name="s02_04_01_08">2.4.1.8 </a>How do I make extruded text?</h4>

<p>
  POV-Ray has true type font support built in that allows you to have 3D text in your scenes (see the documentation 
 about the 'text' object for more details). 
</p>

<p>
  There are also some outside utilities that will import true type fonts and allow user manipulation on the text. One 
 of these programs is called Elefont. 
</p>

<h4><a name="s02_04_01_09">2.4.1.9 </a>How do I make an object hollow?</h4>

<p>
  This question usually means &quot;how do I make a hollow object, like a waterglass, a jug, etc&quot;. 
</p>

<p>
  Before answering that question, let me explain some things about how POV-Ray handles objects: 
</p>

<p>
  Although the POV-Ray documentation talks about &quot;solid&quot; and &quot;hollow&quot; objects, that is not how it 
 actually works. &quot;Solid&quot; and &quot;hollow&quot; are a bit misleading terms to describe the objects. You can 
 also make an object &quot;hollow&quot; with that same keyword, but it is not that simple. 
</p>

<p>
  Firstly: POV-Ray only handles surfaces, not solid 3D-objects. When you specify a sphere, it is actually just a 
 spherical surface. It is only a surface and it is not filled by anything. This can easily be seen by putting the 
 camera inside the sphere or by clipping a hole to one side of the sphere with the clipped_by keyword (so you can look 
 inside). 
</p>

<p>
  People often think that POV-Ray objects are solid, really 3D, with solid material filling the entire object because 
 they make a 'difference' CSG object and it seems like the object is actually solid. What the 'difference' CSG actually 
 does is to cut away a part of the object and <strong>add a new surface</strong> in the place of the hole, which 
 completely covers the hole, so you cannot see inside the object (this new surface is actually the part of the second 
 object which is &quot;inside&quot; the first object). Again, if you move the camera inside the object, you will see 
 that actually it is hollow and the object is just a surface. 
</p>

<p>
  So what is all this &quot;solid&quot; and &quot;hollow&quot; stuff the documentation talks of, and what is the 
 &quot;hollow&quot; keyword used for? 
</p>

<p>
  Although objects are actually surfaces, POV-Ray handles them as if they were solid. For example, fog and media do 
 not go inside solid objects. If you put a glass sphere into the fog, you will see that there is no fog inside the 
 sphere. 
</p>

<p>
  If you add the &quot;hollow&quot; keyword to the object, POV-Ray will no longer handle it as solid, so fog and 
 atmosphere will invade the inside of the object. This is the reason why POV-Ray issues a warning when you put the 
 camera inside a non-hollow object (because, as it says, fog and other atmospheric effects may not work as you 
 expected). 
</p>

<p>
  If your scene does not use any atmospheric effect (fog or media) there is not any difference between a 
 &quot;solid&quot; or &quot;hollow&quot; object. 
</p>

<p>
  So all the objects in POV-Ray are hollow. But the surface of the objects is always infinitely thin, and there is 
 only one surface. With real world hollow objects you have always two surfaces: an outer surface and an inner surface. 
</p>

<p>
  Usually people refer to these kind of objects when they ask for hollow objects. This kind of objects are easily 
 achieved with a 'difference' CSG operation, like this: 
</p>

<pre>
// A simple water glass made with a difference:
difference
{ cone { &lt;0,0,0&gt;,1,&lt;0,5,0&gt;,1.2 }
  cone { &lt;0,.1,0&gt;,.9,&lt;0,5.1,0&gt;,1.1 }
  texture { Glass }
}
</pre>

<p>
  The first cone limits the outer surface of the glass and the second cone limits the inner surface. 
</p>

<h4><a name="s02_04_01_10">2.4.1.10 </a>How can I fill a glass with water or other objects?</h4>

<p>
  As described in the &quot;hollow objects&quot; question above, hollow objects have always two surfaces: an outer 
 surface and an inner surface. If we take the same example, a simple glass would be like: 
</p>

<pre>
// A simple water glass made with a difference:
#declare MyGlass=
difference
{ cone { &lt;0,0,0&gt;,1,&lt;0,5,0&gt;,1.2 }
  cone { &lt;0,.1,0&gt;,.9,&lt;0,5.1,0&gt;,1.1 }
  texture { Glass }
}
</pre>

<p>
  The first cone limits the outer surface of the glass and the second cone limits the inner surface. 
</p>

<p>
  If we want to fill the glass with water, we have to make an object which coincides with the inner surface of the 
 glass. Note that you have to avoid the <a href="s_78.html#s02_04_02_05">coincident surfaces problem</a> so you should 
 scale the &quot;water&quot; object just a little bit smaller than the inner surface of the glass. So we make something 
 like this: 
</p>

<pre>
#declare MyGlassWithWater=
union
{ object { MyGlass }
  cone
  { &lt;0,.1,0&gt;,.9,&lt;0,5.1,0&gt;,1.1
    scale .999
    texture { Water }
  }
}
</pre>

<p>
  Now the glass is filled with water. But there is one problem: There is too much water. The glass should be filled 
 only up to certain level, which should be definable. Well, this can be easily made with a CSG operation: 
</p>

<pre>
#declare MyGlassWithWater=
union
{ object { MyGlass }
  intersection
  { cone { &lt;0,.1,0&gt;,.9,&lt;0,5.1,0&gt;,1.1 }
    plane { y,4 }
    scale .999
    texture { Water }
  }
}
</pre>

<p>
  Now the water level is at a height of 4 units. 
</p>

<h4><a name="s02_04_01_11">2.4.1.11 </a>How can I bend a object?</h4>

<p>
  There is no direct support for bending in POV-Ray, but you can achieve acceptable bending with the <a href="http://www.geocities.com/SiliconValley/Lakes/1434/bend.html" target="new">Object 
 Bender by Chris Colefax</a>. 
</p>

<p>
  Some objects can be &quot;bent&quot; by just modelling it with other objects. For example a bent cylinder can be 
 more easily (and accurately) achieved using the intersection of a torus and some limiting objects. 
</p>

<p>
  It might be a bit strange why most renderers support bending but POV-Ray does not. To understand this one has to 
 know how other renderers (the so-called &quot;scanline-renderers&quot; work): 
</p>

<p>
  In the so-called &quot;scanline renders&quot; all objects are modelled with triangle meshes (or by primitives such 
 as NURBS or bezier patches which can be very easily converted to triangles). The &quot;bending&quot; is, in fact, 
 achieved by moving the vertices of the triangles. 
</p>

<p>
  In this context the term &quot;bending&quot; is a bit misleading. Strictly speaking, bending a triangle mesh would 
 also bend the triangles themselves, not only move their vertices. No renderer can do this. (It can be, however, 
 simulated by splitting the triangles into smaller triangles, and so the &quot;bending&quot; effect is more accurate, 
 although not yet perfect.) What these renderers do is not a true bending in the strict mathematical sense, but only an 
 approximation achieved by moving the vertices of the triangles. 
</p>

<p>
  This difference might sound irrelevant, as the result of this kind of &quot;fake&quot; bending usually looks as 
 good as a true bending. However, it is not irrelevant from the point of view of POV-Ray. This is because POV-Ray does 
 not represent the objects with triangles, but they are true mathematical surfaces. POV-Ray cannot &quot;fake&quot; a 
 bending by moving vertices because there are no vertices to move. In practice bending (and other non-linear 
 transformations) would require the calculation of the intersection of the object surface and a curve (instead of a 
 straight line), which is pretty hard and many times analytically not possible. 
</p>

<p>
  Note that isosurface objects can be modified with proper functions in order to achieve all kinds of transformations 
 (linear and non-linear) and thus they are not really bound to this limitation. However, achieving the desired 
 transformation needs some knowledge of mathematics. 
</p>

<p>
  See also the <a href="s_79.html#s02_04_03_04">variable ior question</a>. 
</p>

<h4><a name="s02_04_01_12">2.4.1.12 </a>Can I get non-grainy focal blur?</h4>

<p>
  <em>&quot;The focal blur is very grainy. Can I get rid of the graininess?&quot;</em> 
</p>

<p>
  Yes. Set <code>variance</code> to 0 (or to a very small value, like for example 1/100000) and choose a high enough <code>blur_samples</code>. 
 The rendering will probably slow down quite a lot, but the result should be very good. 
</p>
 <br> 
<table class="NavBar" width="100%">
  
 <tr>
   
  <td align="left" nowrap="" valign="middle" width="32">
    <a href="s_76.html"><img alt="previous" border="0" src="prev.png"></a> 
   
  </td>
   
  <td align="left" valign="middle" width="30%">
    <a href="s_76.html">2.4 Questions and Tips</a> 
  </td>
   
  <td align="center" valign="middle">
    <strong>2.4.1 Language Tips and tricks to achieve useful things</strong> 
  </td>
   
  <td align="right" valign="middle" width="30%">
    <a href="s_78.html">2.4.2 Language Things that don't work as one 
   expects</a> 
  </td>
   
  <td align="right" nowrap="" valign="middle" width="32">
    <a href="s_78.html"><img alt="next" border="0" src="next.png"></a> 
   
  </td>
   
 </tr>
  
</table>
 </body> </html>