### 2.3.4 Advanced Texture Options

The extremely powerful texturing ability is one thing that really sets POV-Ray apart from other raytracers. So far we have not really tried anything too complex but by now we should be comfortable enough with the program's syntax to try some of the more advanced texture options.

Obviously, we cannot try them all. It would take a tutorial a lot more pages to use every texturing option available in POV-Ray. For this limited tutorial, we will content ourselves to just trying a few of them to give an idea of how textures are created. With a little practice, we will soon be creating beautiful textures of our own.

Note: early versions of POV-Ray made a distinction between pigment and normal patterns, i. e. patterns that could be used inside a `normal` or `pigment` statement. Since POV-Ray 3.0 this restriction was removed so that all patterns listed in section "Patterns" can be used as a pigment or normal pattern.

#### 2.3.4.1 Pigments

Every surface must have a color. In POV-Ray this color is called a `pigment`. It does not have to be a single color. It can be a color pattern, a color list or even an image map. Pigments can also be layered one on top of the next so long as the uppermost layers are at least partially transparent so the ones beneath can show through. Let's play around with some of these kinds of pigments.

We create a file called `texdemo.pov` and edit it as follows:

      #include "colors.inc"
      camera {
        location <1, 1, -7>
        look_at 0
        angle 36
      }
      light_source { <1000, 1000, -1000> White }
      plane {
        y, -1.5
        pigment { checker Green, White }
      }
      sphere {
        <0,0,0>, 1
        pigment { Red }
      }

Giving this file a quick test render at 200x150 `-A` we see that it is a simple red sphere against a green and white checkered plane. We will be using the sphere for our textures.

##### 2.3.4.1.1 Using Color List Pigments

Before we begin we should note that we have already made one kind of pigment, the color list pigment. In the previous example we have used a checkered pattern on our plane. There are three other kinds of color list pigments, `brick`, `hexagon` and the `object` pattern. Let's quickly try each of these. First, we change the plane's pigment as follows:

      pigment { hexagon Green, White, Yellow }

Rendering this we see a three-color hexagonal pattern. Note that this pattern requires three colors. Now we change the pigment to...

      pigment { brick Gray75, Red rotate -90*x scale .25 }

Looking at the resulting image we see that the plane now has a brick pattern. We note that we had to rotate the pattern to make it appear correctly on the flat plane. This pattern normally is meant to be used on vertical surfaces. We also had to scale the pattern down a bit so we could see it more easily. We can play around with these color list pigments, change the colors, etc. until we get a floor that we like.

##### 2.3.4.1.2 Using Pigment and Patterns

Let's begin texturing our sphere by using a pattern and a color map consisting of three colors. We replace the pigment block with the following.

      pigment {
        gradient x
        color_map {
          [0.00 color Red]
          [0.33 color Blue]
          [0.66 color Yellow]
          [1.00 color Red]
        }
      }

Rendering this we see that the `gradient` pattern gives us an interesting pattern of vertical stripes. We change the gradient direction to y. The stripes are horizontal now. We change the gradient direction to z. The stripes are now more like concentric rings. This is because the gradient direction is directly away from the camera. We change the direction back to x and add the following to the pigment block.

      pigment {
        gradient x
        color_map {
          [0.00 color Red]
          [0.33 color Blue]
          [0.66 color Yellow]
          [1.00 color Red]
        }
        rotate -45*z          // <- add this line
      }

The vertical bars are now slanted at a 45 degree angle. All patterns can be rotated, scaled and translated in this manner. Let's now try some different types of patterns. One at a time, we substitute the following keywords for `gradient x` and render to see the result: `bozo`, `marble`, `agate`, `granite`, `leopard`, `spotted` and `wood` (if we like we can test all patterns listed in section "Patterns").

Rendering these we see that each results in a slightly different pattern. But to get really good results each type of pattern requires the use of some pattern modifiers.

##### 2.3.4.1.3 Using Pattern Modifiers

Let's take a look at some pattern modifiers. First, we change the pattern type to bozo. Then we add the following change.

      pigment {
        bozo
        frequency 3            // <- add this line
        color_map {
          [0.00 color Red]
          [0.33 color Blue]
          [0.66 color Yellow]
          [1.00 color Red]
        }
        rotate -45*z
      }

The `frequency` modifier determines the number of times the color map repeats itself per unit of size. This change makes the `bozo` pattern we saw earlier have many more bands in it. Now we change the pattern type to `marble`. When we rendered this earlier, we saw a banded pattern similar to `gradient y` that really did not look much like marble at all. This is because marble really is a kind of gradient and it needs another pattern modifier to look like marble. This modifier is called `turbulence`. We change the line `frequency 3` to `turbulence 1` and render again. That's better! Now let's put `frequency 3` back in right after the turbulence and take another look. Even more interesting!

But wait, it gets better! Turbulence itself has some modifiers of its own. We can adjust the turbulence several ways. First, the float that follows the `turbulence` keyword can be any value with higher values giving us more turbulence. Second, we can use the keywords `omega`, `lambda` and `octaves` to change the turbulence parameters.

Let's try this now:

      pigment {
        marble
        turbulence 0.5
        lambda 1.5
        omega 0.8
        octaves 5
        frequency 3
        color_map {
          [0.00 color Red]
          [0.33 color Blue]
          [0.66 color Yellow]
          [1.00 color Red]
        }
        rotate 45*z
      }

Rendering this we see that the turbulence has changed and the pattern looks different. We play around with the numerical values of turbulence, lambda, omega and octaves to see what they do.

##### 2.3.4.1.4 Using Transparent Pigments and Layered Textures

Pigments are described by numerical values that give the rgb value of the color to be used (like `color rgb<1,0,0>` giving us a red color). But this syntax will give us more than just the rgb values. We can specify filtering transparency by changing it as follows: `color rgbf<1,0,0,1>`. The f stands for `filter`, POV-Ray's word for filtered transparency. A value of one means that the color is completely transparent, but still filters the light according to what the pigment is. In this case, the color will be a transparent red, like red cellophane.

There is another kind of transparency in POV-Ray. It is called transmittance or non-filtering transparency (the keyword is `transmit`; see also `rgbt`). It is different from `filter` in that it does not filter the light according to the pigment color. It instead allows all the light to pass through unchanged. It can be specified like this: `rgbt <1,0,0,1>`.

Let's use some transparent pigments to create another kind of texture, the layered texture. Returning to our previous example, declare the following texture.

      #declare LandArea = texture {
          pigment {
            agate
            turbulence 1
            lambda 1.5
            omega .8
            octaves 8
            color_map {
              [0.00 color rgb <.5, .25, .15>]
              [0.33 color rgb <.1, .5, .4>]
              [0.86 color rgb <.6, .3, .1>]
              [1.00 color rgb <.5, .25, .15>]
            }
          }
        }

This texture will be the land area. Now let's make the oceans by declaring the following.

      #declare OceanArea = texture {
          pigment {
            bozo
            turbulence .5
            lambda 2
            color_map {
              [0.00, 0.33 color rgb <0, 0, 1>
                          color rgb <0, 0, 1>]
              [0.33, 0.66 color rgbf <1, 1, 1, 1>
                          color rgbf <1, 1, 1, 1>]
              [0.66, 1.00 color rgb <0, 0, 1>
                          color rgb <0, 0, 1>]
            }
          }
        }

Note: how the ocean is the opaque blue area and the land is the clear area which will allow the underlying texture to show through.

Now, let's declare one more texture to simulate an atmosphere with swirling clouds.

      #declare CloudArea = texture {
        pigment {
          agate
          turbulence 1
          lambda 2
          frequency 2
          color_map {
            [0.0 color rgbf <1, 1, 1, 1>]
            [0.5 color rgbf <1, 1, 1, .35>]
            [1.0 color rgbf <1, 1, 1, 1>]
          }
        }
      }

Now apply all of these to our sphere.

      sphere {
        <0,0,0>, 1
        texture { LandArea }
        texture { OceanArea }
        texture { CloudArea }
      }

We render this and have a pretty good rendition of a little planetoid. But it could be better. We do not particularly like the appearance of the clouds. There is a way they could be done that would be much more realistic.

##### 2.3.4.1.5 Using Pigment Maps

Pigments may be blended together in the same way as the colors in a color map using the same pattern keywords and a `pigment_map`. Let's just give it a try.

We add the following declarations, making sure they appear before the other declarations in the file.

      #declare Clouds1 = pigment {
          bozo
          turbulence 1
          color_map {
            [0.0 color White filter 1]
            [0.5 color White]
            [1.0 color White filter 1]
          }
        }
      #declare Clouds2 = pigment {
        agate
        turbulence 1
        color_map {
          [0.0 color White filter 1]
          [0.5 color White]
          [1.0 color White filter 1]
          }
        }
      #declare Clouds3 = pigment {
        marble
        turbulence 1
        color_map {
          [0.0 color White filter 1]
          [0.5 color White]
          [1.0 color White filter 1]
        }
      }
      #declare Clouds4 = pigment {
        granite
        turbulence 1
        color_map {
          [0.0 color White filter 1]
          [0.5 color White]
          [1.0 color White filter 1]
        }
      }

Now we use these declared pigments in our cloud layer on our planetoid. We replace the declared cloud layer with.

      #declare CloudArea = texture {
        pigment {
          gradient y
          pigment_map {
            [0.00 Clouds1]
            [0.25 Clouds2]
            [0.50 Clouds3]
            [0.75 Clouds4]
            [1.00 Clouds1]
          }
        }
      }

We render this and see a remarkable pattern that looks very much like weather patterns on the planet earth. They are separated into bands, simulating the different weather types found at different latitudes.

#### 2.3.4.2 Normals

Objects in POV-Ray have very smooth surfaces. This is not very realistic so there are several ways to disturb the smoothness of an object by perturbing the surface normal. The surface normal is the vector that is perpendicular to the angle of the surface. By changing this normal the surface can be made to appear bumpy, wrinkled or any of the many patterns available. Let's try a couple of them.

##### 2.3.4.2.1 Using Basic Normal Modifiers

We comment out the planetoid sphere for now and, at the bottom of the file, create a new sphere with a simple, single color texture.

      sphere {
        <0,0,0>, 1
        pigment { Gray75 }
        normal { bumps 1 scale .2 }
      }

Here we have added a `normal` block in addition to the `pigment` block (note that these do not have to be included in a `texture` block unless they need to be transformed together or need to be part of a layered texture). We render this to see what it looks like. Now, one at a time, we substitute for the keyword `bumps` the following keywords: `dents`, `wrinkles`, `ripples` and `waves` (we can also use any of the patterns listed in "Patterns"). We render each to see what they look like. We play around with the float value that follows the keyword. We also experiment with the scale value.

For added interest, we change the plane texture to a single color with a normal as follows.

      plane {
        y, -1.5
        pigment { color rgb <.65, .45, .35> }
        normal { dents .75 scale .25 }
      }

##### 2.3.4.2.2 Blending Normals

Normals can be layered similar to pigments but the results can be unexpected. Let's try that now by editing the sphere as follows.

      sphere {
        <0,0,0>, 1
        pigment { Gray75 }
          normal { radial frequency 10 }
          normal { gradient y scale .2 }
      }

As we can see, the resulting pattern is neither a radial nor a gradient. It is instead the result of first calculating a radial pattern and then calculating a gradient pattern. The results are simply additive. This can be difficult to control so POV-Ray gives the user other ways to blend normals.

One way is to use normal maps. A normal map works the same way as the pigment map we used earlier. Let's change our sphere texture as follows.

      sphere {
        <0,0,0>, 1
        pigment { Gray75 }
        normal {
          gradient y
          frequency 3
          turbulence .5
          normal_map {
            [0.00 granite]
            [0.25 spotted turbulence .35]
            [0.50 marble turbulence .5]
            [0.75 bozo turbulence .25]
            [1.00 granite]
          }
        }
      }

Rendering this we see that the sphere now has a very irregular bumpy surface. The gradient pattern type separates the normals into bands but they are turbulated, giving the surface a chaotic appearance. But this gives us an idea.

Suppose we use the same pattern for a normal map that we used to create the oceans on our planetoid and applied it to the land areas. Does it follow that if we use the same pattern and modifiers on a sphere the same size that the shape of the pattern would be the same? Would not that make the land areas bumpy while leaving the oceans smooth? Let's try it. First, let's render the two spheres side-by-side so we can see if the pattern is indeed the same. We un-comment the planetoid sphere and make the following changes.

      sphere {
        <0,0,0>, 1
        texture { LandArea }
        texture { OceanArea }
        //texture { CloudArea }  // <-comment this out
        translate -x             // <- add this transformation
      }

Now we change the gray sphere as follows.

      sphere {
        <0,0,0>, 1
        pigment { Gray75 }
        normal {
          bozo
          turbulence .5
          lambda 2
          normal_map {
            [0.4 dents .15 scale .01]
            [0.6 agate turbulence 1]
            [1.0 dents .15 scale .01]
          }
        }
        translate x // <- add this transformation
      }

We render this to see if the pattern is the same. We see that indeed it is. So let's comment out the gray sphere and add the `normal` block it contains to the land area texture of our planetoid. We remove the transformations so that the planetoid is centered in the scene again.

      #declare LandArea = texture {
        pigment {
          agate
          turbulence 1
          lambda 1.5
          omega .8
          octaves 8
          color_map {
            [0.00 color rgb <.5, .25, .15>]
            [0.33 color rgb <.1, .5, .4>]
            [0.86 color rgb <.6, .3, .1>]
            [1.00 color rgb <.5, .25, .15>]
          }
        }
        normal {
          bozo
          turbulence .5
          lambda 2
          normal_map {
            [0.4 dents .15 scale .01]
            [0.6 agate turbulence 1]
            [1.0 dents .15 scale .01]
          }
        }
      }

Looking at the resulting image we see that indeed our idea works! The land areas are bumpy while the oceans are smooth. We add the cloud layer back in and our planetoid is complete.

There is much more that we did not cover here due to space constraints. On our own, we should take the time to explore slope maps, average and bump maps.

#### 2.3.4.3 Finishes

The final part of a POV-Ray texture is the `finish`. It controls the properties of the surface of an object. It can make it shiny and reflective, or dull and flat. It can also specify what happens to light that passes through transparent pigments, what happens to light that is scattered by less-than-perfectly-smooth surfaces and what happens to light that is reflected by surfaces with thin-film interference properties. There are twelve different properties available in POV-Ray to specify the finish of a given object. These are controlled by the following keywords: `ambient`, `diffuse`, `brilliance`, `phong`, `specular`, `metallic`, `reflection`, `crand` and `iridescence`. Let's design a couple of textures that make use of these parameters.

##### 2.3.4.3.1 Using Ambient

Since objects in POV-Ray are illuminated by light sources, the portions of those objects that are in shadow would be completely black were it not for the first two finish properties, `ambient` and `diffuse`. Ambient is used to simulate the light that is scattered around the scene that does not come directly from a light source. Diffuse determines how much of the light that is seen comes directly from a light source. These two keywords work together to control the simulation of ambient light. Let's use our gray sphere to demonstrate this. Let's also change our plane back to its original green and white checkered pattern.

      plane {
        y, -1.5
        pigment {checker Green, White}
      }
      sphere {
        <0,0,0>, 1
        pigment { Gray75 }
        finish {
          ambient .2
          diffuse .6
        }
      }

In the above example, the default values for ambient and diffuse are used. We render this to see what the effect is and then make the following change to the finish.

      ambient 0
      diffuse 0

The sphere is black because we have specified that none of the light coming from any light source will be reflected by the sphere. Let's change `diffuse` back to the default of 0.6.

Now we see the gray surface color where the light from the light source falls directly on the sphere but the shaded side is still absolutely black. Now let's change `diffuse` to 0.3 and `ambient` to 0.3.

The sphere now looks almost flat. This is because we have specified a fairly high degree of ambient light and only a low amount of the light coming from the light source is diffusely reflected towards the camera. The default values of `ambient` and `diffuse` are pretty good averages and a good starting point. In most cases, an ambient value of 0.1 ... 0.2 is sufficient and a diffuse value of 0.5 ... 0.7 will usually do the job. There are a couple of exceptions. If we have a completely transparent surface with high refractive and/or reflective values, low values of both ambient and diffuse may be best. Here is an example:

    sphere {
       <0,0,0>, 1
       pigment { White filter 1 }
       finish {
          ambient 0
          diffuse 0
          reflection .25
          specular 1
          roughness .001
       }
       interior { ior 1.33 }
    }

This is glass, obviously. Glass is a material that takes nearly all of its appearance from its surroundings. Very little of the surface is seen because it transmits or reflects practically all of the light that shines on it. See `glass.inc` for some other examples.

If we ever need an object to be completely illuminated independently of the lighting situation in a given scene we can do this artificially by specifying an `ambient` value of 1 and a `diffuse` value of 0. This will eliminate all shading and simply give the object its fullest and brightest color value at all points. This is good for simulating objects that emit light like light bulbs and for skies in scenes where the sky may not be adequately lit by any other means.

Let's try this with our sphere now.

      sphere {
         <0,0,0>, 1
         pigment { White }
         finish {
            ambient 1
            diffuse 0
         }
      }

Rendering this we get a blinding white sphere with no visible highlights or shaded parts. It would make a pretty good street light.

##### 2.3.4.3.2 Using Surface Highlights

In the glass example above, we noticed that there were bright little hotspots on the surface. This gave the sphere a hard, shiny appearance. POV-Ray gives us two ways to specify surface specular highlights. The first is called Phong highlighting. Usually, Phong highlights are described using two keywords: `phong` and `phong_size`. The float that follows `phong` determines the brightness of the highlight while the float following `phong_size` determines its size. Let's try this.

      sphere {
        <0,0,0>, 1
        pigment { Gray50 }
        finish {
          ambient .2
          diffuse .6
          phong .75
          phong_size 25
        }
      }

Rendering this we see a fairly broad, soft highlight that gives the sphere a kind of plastic appearance. Now let's change `phong_size` to 150. This makes a much smaller highlight which gives the sphere the appearance of being much harder and shinier.

There is another kind of highlight that is calculated by a different means called specular highlighting. It is specified using the keyword `specular` and operates in conjunction with another keyword called `roughness`. These two keywords work together in much the same way as `phong` and `phong_size` to create highlights that alter the apparent shininess of the surface. Let's try using specular in our sphere.

      sphere {
         <0,0,0>, 1
         pigment { Gray50 }
         finish {
            ambient .2
            diffuse .6
            specular .75
            roughness .1
        }
      }

Looking at the result we see a broad, soft highlight similar to what we had when we used `phong_size` of 25. Change `roughness` to .001 and render again. Now we see a small, tight highlight similar to what we had when we used `phong_size` of 150. Generally speaking, specular is slightly more accurate and therefore slightly more realistic than phong but you should try both methods when designing a texture. There are even times when both phong and specular may be used on a finish.

##### 2.3.4.3.3 Using Reflection, Metallic and Metallic

There is another surface parameter that goes hand in hand with highlights, `reflection`. Surfaces that are very shiny usually have a degree of reflection to them. Let's take a look at an example.

      sphere {
         <0,0,0>, 1
         pigment { Gray50 }
         finish {
            ambient .2
            diffuse .6
            specular .75
            roughness .001
            reflection {
               .5
            }
         }
      }

We see that our sphere now reflects the green and white checkered plane and the black background but the gray color of the sphere seems out of place. This is another time when a lower diffuse value is needed. Generally, the higher `reflection` is the lower `diffuse` should be. We lower the diffuse value to 0.3 and the ambient value to 0.1 and render again. That is much better. Let's make our sphere as shiny as a polished gold ball bearing.

      sphere {
         <0,0,0>, 1
         pigment { BrightGold }
         finish {
            ambient .1
            diffuse .1
            specular 1
            roughness .001
            reflection {
               .75
            }
         }
       }

That is close but there is something wrong, the colour of the reflection and the highlight. To make the surface appear more like metal the keyword `metallic` is used. We add it now to see the difference.

      sphere {
         <0,0,0>, 1
         pigment { BrightGold }
         finish {
            ambient .1
            diffuse .1
            specular 1
            roughness .001
            reflection {
              .75
              metallic
            }
         }
      }

The reflection has now more of the gold color than the color of its environment. Last detail, the highlight. We add another metallic statement, now to the finish and not inside the reflection block.

      sphere {
         <0,0,0>, 1
         pigment { BrightGold }
         finish {
            ambient .1
            diffuse .1
            specular 1
            roughness .001
            metallic
            reflection {
              .75
              metallic
            }
         }
      }

We see that the highlight has taken on the color of the surface rather than the light source. This gives the surface a more metallic appearance.

##### 2.3.4.3.4 Using Iridescence

Iridescence is what we see on the surface of an oil slick when the sun shines on it. The rainbow effect is created by something called thin-film interference (read section "Iridescence" for details). For now let's just try using it. Iridescence is specified by the `irid` statement and three values: amount, `thickness` and `turbulence`. The amount is the contribution to the overall surface color. Usually 0.1 to 0.5 is sufficient here. The thickness affects the "busyness" of the effect. Keep this between 0.25 and 1 for best results. The turbulence is a little different from pigment or normal turbulence. We cannot set `octaves`, `lambda` or `omega` but we can specify an amount which will affect the thickness in a slightly different way from the thickness value. Values between 0.25 and 1 work best here too. Finally, iridescence will respond to the surface normal since it depends on the angle of incidence of the light rays striking the surface. With all of this in mind, let's add some iridescence to our glass sphere.

    sphere {
         <0,0,0>, 1
         pigment { White filter 1 }
         finish {
            ambient .1
            diffuse .1
            reflection .2
            specular 1
            roughness .001
            irid {
              0.35
              thickness .5
              turbulence .5
            }
         }
         interior{
            ior 1.5
            fade_distance 5
            fade_power 1
            caustics 1
         }
    }

We try to vary the values for amount, thickness and turbulence to see what changes they make. We also try to add a `normal` block to see what happens.

#### 2.3.4.4 Working With Pigment Maps

Let's look at the pigment map. We must not confuse this with a color map, as color maps can only take individual colors as entries in the map, while pigment maps can use entire other pigment patterns. To get a feel for these, let's begin by setting up a basic plane with a simple pigment map. Now, in the following example, we are going to declare each of the pigments we are going to use before we actually use them. This is not strictly necessary (we could put an entire pigment description in each entry of the map) but it just makes the whole thing more readable.

      // simple Black on White checkerboard... it's a classic
      #declare Pigment1 = pigment {
        checker color Black color White
        scale .1
      }
      // kind of a "psychedelic rings" effect
      #declare Pigment2 = pigment {
        wood
        color_map {
          [ 0.0 Red ]
          [ 0.3 Yellow ]
          [ 0.6 Green ]
          [ 1.0 Blue ]
        }
      }
      plane {
        -z, 0
        pigment {
          gradient x
          pigment_map {
            [ 0.0 Pigment1 ]
            [ 0.5 Pigment2 ]
            [ 1.0 Pigment1 ]
          }
        }
      }

Okay, what we have done here is very simple, and probably quite recognizable if we have been working with color maps all along anyway. All we have done is substituted a pigment map where a color map would normally go, and as the entries in our map, we have referenced our declared pigments. When we render this example, we see a pattern which fades back and forth between the classic checkerboard, and those colorful rings. Because we fade from Pigment1 to Pigment2 and then back again, we see a clear blending of the two patterns at the transition points. We could just as easily get a sudden transition by amending the map to read.

      pigment_map {
        [ 0.0 Pigment1 ]
        [ 0.5 Pigment1 ]
        [ 0.5 Pigment2 ]
        [ 1.0 Pigment2 ]
      }

Blending individual pigment patterns is just the beginning.

#### 2.3.4.5 Working With Normal Maps

For our next example, we replace the plane in the scene with this one.

      plane {
        -z, 0
        pigment { White }
        normal {
          gradient x
          normal_map {
            [ 0.0 bumps 1 scale .1]
            [ 1.0 ripples 1 scale .1]
          }
        }
      }

First of all, we have chosen a solid white color to show off all bumping to best effect. Secondly, we notice that our map blends smoothly from all bumps at 0.0 to all ripples at 1.0, but because this is a default gradient, it falls off abruptly back to bumps at the beginning of the next cycle. We Render this and see just enough sharp transitions to clearly see where one normal gives over to another, yet also an example of how two normal patterns look while they are smoothly blending into one another.

The syntax is the same as we would expect. We just changed the type of map, moved it into the normal block and supplied appropriate bump types. It is important to remember that as of POV-Ray 3, all patterns that work with pigments work as normals as well (and vice versa, except for facets) so we could just as easily have blended from wood to granite, or any other pattern we like. We experiment a bit and get a feel for what the different patterns look like.

After seeing how interesting the various normals look blended, we might like to see them completely blended all the way through rather than this business of fading from one to the next. Well, that is possible too, but we would be getting ahead of ourselves. That is called the `average` function, and we will return to it a little bit further down the page.

#### 2.3.4.6 Working With Texture Maps

We know how to blend colors, pigment patterns, and normals, and we are probably thinking what about finishes? What about whole textures? Both of these can be kind of covered under one topic. While there is no finish map per se, there are texture maps, and we can easily adapt these to serve as finish maps, simply by putting the same pigment and/or normal in each of the texture entries of the map. Here is an example. We eliminate the declared pigments we used before and the previous plane, and add the following.

      #declare Texture1 = texture {
        pigment { Grey }
        finish { reflection 1 }
      }
      #declare Texture2 = texture {
        pigment { Grey }
        finish { reflection 0 }
      }
      cylinder {
        <-2, 5, -2>, <-2, -5, -2>, 1
        pigment { Blue }
      }
      plane {
        -z, 0
        rotate y * 30
        texture {
          gradient y
          texture_map {
            [ 0.0 Texture1 ]
            [ 0.4 Texture1 ]
            [ 0.6 Texture2 ]
            [ 1.0 Texture2 ]
          }
          scale 2
        }
      }

Now, what have we done here? The background plane alternates vertically between two textures, identical except for their finishes. When we render this, the cylinder has a reflection part of the way down the plane, and then stops reflecting, then begins and then stops again, in a gradient pattern down the surface of the plane. With a little adaptation, this could be used with any pattern, and in any number of creative ways, whether we just wanted to give various parts of an object different finishes, as we are doing here, or whole different textures altogether.

One might ask: if there is a texture map, why do we need pigment and normal maps? Fair question. The answer: speed of calculation. If we use a texture map, for every in-between point, POV-Ray must make multiple calculations for each texture element, and then run a weighted average to produce the correct value for that point. Using just a pigment map (or just a normal map) decreases the overall number of calculations, and our texture renders a bit faster in the bargain. As a rule of thumb: we use pigment or normal maps where we can and only fall back on texture maps if we need the extra flexibility.

#### 2.3.4.7 Working With List Textures

If we have followed the corresponding tutorials on simple pigments, we know that there are three patterns called color list patterns, because rather than using a color map, these simple but useful patterns take a list of colors immediately following the pattern keyword. We are talking about checker, hexagon, the brick pattern and the object pattern.

Naturally they also work with whole pigments, normals, and entire textures, just as the other patterns do above. The only difference is that we list entries in the pattern (as we would do with individual colors) rather than using a map of entries. Here is an example. We strike the plane and any declared pigments we had left over in our last example, and add the following to our basic file.

      #declare Pigment1 = pigment {
        hexagon
        color Yellow color Green color Grey
        scale .1
      }
      #declare Pigment2 = pigment {
        checker
        color Red color Blue
        scale .1
      }
      #declare Pigment3 = pigment {
        brick
        color White color Black
        rotate -90*x
        scale .1
      }
      box {
        -5, 5
        pigment {
          hexagon
          pigment {Pigment1}
          pigment {Pigment2}
          pigment {Pigment3}
          rotate 90*x
        }
      }

We begin by declaring an example of each of the color list patterns as individual pigments. Then we use the hexagon pattern as a pigment list pattern, simply feeding it a list of pigments rather than colors as we did above. There are two rotate statements throughout this example, because bricks are aligned along the z-direction, while hexagons align along the y-direction, and we wanted everything to face toward the camera we originally declared out in the -z-direction so we can really see the patterns within patterns effect here.

Of course color list patterns used to be only for pigments, but as of POV-Ray 3, everything that worked for pigments can now also be adapted for normals or entire textures. A couple of quick examples might look like

      normal {
        brick
        normal { granite .1 }
        normal { bumps 1 scale .1 }
      }

or...

      texture {
        checker
        texture { Gold_Metal }
        texture { Silver_Metal }
      }

#### 2.3.4.8 What About Tiles?

In earlier versions of POV-Ray, there was a texture pattern called `tiles`. By simply using a checker texture pattern (as we just saw above), we can achieve the same thing as tiles used to do, so it is now obsolete. It is still supported by POV-Ray 3 for backwards compatibility with old scene files, but now is a good time to get in the habit of using a checker pattern instead.

#### 2.3.4.9 Average Function

Now things get interesting. Above, we began to see how pigments and normals can fade from one to the other when we used them in maps. But how about if we want a smooth blend of patterns all the way through? That is where a new feature called `average` can come in very handy. Average works with pigment, normal, and texture maps, although the syntax is a little bit different, and when we are not expecting it, the change can be confusing. Here is a simple example. We use our standard includes, camera and light source from above, and enter the following object.

      plane { -z, 0
        pigment { White }
        normal {
          average
          normal_map {
            [1, gradient x ]
            [1, gradient y ]
          }
        }
      }

What we have done here is pretty self explanatory as soon as we render it. We have combined a vertical with a horizontal gradient bump pattern, creating crisscrossing gradients. Actually, the crisscrossing effect is a smooth blend of gradient x with gradient y all the way across our plane. Now, what about that syntax difference?

We see how our normal map has changed from earlier examples. The floating point value to the left-hand side of each map entry has a different meaning now. It gives the weight factor per entry in the map. Try some different values for the 'gradient x' entry and see how the normal changes.

The weight factor can be omitted, the result then will be the same as if each entry had a weight factor of 1.

#### 2.3.4.10 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 will not receive a warning or an error - technically it is legal to do this: it just does not 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 do not 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!

##### 2.3.4.10.1 Declaring Layered Textures

In the event we want to reuse a layered texture on several objects in our scene, it is perfectly legal to declare a layered texture. We will not repeat the whole texture from above, but the general format would be something like this:

      #declare Abused_Metal =
        texture { /* insert your base texture here... */ }
        texture { /* and your rust flecks here... */ }
        texture { /* and of course, your sooty burn marks here */ }

POV-Ray has no problem spotting where the declaration ends, because the textures follow one after the other with no objects or directives in between. The layered texture to be declared will be assumed to continue until it finds something other than another texture, so any number of layers can be added in to a declaration in this fashion.

One final word about layered textures: whatever layered texture we create, whether declared or not, we must not leave off the texture wrapper. In conventional single textures a common shorthand is to have just a pigment, or just a pigment and finish, or just a normal, or whatever, and leave them outside of a texture statement. This shorthand does not extend to layered textures. As far as POV-Ray is concerned we can layer entire textures, but not individual pieces of textures. For example

      #declare Bad_Texture =
        texture { /* insert your base texture here... */ }
        pigment { Red filter .5 }
        normal { bumps 1 }

will not work. The pigment and the normal are just floating there without being part of any particular texture. Inside an object, with just a single texture, we can do this sort of thing, but with layered textures, we would just generate an error whether inside the object or in a declaration.

##### 2.3.4.10.2 Another Layered Textures Example

To further explain how layered textures work another example is described in detail. A tablecloth is created to be used in a picnic scene. Since a simple red and white checkered cloth looks entirely too new, too flat, and too much like a tiled floor, layered textures are used to stain the cloth.

We are going to create a scene containing four boxes. The first box has that plain red and white texture we started with in our picnic scene, the second adds a layer meant to realistically fade the cloth, the third adds some wine stains, and the final box adds a few wrinkles (not another layer, but we must note when and where adding changes to the surface normal have an effect in layered textures).

We start by placing a camera, some lights, and the first box. At this stage, the texture is plain tiling, not layered. See file `layered1.pov`.

      #include "colors.inc"
      camera {
        location <0, 0, -6>
        look_at <0, 0, 0>
      }
      light_source { <-20, 30, -100> color White }
      light_source { <10, 30, -10> color White }
      light_source { <0, 30, 10> color White }
      #declare PLAIN_TEXTURE =
        // red/white check
        texture {
          pigment {
            checker
            color rgb<1.000, 0.000, 0.000>
            color rgb<1.000, 1.000, 1.000>
            scale <0.2500, 0.2500, 0.2500>
          }
        }
      // plain red/white check box
      box {
        <-1, -1, -1>, <1, 1, 1>
        texture {
          PLAIN_TEXTURE
        }
        translate  <-1.5, 1.2, 0>
      }

We render this scene. It is not particularly interesting, is it? That is why we will use some layered textures to make it more interesting.

First, we add a layer of two different, partially transparent grays. We tile them as we had tiled the red and white colors, but we add some turbulence to make the fading more realistic. We add the following box to the previous scene and re-render (see file `layered2.pov`).

      #declare FADED_TEXTURE =
        // red/white check texture
        texture {
          pigment {
            checker
            color rgb<0.920, 0.000, 0.000>
            color rgb<1.000, 1.000, 1.000>
            scale <0.2500, 0.2500, 0.2500>
          }
        }
        // greys to fade red/white
        texture {
          pigment {
            checker
            color rgbf<0.632, 0.612, 0.688, 0.698>
            color rgbf<0.420, 0.459, 0.520, 0.953>
            turbulence 0.500
            scale <0.2500, 0.2500, 0.2500>
          }
        }
      // faded red/white check box
      box {
        <-1, -1, -1>, <1, 1, 1>
        texture {
          FADED_TEXTURE
        }
        translate  <1.5, 1.2, 0>
      }

Even though it is a subtle difference, the red and white checks no longer look quite so new.

Since there is a bottle of wine in the picnic scene, we thought it might be a nice touch to add a stain or two. While this effect can almost be achieved by placing a flattened blob on the cloth, what we really end up with is a spill effect, not a stain. Thus it is time to add another layer.

Again, we add another box to the scene we already have scripted and re-render (see file `layered3.pov`).

      #declare STAINED_TEXTURE =
        // red/white check
        texture {
          pigment {
            checker
            color rgb<0.920, 0.000, 0.000>
            color rgb<1.000, 1.000, 1.000>
            scale <0.2500, 0.2500, 0.2500>
          }
        }
        // greys to fade check
        texture {
          pigment {
            checker
            color rgbf<0.634, 0.612, 0.688, 0.698>
            color rgbf<0.421, 0.463, 0.518, 0.953>
            turbulence 0.500
            scale <0.2500, 0.2500, 0.2500>
          }
        }
        // wine stain
        texture {
          pigment {
            spotted
            color_map {
              [ 0.000  color rgb<0.483, 0.165, 0.165> ]
              [ 0.329  color rgbf<1.000, 1.000, 1.000, 1.000> ]
              [ 0.734  color rgbf<1.000, 1.000, 1.000, 1.000> ]
              [ 1.000  color rgb<0.483, 0.165, 0.165> ]
            }
            turbulence 0.500
            frequency 1.500
          }
        }
      // stained box
      box {
        <-1, -1, -1>, <1, 1, 1>
        texture {
          STAINED_TEXTURE
        }
        translate  <-1.5, -1.2, 0>
      }

Now there is a tablecloth texture with personality.

Another touch we want to add to the cloth are some wrinkles as if the cloth had been rumpled. This is not another texture layer, but when working with layered textures, we must keep in mind that changes to the surface normal must be included in the uppermost layer of the texture. Changes to lower layers have no effect on the final product (no matter how transparent the upper layers are).

We add this final box to the script and re-render (see file `layered4.pov`)

      #declare WRINKLED_TEXTURE =
        // red and white check
        texture {
          pigment {
            checker
            color rgb<0.920, 0.000, 0.000>
            color rgb<1.000, 1.000, 1.000>
            scale <0.2500, 0.2500, 0.2500>
          }
        }
        // greys to "fade" checks
        texture {
          pigment {
            checker
            color rgbf<0.632, 0.612, 0.688, 0.698>
            color rgbf<0.420, 0.459, 0.520, 0.953>
            turbulence 0.500
            scale <0.2500, 0.2500, 0.2500>
          }
        }
        // the wine stains
        texture {
          pigment {
            spotted
            color_map {
              [ 0.000  color rgb<0.483, 0.165, 0.165> ]
              [ 0.329  color rgbf<1.000, 1.000, 1.000, 1.000> ]
              [ 0.734  color rgbf<1.000, 1.000, 1.000, 1.000> ]
              [ 1.000  color rgb<0.483, 0.165, 0.165> ]
            }
            turbulence 0.500
            frequency 1.500
          }
          normal {
            wrinkles 5.0000
          }
        }
      // wrinkled box
      box {
        <-1, -1, -1>, <1, 1, 1>
        texture {
          WRINKLED_TEXTURE
        }
        translate  <1.5, -1.2, 0>
      }

Well, this may not be the tablecloth we want at any picnic we are attending, but if we compare the final box to the first, we see just how much depth, dimension, and personality is possible just by the use of creative texturing.

One final note: the comments concerning the surface normal do not hold true for finishes. If a lower layer contains a specular finish and an upper layer does not, any place where the upper layer is transparent, the specular will show through.

#### 2.3.4.11 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 "Persistence 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 following 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 consequence: 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 a 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 <N/255,0,0>, where "N" 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 create the following code, name it `povmap.pov`, then render it. This will create an output file called `povmap.tga` (`povmap.bmp` on Windows systems).

      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 palette mapped GIF we used before, except that we did not have to use an external paint program to generate our source: POV-Ray did it all!

#### 2.3.4.12 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 does not actually prevent us from doing anything we could not 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 would not 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!

More about "pigment"

- 3.5.1 Pigment in 3.5 Textures
- 3.8.10.4 Pigment in 3.8.10 Texture

More about "object"

- 3.4 Objects in 3 POV-Ray Reference
- 3.5.11.23 Object Pattern in 3.5.11 Patterns
- 3.8.8 Objects in 3.8 Quick Reference

More about "gradient"

- 3.5.11.17 Gradient in 3.5.11 Patterns
- 3.7.9.3 Vector Analysis in 3.7.9 math.inc

More about "wood"

- 3.5.11.36 Wood in 3.5.11 Patterns
- 3.7.17.3 Woods in 3.7.17 textures.inc

More about "turbulence"

- 3.5.12 Pattern Modifiers in 3.5 Textures
- 3.5.12.5 Turbulence in 3.5.12 Pattern Modifiers
- 3.2.1.4.5 Functions in 3.2.1.4 Vector Expressions

More about "finish"

- 3.5.3 Finish in 3.5 Textures
- 3.8.10.6 Finish in 3.8.10 Texture

More about "ambient"

- 3.5.3 Finish in 3.5 Textures
- 3.5.3.1 Ambient in 3.5.3 Finish