Povray beginner tutorial: Textures (pigment)

- Textures:

Texture is one of the most comprehensive features in Povray, and this little beginner tutorial will not cover but a few details of it. To see the entire help about Povray textures, see the section 7.6 (pov3.0) or 4.7 (pov3.1) of the documentation (this section is naturally really large).

The general syntax for textures is the following:

texture
{ pigment
  { ...
  }
  finish
  { ...
  }
  normal
  { ...
  }
}

You can also specify any of those (pigment, finish and normal) separately, without the 'texture' body (as we have seen with the pigment color in previous sections). The 'texture' statement is specially useful when declaring textures.
You can declare a complete texture or a pigment, a finish or a normal as an identifier. For example:

#declare MyTexture=
  texture
  { pigment { (pigment statements here) }
    finish { (finish statements here) }
    normal { (normal statements here) }
  }

#declare MyPigment=
  pigment
  { (pigment statements...)
  }

When using declared textures, be sure you use them inside the correct statement. For example:

object
{ MyObject1
  texture { MyTexture }
}
object
{ MyObject2
  pigment { MyPigment }
}

Povray 3.1: Besides the texture-block there's an interior-block for defining properties of the interior of the object. Some properties which were inside the finish-block in 3.0 are now moved into the interior-block.

- Pigment:

The pigment defines the coloration of the surface of the object.
To declare a uniform color, we have several possibilities.
The color can have 5 components: red, green, blue, filter and transmit. You can define each one separately, for example:

pigment { red 1 green 0.5 blue 0.1 filter 0.2 transmit 0.5 }
(they are all optional.)
You can also use a color vector after a 'color' keyword, for example:
pigment { color <1, 0.5, 0.1, 0.2, 0.5> }
The first value of the vector is the red component, the second is the green component, the third is the blue component, the fourth is the filter and the last value is the transmit. If you omit one or more values at the end of the vector, they are assumed to be 0. You can also combine a color vector and a color component statement, for example:
pigment { color <1, 0.5, 0.1> transmit 0.5 }
There is also a third possibility to define a color vector (and in my opinion the best one) using the keywords 'rgb', 'rbgf', 'rgbt' or 'rgbft', like this:
pigment { rgb <1, 0.5, 0.1> }
pigment { rgbf <1, 0.5, 0.1, 0.2> }
pigment { rgbt <1, 0.5, 0.1, 0.5> }
pigment { rgbft <1, 0.5, 0.1, 0.2, 0.5> }
'rgb' expects a vector with three components defining red, green and blue. 'rgbf' and 'rgbt' expect a vector with four components, being the last component the filter or the transmit value. 'rgbft' expects a vector with all five components (and is equal to the 'color' statement).

We have already seen what the transmit component does: It gives transparency to the object. However, it doesn't change the color of the light passing through it. It just dimishes the brightness of the light.
Filter is like transmit, but it changes the color of the light passing through it (like a tinted glass).
See the section 7.1.5 of the Povray documentation for a more explicit definition for filter and transmit.

Let's see an example about filter and transmit:

camera { location <0,8,-8> look_at <0,0,0> angle 35 }
light_source { <100,100,-200> color 1 }
plane { <0,1,0>,-1 pigment { rgb <1,1,1> } }
plane { <0,0,-1>,-2 pigment { rgb <1,1,1> } }

sphere { <-2.5,0,0>,1 pigment { rgbf <1,0,0,0.7> } }
sphere { <0,0,0>,1 pigment { rgbt <1,0,0,0.7> } }
sphere { <2.5,0,0>,1 pigment { rgbft <1,0,0,0.7,0.7> } }
The first sphere has a filter value of 0.7, the second has the same value as transmit and the third sphere has both values set to 0.7. The result:

- Color list pigments:

There are three color list patterns: checker, hexagon and brick.
Checker is the typical chessboard checkered pattern. It expects two color statements (and acutally you can use any pigment body you want) separated with commas. For example, to make a chessboard-like floor with white and black tiles, you'll make something like:

plane
{ <0,1,0>,0
  pigment { checker rgb <0,0,0>, rgb <1,1,1> }
}

Hexagon expects three color statements. It is a pattern of hexagonal tiles, like a honeycomb.
Brick expects two color statements. It's handy for making brick walls.

Let's see an example with these three pigment types:

camera { location <0,8,-8> look_at <0,0,0> angle 35 }
light_source { <100,200,-200> color 1 }

// A floor with checker pattern
plane { <0,1,0>,-1 pigment { checker rgb <0,0,0>, rgb <1,1,1> } }

// A cube with hexagon pattern
box
{ <-1,-1,-1>,<1,1,1>
  pigment
  { hexagon rgb <1,0,0>, rgb <1,1,0>, rgb <1,0.5,0>
    scale 0.3
  }
  translate <-1.5,0,0>
}

// A cube with brick pattern
box
{ <-1,-1,-1>,<1,1,1>
  pigment
  { brick rgb <0.5,0.2,0>, rgb <1,0,0>
    scale 0.2
  }
  translate <1.5,0,0>
}

As you can see in the example, textures can be transformed independently.

A note about textures and transforming: The order of the texture and transform definitions is important. If you transform the object first and then define a texture, the texture is not transformed with the object. If you define the texture first and then transform the object, the texture is transformed too. The transformations made inside a texture block do not affect the object, only the texture.
To visualize this, let's see another example:

camera { location <0,8,-8> look_at <0,0,0> angle 35 }
light_source { <100,200,-200> color 1 }

// The box is first scaled and then textured:
box
{ <-1,-1,-1>,<1,1,1>
  scale <0.5,1,2>
  pigment { checker rgb <1,0,0>, rgb <1,1,0> scale 0.3 }
  translate <-1.5,0,0>
}

// The box is first textured and then scaled:
box
{ <-1,-1,-1>,<1,1,1>
  pigment { checker rgb <1,0,0>, rgb <1,1,0> scale 0.3 }
  scale <0.5,1,2>
  translate <1.5,0,0>
}

It is possible to define entire pigments as color statements for checker, hexagon and brick, for example:

pigment { checker pigment { Pigment1 }, pigment { Pigment2 } }
This way you can easyly define, for example, a chessboard with tiles made of white and black marble pigments (instead of just a constant color)

- textures.inc

There are lots of other pigment types in Povray, but that goes beyond this beginner tutorial.
There is an include file called "textures.inc" which contains lots of predefined textures and pigments and is very suitable for beginners.

Let's see an example:

#include "colors.inc" // This has to be included before "textures.inc"
#include "textures.inc"

camera { location <0,8,-8> look_at <0,0,0> angle 35 }
light_source { <100,200,-200> color White }

box
{ <-3,-1,-3>,<3,0,3>
  pigment
  { checker pigment { Jade }, pigment { Red_Marble }
    scale 6/8
  }
}

To see all the textures available in textures.inc, open it in a text editor and see its contents (actually you'll have to open "textures.v2" since "textures.inc" just includes it).

[Go to the next section]