Difference between revisions of "Documentation:Tutorial Section 4"

From POV-Wiki
Jump to navigation Jump to search
m (link housekeeping)
(Q&T now points to the KB version)
Line 10: Line 10:
 
<!--<sectiondesc desc=<"tutorial questions and tips">--->
 
<!--<sectiondesc desc=<"tutorial questions and tips">--->
 
<!--<indexentry primary "Questions and Tips" "VFAQ" "FAQ">--->
 
<!--<indexentry primary "Questions and Tips" "VFAQ" "FAQ">--->
−
<p>
+
<p>Now that you've learned the basics, you may have questions about a particular behaviour, or perhaps you're looking for ways to speed up, or improve your scenes. Please refer to to link below to view the POV-Ray Questions and Tips or <b>FAQ</b>. </p>
−
This section contains answers to frequently asked questions about
+
===Use the online Version===
−
POV-Ray as well as many useful tips not covered in other parts of this documentation.</p>
+
<p class="Note">
−
<p>
+
<b>Note: </b>Previous versions of this documentation included a copy of the POV-Ray Questions and Tips with the application distribution package. You should now refer to the online version of the [http://wiki.povray.org/content/Knowledgebase:POV-Ray_Questions_and_Tips POV-Ray Questions and Tips] that's located on the POV-Wiki.</p>
−
While it was current at the time that this POV-Ray documentation help file was created,
 
−
it will almost certainly be out of date by the time you are reading this. So, if you
 
−
do not find an answer to your question here, please check out the [http://www.povray.org/search/redirect?VFAQ current version]
 
−
on the internet.
 
−
</p>
 
−
<p>
 
−
If you have some question not answered in this FAQ, do not be afraid to
 
−
contact the [http://tag.povray.org/ TAG]
 
−
or ask in the proper group of the [news://news.povray.org POV-Ray news-server].
 
−
</p>
 
−
===Language Tips and tricks to achieve useful things===
 
−
 
 
−
===How do I make a visible light source?===
 
−
<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:
 
−
 
 
−
<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>
 
−
<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>
 
−
 
 
−
===How do I make bright objects?===
 
−
<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>
 
−
 
 
−
===How do I move the camera in a circular path?===
 
−
<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:
 
−
 
 
−
<pre>
 
−
camera
 
−
{ location &lt;0,0,-10&gt;
 
−
  look_at 0
 
−
  rotate &lt;0,clock*360,0&gt;
 
−
}
 
−
</pre>
 
−
 
 
−
</p>
 
−
<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:
 
−
 
 
−
<pre>
 
−
camera
 
−
{ location &lt;10*sin(2*pi*clock),0,-10*cos(2*pi*clock)&gt;
 
−
  look_at 0
 
−
}
 
−
</pre>
 
−
 
 
−
</p>
 
−
<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.
 
−
 
 
−
<pre>
 
−
camera
 
−
{ location vrotate(x*10, y*360*clock)
 
−
  look_at 0
 
−
}
 
−
</pre>
 
−
 
 
−
</p>
 
−
<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>
 
−
 
 
−
===How do I use an image to texture my object?===
 
−
<p>The answer to this question can be easily found in the POV-Ray
 
−
documentation, so I will just quote the syntax:
 
−
 
 
−
<pre>
 
−
pigment
 
−
{ image_map
 
−
  { gif &quot;image.gif&quot;
 
−
    map_type 1
 
−
  }
 
−
}
 
−
</pre>
 
−
 
 
−
</p>
 
−
<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>
 
−
 
 
−
===How can I generate a spline?===
 
−
<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 [http://web.archive.org/web/20080610121611/http://www.geocities.com/ccolefax/spline/index.html spline macros] by Chris Colefax.
 
−
</p>
 
−
 
 
−
===How can I simulate motion blur?===
 
−
<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 [http://iki.fi/warp/PovUtils/average/ Targa Averager] program.
 
−
</p>
 
−
 
 
−
===How can I find the size of a text object?===
 
−
<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>
 
−
 
 
−
===How do I make extruded text?===
 
−
<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>
 
−
 
 
−
===How do I make an object hollow?===
 
−
<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:
 
−
 
 
−
<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>
 
−
<p>The first cone limits the outer surface of the glass and the second cone
 
−
limits the inner surface.</p>
 
−
 
 
−
===How can I fill a glass with water or other objects?===
 
−
<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:
 
−
 
 
−
<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>
 
−
<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
 
−
<!--<linkto "black spots">coincident surfaces problem</linkto>--->[[Documentation:Tutorial Section 4.1#Why are there strange dark pixels or noise on my CSG object?|coincident surfaces problem]]
 
−
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:
 
−
 
 
−
<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>
 
−
<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:
 
−
 
 
−
<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>
 
−
<p>Now the water level is at a height of 4 units.
 
−
</p>
 
−
 
 
−
===How can I bend a object?===
 
−
<p>There is no direct support for bending in POV-Ray, but you can achieve acceptable
 
−
bending with the [http://www.geocities.com/SiliconValley/Lakes/1434/bend.html Object Bender by Chris Colefax].
 
−
 
 
−
</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
 
−
<!--<linkto "variable ior">variable ior question</linkto>--->[[Documentation:Tutorial Section 4.1#Can I specify variable IOR for an object?|variable ior question]].
 
−
 
 
−
</p>
 
−
 
 
−
===Can I get non-grainy focal blur?===
 
−
<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>
 
−
 
 
−
===Language Things that don't work as one expects===
 
−
 
 
−
===Using several transparent objects makes them black?===
 
−
<p><em>&quot;When I put several
 
−
transparent objects one in front of another or inside another, POV-Ray
 
−
calculates a few of them, but the rest are completely black, no matter
 
−
what transparency values I give.&quot;</em>
 
−
 
 
−
</p>
 
−
<p>Short answer: Try increasing the <code>max_trace_level</code>
 
−
value in the <code>global_settings</code> block (the default is 5).
 
−
 
 
−
</p>
 
−
<p>Long answer:
 
−
 
 
−
</p>
 
−
<p>Raytracing has a peculiar feature: It can calculate
 
−
reflection and refraction. Each time a ray hits the surface of an
 
−
object, the program looks if this surface is reflective and/or
 
−
refractive. If so, it shoots another ray from this point to the
 
−
appropriate direction.
 
−
 
 
−
</p>
 
−
<p>Now, imagine we have a glass sphere. Glass
 
−
reflects and refracts, so when the ray hits the sphere, two additional
 
−
rays are calculated, one outside the sphere (for the reflection) and
 
−
one inside (for the refraction). Now the inside ray will hit the
 
−
sphere again, so two new rays are calculated, and so on and so
 
−
on...
 
−
 
 
−
</p>
 
−
<p>You can easily see that there must be a maximum number of
 
−
reflections/refractions calculated, because otherwise POV-Ray would
 
−
calculate that one pixel forever.
 
−
 
 
−
</p>
 
−
<p>This number can be set with the
 
−
<code>max_trace_level</code> option in the <code>global_settings</code> block.
 
−
The default value
 
−
is 5, which is enough for most scenes. Sometimes it is not enough
 
−
(specially when there are lots of semitransparent objects one over
 
−
another) so you have to increase it.
 
−
 
 
−
</p>
 
−
<p>So try something like:
 
−
<pre>
 
−
global_settings
 
−
{
 
−
  max_trace_level 10
 
−
}
 
−
</pre>
 
−
</p>
 
−
 
 
−
===I'm getting color banding in the image===
 
−
<p><em>&quot;When I make an image with POV-Ray, it seems to use just a few colors
 
−
since I get color banding or concentric circles of colors or whatever where
 
−
it should not. How can I make POV-Ray to use more colors?&quot;</em>
 
−
 
 
−
</p>
 
−
<p>POV-Ray always writes true color images (ie. with 16777216 colors, ie.
 
−
256 shades of red, 256 shades of green and 256 shades of blue) (this can
 
−
be changed when outputting to PNG or to B/W TGA but this is irrelevant when
 
−
answering to this question).
 
−
 
 
−
</p>
 
−
<p>So POV-Ray is not guilty. It always uses the maximum color resolution
 
−
available in the target image file format.
 
−
 
 
−
</p>
 
−
<p>This problem usually happens when you are using windows with 16-bit
 
−
colors (ie. only 65536 colors, the so-called hicolor mode) and open
 
−
the image created by POV-Ray with a program which does not dither the
 
−
image. The image is still true color, but the program is unable to
 
−
show all the colors, but shows only 65536 of them (dithering is a
 
−
method that &quot;fakes&quot; more colors by mixing pixels of two adjacent
 
−
colors to simulate the in-between colors).
 
−
 
 
−
</p>
 
−
<p>So the problem is not
 
−
in POV-Ray, but in your image viewer program. Even if POV-Ray shows a
 
−
poor image while rendering because you have a resolution with too few
 
−
colors, the image file created will have full color range.
 
−
</p>
 
 
<!--<wikinav>--->
 
<!--<wikinav>--->
 
<br>
 
<br>
Line 524: Line 20:
 
[[Documentation:Tutorial Section 3.10#The Camera-setup|The Camera-setup]]</td>
 
[[Documentation:Tutorial Section 3.10#The Camera-setup|The Camera-setup]]</td>
 
<td width=50% bgcolor=#EEEEEF align=right>
 
<td width=50% bgcolor=#EEEEEF align=right>
−
[[Documentation:Tutorial Section 4.1#Rotation behaves very strangely|Rotation behaves very strangely]]</td></tr>
+
[[Documentation:Tutorial Section 5#Appendices|Appendices]]</td></tr>
 
</table>
 
</table>
 
<!--</wikinav>--->
 
<!--</wikinav>--->

Revision as of 09:14, 15 March 2010

This document is protected, so submissions, corrections and discussions should be held on this documents talk page.


Questions and Tips

Now that you've learned the basics, you may have questions about a particular behaviour, or perhaps you're looking for ways to speed up, or improve your scenes. Please refer to to link below to view the POV-Ray Questions and Tips or FAQ.

Use the online Version

Note: Previous versions of this documentation included a copy of the POV-Ray Questions and Tips with the application distribution package. You should now refer to the online version of the POV-Ray Questions and Tips that's located on the POV-Wiki.


The Camera-setup Appendices


This document is protected, so submissions, corrections and discussions should be held on this documents talk page.