2.4 Questions and Tips |
POV-Ray 3.6 for UNIX documentation 2.4.1 Language Tips and tricks to achieve useful things |
2.4.2 Language Things that don't work as one expects |
"How do I make a visible light source?" or: "Although I put the camera just in front of my light source, I cannot see anything. What am I doing wrong?"
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 "hey, there is light coming from this point". As the name says, it is a light source, 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.
To make the light source visible, you have to put something there. There is a looks_like
keyword in
the light_source
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:
light_source { <0,0,0> color 1 looks_like { sphere { <0,0,0>,0.1 color { rgb 1 } finish { ambient 1 } } } translate <10,20,30> }
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.
Note also the 'finish { ambient 1 }
' which makes the sphere to apparently glow (see also the next
question).
You can also get visible light sources using other techniques: Media, lens flare (available as 3rd party include file), glow patch, etc.
"How do I make bright objects, which look like they are emitting light?"
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).
A more sophisticated method would be using an emitting media inside the object (and making the object itself transparent or semi-transparent).
"How do I move the camera in a circular path while looking at the origin?"
There are two ways to make this: The easy (and limited) way, and the more mathematical way.
The easy way:
camera { location <0,0,-10> look_at 0 rotate <0,clock*360,0> }
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).
The mathematical way:
camera { location <10*sin(2*pi*clock),0,-10*cos(2*pi*clock)> look_at 0 }
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).
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.
camera { location vrotate(x*10, y*360*clock) look_at 0 }
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).
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 functions.inc
(new in
POV-Ray 3.5).
The answer to this question can be easily found in the POV-Ray documentation, so I will just quote the syntax:
pigment { image_map { gif "image.gif" map_type 1 } }
(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.)
Substitute the keyword gif
with the type of image you are using (if it is not a GIF): tga, iff,
ppm, pgm, png or sys
.
A map_type 0
gives the default planar mapping.
A map_type 1
gives a spherical mapping
(maps the image onto a sphere).
With map_type 2
you get a cylindrical mapping (maps the image onto a
cylinder).
Finally map_type 5
is a torus or donut shaped mapping (maps the image onto a torus).
See the documentation for more details.
"How can I generate a spline, for example for a camera path for an animation?"
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 spline macros by Chris Colefax.
The official POV-Ray 3.6 does not support motion blur calculations, but there are some patched versions which do.
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 Targa Averager program.
"How can I find the size of a text object / center text / justify text?"
You can use the min_extent()
and max_extent()
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.
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).
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.
This question usually means "how do I make a hollow object, like a waterglass, a jug, etc".
Before answering that question, let me explain some things about how POV-Ray handles objects:
Although the POV-Ray documentation talks about "solid" and "hollow" objects, that is not how it actually works. "Solid" and "hollow" are a bit misleading terms to describe the objects. You can also make an object "hollow" with that same keyword, but it is not that simple.
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).
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 add a new surface 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 "inside" 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.
So what is all this "solid" and "hollow" stuff the documentation talks of, and what is the "hollow" keyword used for?
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.
If you add the "hollow" 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).
If your scene does not use any atmospheric effect (fog or media) there is not any difference between a "solid" or "hollow" object.
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.
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:
// A simple water glass made with a difference: difference { cone { <0,0,0>,1,<0,5,0>,1.2 } cone { <0,.1,0>,.9,<0,5.1,0>,1.1 } texture { Glass } }
The first cone limits the outer surface of the glass and the second cone limits the inner surface.
As described in the "hollow objects" 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:
// A simple water glass made with a difference: #declare MyGlass= difference { cone { <0,0,0>,1,<0,5,0>,1.2 } cone { <0,.1,0>,.9,<0,5.1,0>,1.1 } texture { Glass } }
The first cone limits the outer surface of the glass and the second cone limits the inner surface.
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 coincident surfaces problem so you should scale the "water" object just a little bit smaller than the inner surface of the glass. So we make something like this:
#declare MyGlassWithWater= union { object { MyGlass } cone { <0,.1,0>,.9,<0,5.1,0>,1.1 scale .999 texture { Water } } }
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:
#declare MyGlassWithWater= union { object { MyGlass } intersection { cone { <0,.1,0>,.9,<0,5.1,0>,1.1 } plane { y,4 } scale .999 texture { Water } } }
Now the water level is at a height of 4 units.
There is no direct support for bending in POV-Ray, but you can achieve acceptable bending with the Object Bender by Chris Colefax.
Some objects can be "bent" 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.
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 "scanline-renderers" work):
In the so-called "scanline renders" 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 "bending" is, in fact, achieved by moving the vertices of the triangles.
In this context the term "bending" 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 "bending" 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.
This difference might sound irrelevant, as the result of this kind of "fake" 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 "fake" 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.
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.
See also the variable ior question.
"The focal blur is very grainy. Can I get rid of the graininess?"
Yes. Set variance
to 0 (or to a very small value, like for example 1/100000) and choose a high enough blur_samples
.
The rendering will probably slow down quite a lot, but the result should be very good.
2.4 Questions and Tips | 2.4.1 Language Tips and tricks to achieve useful things | 2.4.2 Language Things that don't work as one expects |