Difference between revisions of "Documentation:Tutorial Section 3.4"

From POV-Wiki
Jump to navigation Jump to search
m (Protected "Documentation:Tutorial Section 3.4" [edit=sysop:move=sysop])
m (Indexentries fix)
 
(7 intermediate revisions by 3 users not shown)
Line 7: Line 7:
 
<br>
 
<br>
 
<!--</wikitalk>--->
 
<!--</wikitalk>--->
===Using Surface Highlights===
+
<!--REMOVE--->====Finishes====<!--THIS--->
<!--<indexentry "Surface Highlights, using" "Highlights">--->
+
=====Using Surface Highlights=====
<!--<indexentry "phong, tutorial">--->
+
{{#indexentry:Surface Highlights, using}}
 +
{{#indexentry:Highlights}}
 +
{{#indexentry:phong, tutorial}}
 
<p>In the glass example above, we noticed that there were bright little <em>
 
<p>In the glass example above, we noticed that there were bright little <em>
 
hotspots</em> on the surface. This gave the sphere a hard, shiny appearance.
 
hotspots</em> on the surface. This gave the sphere a hard, shiny appearance.
 
POV-Ray gives us two ways to specify surface specular highlights. The first
 
POV-Ray gives us two ways to specify surface specular highlights. The first
is called <em>Phong highlighting.</em> Usually, Phong highlights are
+
is called <em>phong highlighting.</em> Usually, phong highlights are
described using two keywords: <code><!--<linkto "phong">phong</linkto>--->[[Documentation:Reference Section 5.1#Phong Highlights|phong]]</code> and
+
described using two keywords: <code>[[Reference:Finish#Phong Highlights|phong]]</code> and <code>
<code><!--<linkto "phong_size">phong_size</linkto>--->[[Documentation:Reference Section 5.1#Phong Highlights|phong_size]]</code>. The float that follows
+
[[Reference:Finish#Phong Highlights|phong_size]]</code>. The float that follows <code>phong</code> determines the brightness of the highlight while the float following <code>phong_size</code> determines its size. Let's try this.</p>
<code>phong</code> determines the brightness of the highlight while the float
 
following <code>phong_size</code> determines its size. Let's try this.</p>
 
 
<pre>
 
<pre>
 
   sphere {
 
   sphere {
Line 32: Line 32:
  
 
<p>Rendering this we see a fairly broad, soft highlight that gives the sphere
 
<p>Rendering this we see a fairly broad, soft highlight that gives the sphere
a kind of plastic appearance. Now let's change <code> phong_size</code>
+
a kind of plastic appearance. Now let's change <code>phong_size</code>
 
to 150. This makes a much smaller highlight which gives the sphere the
 
to 150. This makes a much smaller highlight which gives the sphere the
 
appearance of being much harder and shinier.</p>
 
appearance of being much harder and shinier.</p>
Line 38: Line 38:
 
There is another kind of highlight that is calculated by a different means
 
There is another kind of highlight that is calculated by a different means
 
called <em>specular highlighting</em>. It is specified using the keyword
 
called <em>specular highlighting</em>. It is specified using the keyword
<code><!--<linkto "specular">specular</linkto>--->[[Documentation:Reference Section 5.1#Specular Highlight|specular]]</code> and operates in conjunction with another keyword
+
<code>[[Reference:Finish#Specular Highlight|specular]]</code> and operates in conjunction with another keyword
called <code><!--<linkto "roughness">roughness</linkto>--->[[Documentation:Reference Section 5.1#Specular Highlight|roughness]]</code>. These two keywords work together in much the
+
called <code>[[Reference:Finish#Specular Highlight|roughness]]</code>. These two keywords work together in much the
 
same way as <code>phong</code> and <code>phong_size</code> to create
 
same way as <code>phong</code> and <code>phong_size</code> to create
 
highlights that alter the apparent shininess of the surface. Let's try
 
highlights that alter the apparent shininess of the surface. Let's try
Line 64: Line 64:
 
both phong and specular may be used on a finish.</p>
 
both phong and specular may be used on a finish.</p>
  
===Using Reflection, Metallic and Metallic===
+
=====Using Reflection, Metallic and Metallic=====
<!--<indexentry "Reflection, using" "Metallic, using">--->
+
{{#indexentry:Reflection, using}}
 +
{{#indexentry:Metallic, using}}
 
<p>There is another surface parameter that goes hand in hand with highlights,
 
<p>There is another surface parameter that goes hand in hand with highlights,
<code><!--<linkto "reflection">reflection</linkto>--->[[Documentation:Reference Section 5.2#Specular Reflection|reflection]]</code>. Surfaces that are very shiny usually have a degree
+
<code>[[Reference:Finish#Specular Reflection|reflection]]</code>. Surfaces that are very shiny usually have a degree
 
of reflection to them. Let's take a look at an example.</p>
 
of reflection to them. Let's take a look at an example.</p>
 
<pre>
 
<pre>
Line 109: Line 110:
  
 
<p>That is close but there is something wrong, the colour of the reflection and the highlight. To
 
<p>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 <code><!--<linkto "metallic">metallic</linkto>--->[[Documentation:Reference Section 5.1#Metallic Highlight Modifier|metallic]]</code>
+
make the surface appear more like metal the keyword <code>[[Reference:Finish#Metallic Highlight Modifier|metallic]]</code>
 
is used. We add it now to see the difference.</p>
 
is used. We add it now to see the difference.</p>
 
<pre>
 
<pre>
Line 150: Line 151:
 
than the light source. This gives the surface a more metallic appearance.</p>
 
than the light source. This gives the surface a more metallic appearance.</p>
  
===Using Iridescence===
+
=====Using Iridescence=====
<!--<indexentry "Irid, using" "Thin-Film Interference" "Interference">--->
+
{{#indexentry:Irid, using}}
 +
{{#indexentry:Thin-Film Interference}}
 +
{{#indexentry:Interference}}
 
<p><em>Iridescence</em> is what we see on the surface of an oil slick when
 
<p><em>Iridescence</em> 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
 
the sun shines on it. The rainbow effect is created by something called
<em>thin-film interference</em> (read section &quot;<!--<linkto "Iridescence">Iridescence</linkto>--->[[Documentation:Reference Section 5.2#Iridescence|Iridescence]]&quot; for
+
<em>thin-film interference</em> (read section [[Reference:Finish#Iridescence|Iridescence]] for
 
details). For now let's just try using it. Iridescence is specified by
 
details). For now let's just try using it. Iridescence is specified by
the <code><!--<linkto "irid">irid</linkto>--->[[Documentation:Reference Section 5.2#Iridescence|irid]]</code> statement and three values: amount,
+
the <code>[[Reference:Finish#Iridescence|irid]]</code> statement and three values: amount,
 
<code>thickness</code> and <code>turbulence</code>. The amount is the contribution
 
<code>thickness</code> and <code>turbulence</code>. The amount is the contribution
 
to the overall surface color. Usually 0.1 to 0.5 is sufficient here.
 
to the overall surface color. Usually 0.1 to 0.5 is sufficient here.
The thickness affects the &quot;busyness&quot; of the effect. Keep this between
+
The thickness affects the <em>busyness</em> of the effect. Keep this between
 
0.25 and 1 for best results. The turbulence is a little different from
 
0.25 and 1 for best results. The turbulence is a little different from
 
pigment or normal turbulence. We cannot set <code>octaves</code>, <code>lambda</code>
 
pigment or normal turbulence. We cannot set <code>octaves</code>, <code>lambda</code>
Line 196: Line 199:
 
happens.</p>
 
happens.</p>
  
===Working With Pigment Maps===
+
====Working With Pigment Maps====
<!--<indexentry "Pigment Maps, working with">--->
+
{{#indexentry:Pigment Maps, working with}}
 
 
 
<p>Let's look at the pigment map. We must not confuse this with a color
 
<p>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,
 
map, as color maps can only take individual colors as entries in the map,
Line 256: Line 258:
 
<p>Blending individual pigment patterns is just the beginning.</p>
 
<p>Blending individual pigment patterns is just the beginning.</p>
  
===Working With Normal Maps===
+
====Working With Normal Maps====
<!--<indexentry "Normal Maps, working with">--->
+
{{#indexentry:Normal Maps, working with}}
<!--<indexentry "normal_map, using">--->
+
{{#indexentry:normal_map, using}}
 
<p> For our next example, we replace the plane in the scene with this
 
<p> For our next example, we replace the plane in the scene with this
 
one.</p>
 
one.</p>
Line 294: Line 296:
 
to see them completely blended all the way through rather than this business
 
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
 
of fading from one to the next. Well, that is possible too, but we would be
getting ahead of ourselves. That is called the <code> average</code>
+
getting ahead of ourselves. That is called the <code>average</code>
 
function, and we will return to it a little bit further down the page.</p>
 
function, and we will return to it a little bit further down the page.</p>
  
===Working With Texture Maps===
+
====Working With Texture Maps====
<!--<indexentry "Texture Maps, working with" "texture_map, tutorial">--->
+
{{#indexentry:Texture Maps, working with}}
 +
{{#indexentry:texture_map, tutorial}}
 
<p>We know how to blend colors, pigment patterns, and normals, and we are
 
<p>We know how to blend colors, pigment patterns, and normals, and we are
 
probably thinking what about finishes? What about whole textures? Both of
 
probably thinking what about finishes? What about whole textures? Both of
Line 354: Line 357:
 
flexibility.</p>
 
flexibility.</p>
  
===Working With List Textures===
+
====Working With List Textures====
<!--<indexentry "List Textures, working with">--->
+
{{#indexentry:List Textures, working with}}
 
<p> If we have followed the corresponding tutorials on simple pigments, we
 
<p> If we have followed the corresponding tutorials on simple pigments, we
 
know that there are three patterns called <em>color list</em> patterns,
 
know that there are three patterns called <em>color list</em> patterns,
Line 426: Line 429:
 
</pre>
 
</pre>
  
===What About Tiles?===
+
====What About Tiles?====
<!--<indexentry "Tiles, what about">--->
+
{{#indexentry:Tiles, what about}}
 
<p>In earlier versions of POV-Ray, there was a texture pattern called
 
<p>In earlier versions of POV-Ray, there was a texture pattern called
 
<code>tiles</code>. By simply using a checker texture pattern (as we just saw
 
<code>tiles</code>. By simply using a checker texture pattern (as we just saw
Line 435: Line 438:
 
checker pattern instead.</p>
 
checker pattern instead.</p>
  
===Average Function===
+
====Average Function====
<!--<indexentry "average, tutorial">--->
+
{{#indexentry:average, tutorial}}
 
<p>Now things get interesting. Above, we began to see how pigments and
 
<p>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
 
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
 
about if we want a smooth blend of patterns all the way through? That is
where a new feature called <code><!--<linkto "average">average</linkto>--->[[Documentation:Reference Section 5.3#Average|average]]</code> can come in very handy.
+
where a new feature called <code>[[Reference:Average Pattern|average]]</code> can come in very handy.
 
Average works with pigment, normal, and texture maps, although the syntax is
 
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
 
a little bit different, and when we are not expecting it, the change can be
Line 471: Line 474:
 
then will be the same as if each entry had a weight factor of 1.</p>
 
then will be the same as if each entry had a weight factor of 1.</p>
  
===Working With Layered Textures===
+
====Working With Layered Textures====
<!--<indexentry "Layered Textures, working with">--->
+
{{#indexentry:Layered Textures, working with}}
 
<p>With the multitudinous colors, patterns, and options for creating complex
 
<p>With the multitudinous colors, patterns, and options for creating complex
 
textures in POV-Ray, we can easily become deeply engrossed in mixing and
 
textures in POV-Ray, we can easily become deeply engrossed in mixing and
Line 577: Line 580:
 
generate!</p>
 
generate!</p>
  
===Declaring Layered Textures===
+
=====Declaring Layered Textures=====
<!--<indexentry "Layered Textures, declaring">--->
+
{{#indexentry:Layered Textures, declaring}}
 
<p>In the event we want to reuse a layered texture on several objects in our
 
<p>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
 
scene, it is perfectly legal to declare a layered texture. We will not
Line 615: Line 618:
 
just generate an error whether inside the object or in a declaration.</p>
 
just generate an error whether inside the object or in a declaration.</p>
  
===Another Layered Textures Example===
+
=====Another Layered Textures Example=====
<!--<indexentry "Layered Textures, another example">--->
+
{{#indexentry:Layered Textures, another example}}
 
<p>To further explain how layered textures work another example is described
 
<p>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
 
in detail. A tablecloth is created to be used in a picnic scene. Since a
Line 631: Line 634:
 
<p>
 
<p>
 
We start by placing a camera, some lights, and the first box. At this stage,
 
We start by placing a camera, some lights, and the first box. At this stage,
the texture is plain tiling, not layered. See file <code>
+
the texture is plain tiling, not layered. See file <code>layered1.pov</code>.</p>
layered1.pov</code>.</p>
 
 
<pre>
 
<pre>
 
   #include &quot;colors.inc&quot;
 
   #include &quot;colors.inc&quot;
Line 765: Line 767:
 
upper layers are).</p>
 
upper layers are).</p>
 
<p>
 
<p>
We add this final box to the script and re-render (see file <code>
+
We add this final box to the script and re-render (see file <code>layered4.pov</code>)</p>
layered4.pov</code>)</p>
 
 
<pre>
 
<pre>
 
   #declare WRINKLED_TEXTURE =
 
   #declare WRINKLED_TEXTURE =
Line 825: Line 826:
 
transparent, the specular will show through.</p>
 
transparent, the specular will show through.</p>
  
===When All Else Fails: Material Maps===
+
====When All Else Fails: Material Maps====
<!--<indexentry "material_map, tutor">--->
+
{{#indexentry:material_map, tutor}}
 
<p>We have some pretty powerful texturing tools at our disposal, but what if
 
<p>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
 
we want a more free form arrangement of complex textures? Well, just as image
Line 868: Line 869:
 
least we can see how the process works. The textures have simply been placed
 
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
 
according to the location of pixels of a particular palette index. By using
the <code><!--<linkto "once">once</linkto>--->[[Documentation:Reference Section 5.6#The once Option|once]]</code> keyword (to keep it from tiling), and translating and
+
the <code>[[Reference:Bitmap Modifiers#The once Option|once]]</code> 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
scaling our map to match the camera we have been using, we get to see the
 
 
whole thing laid out for us.</p>
 
whole thing laid out for us.</p>
 
<p>
 
<p>
Line 903: Line 903:
 
<p>
 
<p>
 
We create the following code, name it <code>povmap.pov</code>, then render
 
We create the following code, name it <code>povmap.pov</code>, then render
it. This will create an output file called <code>povmap.tga</code> (<b><code>povmap.bmp</code>
+
it. This will create an output file called <code>povmap.png</code></p>
on Windows systems</b>).</p>
 
 
<pre>
 
<pre>
 
   camera {
 
   camera {

Latest revision as of 14:23, 16 December 2016

This document is protected, so submissions, corrections and discussions should be held on this documents talk page.


Finishes

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.

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.

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.

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.

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.

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.

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 }
  }

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.

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.

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!

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.

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.

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.png

  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!


Using Ambient Limitations Of Special Textures


This document is protected, so submissions, corrections and discussions should be held on this documents talk page.