Previous:Average Function   Main Index   Next:Declaring Layered Textures



Working With Layered Textures

With the multitudinous colors, patterns, and options for creating complex textures in POV-Ray, we can easily become deeply engrossed in mixing and tweaking just the right textures to apply to our latest creations. But as we go, sooner or later there is going to come that special texture. That texture that is sort of like wood, only varnished, and with a kind of spotty yellow streaking, and some vertical gray flecks, that looks like someone started painting over it all, and then stopped, leaving part of the wood visible through the paint.

Only... now what? How do we get all that into one texture? No pattern can do that many things. Before we panic and say image map there is at least one more option: layered textures.

With layered textures, we only need to specify a series of textures, one after the other, all associated with the same object. Each texture we list will be applied one on top of the other, from bottom to top in the order they appear.

It is very important to note that we must have some degree of transparency (filter or transmit) in the pigments of our upper textures, or the ones below will get lost underneath. We won't receive a warning or an error - technically it is legal to do this: it just doesn't make sense. It is like spending hours sketching an elaborate image on a bare wall, then slapping a solid white coat of latex paint over it.

Let's design a very simple object with a layered texture, and look at how it works. We create a file called LAYTEX.POV and add the following lines.

  #include "colors.inc"

  #include "textures.inc"

  camera {

    location <0, 5, -30>

    look_at <0, 0, 0>

  }

  light_source { <-20, 30, -50> color White }

  plane { y, 0 pigment { checker color Green color Yellow  } }

  background { rgb <.7, .7, 1> }

  box { <-10, 0, -10>, <10, 10, 10>

    texture {

      Silver_Metal // a metal object ...

      normal {     // ... which has suffered a beating

        dents 2

        scale 1.5

      }

    } // (end of base texture)

    texture { // ... has some flecks of rust ...

      pigment {

        granite

        color_map {

          [0.0 rgb <.2, 0, 0> ]

          [0.2 color Brown ]

          [0.2 rgbt <1, 1, 1, 1> ]

          [1.0 rgbt <1, 1, 1, 1> ]

        }

        frequency 16

      }

    } // (end rust fleck texture)

    texture { // ... and some sooty black marks

      pigment {

        bozo

        color_map {

          [0.0 color Black ]

          [0.2 color rgbt <0, 0, 0, .5> ]

          [0.4 color rgbt <.5, .5, .5, .5> ]

          [0.5 color rgbt <1, 1, 1, 1> ]

          [1.0 color rgbt <1, 1, 1, 1> ]

        }

        scale 3

      }

    } // (end of sooty mark texture)

  } // (end of box declaration)

Whew. This gets complicated, so to make it easier to read, we have included comments showing what we are doing and where various parts of the declaration end (so we don't get lost in all those closing brackets!). To begin, we created a simple box over the classic checkerboard floor, and give the background sky a pale blue color. Now for the fun part...

To begin with we made the box use the Silver_Metal texture as declared in textures.inc (for bonus points, look up textures.inc and see how this standard texture was originally created sometime). To give it the start of its abused state, we added the dents normal pattern, which creates the illusion of some denting in the surface as if our mysterious metal box had been knocked around quite a bit.

The flecks of rust are nothing but a fine grain granite pattern fading from dark red to brown which then abruptly drops to fully transparent for the majority of the color map. True, we could probably come up with a more realistic pattern of rust using pigment maps to cluster rusty spots, but pigment maps are a subject for another tutorial section, so let's skip that just now.

Lastly, we have added a third texture to the pot. The randomly shifting bozo texture gradually fades from blackened centers to semi-transparent medium gray, and then ultimately to fully transparent for the latter half of its color map. This gives us a look of sooty burn marks further marring the surface of the metal box. The final result leaves our mysterious metal box looking truly abused, using multiple texture patterns, one on top of the other, to produce an effect that no single pattern could generate!



Previous:Average Function   Main Index   Next:Declaring Layered Textures