The Online POV-Ray Tutorial

Texture

The topics in this section are texture declarations which don't fit into any other category.

Material Map

Material maps are basically image maps, except you're wrapping patterns of textures around an object instead of patterns of solid colors. This kind of thing is useful for creating inlaid floors, for example. The basic syntax for a material map is like this

texture {
   material_map {
      type "filename"
      /* modifiers */
      texture {
         /* texture 0 */
      }
      texture {
         /* texture 1 */
      }
      /* as many textures as you need */
   }
   /* any transformations */
}

Here, type is one of gif, tga, iff, or dump. This specifies the type of image file being read. This is then followed by filename, in quotes. After the file, you specify any mapping modifiers (like once or map_type). Interpolation is supported for material maps, but it interpolates between textures, not between colors, and so will probably not have the desired effect.

Anyway, for the indexed color type of image (gifs), the texture selected at a point is based on the palette index. For example, if a particular pixel is black, and the palette index of black is 4, then texture 4 will be used to color that point. Color 0 in the palette gets texture 0 in the list mapped onto it. Color 1 in the palette gets texture 1, and so on. If there are not enough textures in the list to assign a texture to a particular number, the indexing will wrap around back to the first texture. For example, if you list three textures, and have a Color 3 in your material map, it will get mapped back to texture 0.

When material mapping rgb images, the value of the red byte for each pixel is used as the texture index.

If you specify a material map, any and all texture declarations (pigment, finish, or normal) must appear in textures in the texture list. They cannot appear outside in the "main" texture declaration. For example, the following is illegal.

texture {
   material_map {
      gif "inlaid.gif"
      texture { Text1 }
      texture { Text2 }
      texture { Text3 }
      texture { Text4 }
   }
   finish { ambient 0 }
}

If you want to do something like this, you must manually add the "ambient 0" to each texture statement in the list.

Here's an example of a material map. The map is the first image, the rendered scene is the second.


Texture

The texture statement is used to give an object a surface texture. Surface textures consist of a pigment, a finish, and a normal. Any of these can be left to the default. Usually finishes and normals are left until the fine-tuning stages of scene production, anyway. Any floating pigment, normal, or finish statement in an object is assumed to be enclosed in a texture block. For example, POV-Ray considers the following statements to be identical. In fact, if you use the first form, POV-Ray assumes you mean the second.

sphere {
   <0, 0, 0>, 5
   pigment { color Green }
}

sphere {
   <0, 0, 0>, 5
   texture {
      pigment { color Green }
   }
}

Most of the different texture components are covered in their own sections.

A very powerful technique in object texturing is that of layered textures. With layered textures, you cover an object with several overlapping textures. Presumably the upper textures have transparent parts to let the lower ones show through. This is down by specifying multiple textures for an object. It might look something like this.

object {
   Something_To_Put_Layered_Textures_On
   texture {         /* the first texture listed goes on the bottom */
      Bottom_Layer
   }
   texture {         /* a middle layer which is draped over the first */
      Middle_Layer
   }
   texture {         /* and finally, a top layer */
      Top_Layer
   }
}

You may have as many textures in a layered texture declaration as you need.

Layered textures allow you to vary the built in textures styles in an almost infinite number of ways. For a number of really awesome examples of layered textures, see the standard include file stones.inc. Here, layered textures are used to create some exceedingly realistic looking stone textures.

As an example, here's a layered texture being constructed from the bottom up. This texture was sort of designed to look like a molten planet or a dying star, but it's up to your imagination. In the first image, there's just a base for the texture. Usually this isn't very complex as everything else will be on top of it, but you can do whatever you want. Here it's just a simple bozo.

Next some violent orange bands were added on top (using agate).

Finally, some random splotches of yellow were put on top (this was done with granite).

Although this particular texture may not be the best or most realistic texture, it's much more interesting than a standard one-layer texture.


Tiles

Tiles are to textures what checker is to colors. The tiles texture uses two textures and creates alternating "blocks" of those textures. When used on a plane, this typically looks like squares of texture. With some creative rotation, you can do a lot more, too. Anyway, the general form for a tiled texture is like this

texture {
   tiles {
      texture { Text1 }
      tile2
      texture { Text2 }
   }
}

The keyword tile2 is a separator and must occur between the two texture declarations. Any transformations of the texture must appear either inside the individual textures (which are to be tiled) or outside the tiles block altogether. A tiled texture may be used as one of the textures in another tiled texture to create a double-tiled texture (but you'll have to scale the inner one down or it'll overlap exactly with the outer one). Anyway, here's an example of a tiled texture.

Here's a tiled texture with one of those aforementioned creative rotations.


Reference Index Top of Document Beginning of the Tutorial

The Online POV-Ray Tutorial © 1996 The Online POV-Ray Tutorial ThinkQuest Team