How do I make a visible light source?
"How do I make a visible light source?" or: "Although I put the camera just in front of my light source, I can't 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's a light source, not a physical light (like a light bulb or a bright spot like a star). POV-Ray doesn't add anything to that place where the light is coming, ie. there is nothing there, only empty space. It's 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 doesn't cast any shadows. You can make something like this:
light_source
{ <0,0,0>, 1
looks_like
{ sphere
{ <0,0,0>,0.1
pigment { rgb 1 }
finish { ambient 1 }
}
}
translate <10,20,30>
}
It's 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?
"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's 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?
"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 don't 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).
How do I use an image to texture my object?
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 isn't 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?
"How can I generate a spline, for example for a camera path for an animation?"
POV-Ray 3.5 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 (http://www.geocities.com/ccolefax/spline/index.html).
How can I simulate motion blur?
The official POV-Ray 3.5 doesn't support motion blur calculations, but there are some patched versions which do. (eg. the so-called MegaPov, which at the time of writing this documentation
was still based on POV-Ray 3.1 code).
MegaPov can be found at http://nathan.kopp.com/patched.htm
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 (http://iki.fi/warp/PovUtils/average/).
How can I find the size of a text object?
"How can I find the size of a text object / center text / justify text?"
You can use the min_extent() and max_extent() functions (new in POV-Ray 3.5) 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.
How do I make extruded text?
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.
How do I make an object hollow?
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's 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's not that simple.
Firstly: POV-Ray only handles surfaces, not solid 3D-objects. When you specify a sphere, it's actually just a spherical surface. It's only a surface and it's 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 can't 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's hollow and the object is just a surface.
So what's all this "solid" and "hollow" stuff the documentation talks of, and what's 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's 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 isn't 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's 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.
How can I fill a glass with water or other objects?
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's one problem: There's 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.
How can I bend a object?
There's no direct support for bending in POV-Ray, but you can achieve acceptable bending with the Object Bender by Chris Colefax (http://www.geocities.com/SiliconValley/Lakes/1434/bend.html).
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 doesn't. 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's 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 can't "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.
Can I get non-grainy focal blur?
"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.
Is blurred reflection possible?
In the unofficial POV-Ray patch called MegaPov there is a feature which
allows calculating blurred reflection (which works by shooting many
reflected rays and averaging the result instead of shooting just one, as
POV-Ray does by default). People were a bit disappointed when this feature
was not included in POV-Ray 3.5.
However, is there any way to get blurred reflection in 3.5?
Perhaps a bit surprisingly, the answer is yes. You can get blurred reflection
which works pretty much like the one in MegaPov, and which can even look better
and be a bit faster to render...
The trick is to use averaged textures with differing normals:
When POV-Ray calculates the color of an averaged texture map, it has to calculate the color of each texture individually before it can average them. If the textures are reflective, it has to shoot a reflected ray for each texture in order to get its color. The trick exploits this behaviour in order to achieve blurred reflection by shooting many reflected rays: The idea is to create many identical textures but with slightly differing normals and then average them, which causes POV-Ray to shoot a reflected ray for each one of them.
So you can implement this trick like this:
#declare BlurAmount = .2; // Amount of blurring
#declare BlurSamples = 40; // How many rays to shoot
object
{ MyObject
texture
{ average texture_map
{ #declare Ind = 0;
#declare S = seed(0);
#while(Ind < BlurSamples)
[1 // The pigment of the object:
pigment { ObjectPigment }
// The surface finish:
finish { ObjectFinish }
// This is the actual trick:
normal
{ bumps BlurAmount
translate <rand(S),rand(S),rand(S)>*100
scale 1000
}
]
#declare Ind = Ind+1;
#end
}
}
}
There are basically two ways of using this trick: scaling the normals very big (as in the example above) or scaling them very small (ie. with something like scale .001). These two give slightly different results with their own advantages and disadvantages:
- Scaling very big will usually produce much smoother results, but if the amount of blurriness (
BlurAmount) is high it often requires quite many samples to avoid banding artifacts. It works best when the blur amount is small. Another disadvantage is that it may sometimes be rather slow when using heavy antialiasing.
- Scaling very small will usually produce a rather grainy result which may or may not look good. The advantage of this is that a heavy antialiasing will make the blurriness look better. If you are going to use extreme antialiasing settings for your final rendering, you can often lower the blur samples amount for extra speed and still get a good-looking result.
Also note that this exact same trick can be used to get blurred refraction. It's also possible to get uneven blur, eg. the reflection is blurred more in the x-axis direction than in the other directions (this is achieved by scaling the normals unevenly), and countless variations of this (eg. the amount and direction of the blur may vary throughout the surface of the object) which makes this trick even more powerful than the reflection blur in MegaPov.
If you also want to use a normal modifier in the object in addition to the blurred reflection, you can add it to the normal-block as an averaged normal map or similar, for example like this:
normal
{ average normal_map
{ [1 bumps BlurAmount
translate <rand(S),rand(S),rand(S)>*100
scale 1000
]
[1 MyNormal]
}
}
(Note, however, that this will diminish the amount of blur so BlurAmount will have to be doubled. Also the depth of MyNormal should be double from what it normally would be.)
How to get really good antialiasing?
"I have really thin lines or very small details and I'm getting jagged lines and heavy moire patterns no matter what antialiasing settings I use. Is there any way of getting the best possible antialiasing, no matter how long it takes to render?"
You can achieve a very high-quality antialiasing by using the antialiasing settings "+a0.0 +am2". To increase the quality even further, you can increase the value of the "+r" parameter from its default value (which is 3), for example "+r4" (or higher).
Note that this can take really long to render because it makes POV-Ray to calculate antialiasing for every pixel in the image. You can speed up the rendering by giving the "+a" parameter a value larger than 0.0, but any such value will cause jagginess/moire effects if you have lots of really small sub-pixel-sized details in your image. (Usually images don't contain significant amounts of such details and that's why a larger threshold value is enough for most images.)
How to repeat a
cylindrical image map?
"If I use an image map with a cylindrical map type (map_type 2) the
image is used only once around the cylinder. Is there any way to repeat
the image several times around it instead of just once?"
It is indeed only possible to put the image once around a cylinder
when using map_type 2. This is a typical example:
cylinder
{ -y, y, 1
pigment
{ image_map { jpeg "myimage" map_type 2 }
translate -y*.5
scale 2
}
}
The cylinder is wrapped with the image only once. There is a way to
circumvent this limitation, though, and it's by using the cylindrical
warp transformation. The idea is to use default planar mapping in the
image map, scale it down in the proper axis and then apply a cylindrical
warp to the pigment, like this:
cylinder
{ -y, y, 1
pigment
{ image_map { jpeg "myimage" }
// The trick:
scale <1/8, 1, 1> // repeat 8 times
warp { cylindrical }
translate -y*.5
scale 2
}
}
This same trick can be used to apply the image only to a part of the
cylinder instead of wrapping it around it completely. To achieve this, just
add the keyword once inside the image_map block.
The parts not covered by the image will be transparent (this is very useful
when using layered textures, with the image map on top of another texture).
Note that the cylindrical warp can be used to apply any pigment
(or texture) around the cylinder, not just image maps. This is sometimes
quite useful when wanting to apply something to the surface of a cylinder,
such as a text pattern, like this:
camera { location -z*6 look_at 0 angle 35 }
light_source { <10, 20, -50>, 1 }
cylinder
{ -y, y, 1
pigment
{ object
{ text { ttf "crystal", "Hello", 1.1, 0 }
// Note: Thickness must be larger than cylinder radius
rgb 1, rgb x
}
scale <1/8, 1, 1>
warp { cylindrical }
translate -y*.2
}
rotate y*145
}
plane { y, -1.001 pigment { checker rgb 1, rgb .5 } }
|