Section 4.9.8
When All Else Fails: Material Maps

We have some pretty powerful texturing tools at our disposal, but what if we want a more free form arrangement of complex textures? Well, just as image maps do for pigments, and bump maps do for normals, whole textures can be mapped using a material map, should the need arise.

Just as with image maps and bump maps, we need a source image in bitmapped format which will be called by POV-Ray to serve as the map of where the individual textures will go, but this time, we need to specify what texture will be associated with which palette index. To make such an image, we can use a paint program which allows us to select colors by their palette index number (the actual color is irrelevant, since it is only a map to tell POV-Ray what texture will go at that location). Now, if we have the complete package that comes with POV-Ray, we have in our include files an image called povmap.gif which is a bitmapped image that uses only the first four palette indices to create a bordered square with the words Persistance of Vision in it. This will do just fine as a sample map for the following example. Using our same include files, the camera and light source, we enter the follow object.

plane { -z, 0 texture { material_map { gif "povmap.gif" interpolate 2 once texture { PinkAlabaster } // the inner border texture { pigment { DMFDarkOak } } // outer border texture { Gold_Metal } // lettering texture { Chrome_Metal } // the window panel } translate <-0.5, -0.5, 0> scale 5 } }

The position of the light source and the lack of foreground objects to be reflected do not show these textures off to their best advantage. But at least we can see how the process works. The textures have simply been placed according to the location of pixels of a particular palette index. By using the once keyword (to keep it from tiling), and translating and scaling our map to match the camera we have been using, we get to see the whole thing laid out for us.

Of course, that is just with palette mapped image formats, such as GIF and certain flavors of PNG. Material maps can also use non-paletted formats, such as the TGA files that POV-Ray itself outputs. That leads to an interesting consquence: We can use POV-Ray to produce source maps for POV-Ray! Before we wrap up with some of the limitations of special textures, let's do one more thing with material maps, to show how POV-Ray can make its own source maps.

To begin with, if using an non-paletted image, POV-Ray looks at the 8 bit red component of the pixel's color (which will be a value from 0 to 255) to determine which texture from the list to use. So to create a source map, we need to control very precisely what the red value of a given pixel will be. We can do this by

1.)Using an rgb statement to choose our color such as rgb <x/255, 0, 0>, where "x" is the red value we want to assign that pigment, and then...
2.)Use no light sources and apply a finish of finish { ambient 1 } to all objects, to ensure that highlighting and shadowing will not interfere.

Confused? Alright, here is an example, which will generate a map very much like povmap.gif which we used earlier, except in TGA file format. We notice that we have given the pigments blue and green components too. POV-Ray will ignore that in our final map, so this is really for us humans, whose unaided eyes cannot tell the difference between red variances of 0 to 4/255ths. Without those blue and green variances, our map would look to our eyes like a solid black screen. That may be a great way to send secret messages using POV-Ray (plug it into a material map to decode) but it is no use if we want to see what our source map looks like to make sure we have what we expected to.

We render the following code, and name the resulting file povmap.tga.

camera { orthographic up <0, 5, 0> right <5, 0, 0> location <0, 0, -25> look_at <0, 0, 0> } plane { -z, 0 pigment { rgb <1/255, 0, 0.5> } finish { ambient 1 } } box { <-2.3, -1.8, -0.2>, <2.3, 1.8, -0.2> pigment { rgb <0/255, 0, 1> } finish { ambient 1 } } box { <-1.95, -1.3, -0.4>, <1.95, 1.3, -0.3> pigment { rgb <2/255, 0.5, 0.5> } finish { ambient 1 } } text { ttf "crystal.ttf", "The vision", 0.1, 0 scale <0.7, 1, 1> translate <-1.8, 0.25, -0.5> pigment { rgb <3/255, 1, 1> } finish { ambient 1 } } text { ttf "crystal.ttf", "Persists!", 0.1, 0 scale <0.7, 1, 1> translate <-1.5, -1, -0.5> pigment { rgb <3/255, 1, 1> } finish { ambient 1 } }

All we have to do is modify our last material map example by changing the material map from GIF to TGA and modifying the filename. When we render using the new map, the result is extremely similar to the pallette mapped GIF we used before, except that we didn't have to use an external paint program to generate our source: POV-Ray did it all!

Section 4.9.9
Limitations Of Special Textures

There are a couple limitations to all of the special textures we have seen (from textures, pigment and normal maps through material maps). First, if we have used the default directive to set the default texture for all items in our scene, it will not accept any of the special textures discussed here. This is really quite minor, since we can always declare such a texture and apply it individually to all objects. It doesn't actually prevent us from doing anything we couldn't otherwise do.

The other is more limiting, but as we will shortly see, can be worked around quite easily. If we have worked with layered textures, we have already seen how we can pile multiple texture patterns on top of one another (as long as one texture has transparency in it). This very useful technique has a problem incorporating the special textures we have just seen as a layer. But there is an answer!

For example, say we have a layered texture called Speckled_Metal, which produces a silver metallic surface, and then puts tiny specks of rust all over it. Then we decide, for a really rusty look, we want to create patches of concentrated rust, randomly over the surface. The obvious approach is to create a special texture pattern, with transparency to use as the top layer. But of course, as we have seen, we wouldn't be able to use that texture pattern as a layer. We would just generate an error message. The solution is to turn the problem inside out, and make our layered texture part of the texture pattern instead, like this

// This part declares a pigment for use // in the rust patch texture pattern #declare Rusty = pigment { granite color_map { [ 0 rgb <0.2, 0, 0> ] [ 1 Brown ] } frequency 20 } // And this part applies it // Notice that our original layered texture // "Speckled_Metal" is now part of the map #declare Rust_Patches = texture { bozo texture_map { [ 0.0 pigment {Rusty} ] [ 0.75 Speckled_Metal ] [ 1.0 Speckled_Metal ] } }

And the ultimate effect is the same as if we had layered the rust patches on to the speckled metal anyway.

With the full array of patterns, pigments, normals, finishes, layered and special textures, there is now practically nothing we cannot create in the way of amazing textures. An almost infinite number of new possibilities are just waiting to be created!

Section 4.10
Using Atmospheric Effects

POV-Ray offers a variety of atmospheric effects, i. e. features that affect the background of the scene or the air by which everything is surrounded.

It is easy to assign a simple color or a complex color pattern to a virtual sky sphere. You can create anything from a cloud free, blue summer sky to a stormy, heavy clouded sky. Even starfields can easily be created.

You can use different kinds of fog to create foggy scenes. Multiple fog layers of different colors can add an eerie touch to your scene.

A much more realistic effect can be created by using an atmosphere, a constant fog that interacts with the light coming from light sources. Beams of light become visible and objects will cast shadows into the fog.

Last but not least you can add a rainbow to your scene.

Next Section
Table Of Contents