Tutorial: Advanced Textures in POV-Ray

To start modeling in POV-ray it is always useful to make some preliminary preparations and organize your environment. It is known from POV documentation that "in general, the more memory you have (up to a point) the faster things will run". Probably this statement is not referring to machines with 1G RAM, but for older computers with 250 Mb memory you can achieve this by installing some flavor of Linux operating system with a lightweight desktop like XFCE. In Linux POV-Ray is a command line tool. This means that it has no GUI at all. For a Windows user the idea of using a program without an interface might seem absurd, but this approach provides some benefits. You can use a more powerful editor than the one built in POV-Ray for Windows. Emacs has a decent POV-mode. Another popular editor written in Java and suitable for POV-Ray is jEdit. I use it both in Linux and Windows. The pieces of POV code you will find below were made by jEdit plugin Code2HTML.

It is not very convenient to use an external editor to edit POV scene files in Windows but is possible. The way is the same as for Linux. You need to make an ini file that contains all the necessary commands like this one generated by povanim in Blender. Take a look also at this tutorial explaining the meaning of every key. In Linux you will need to enter a command pointing to this file in an X-terminal, while in Windows you can do it the following way: Open your ini file in the POV editor and run once. After rendering close it together with all other tabs. POV-Ray will remember the last edited file and will render it every time even if it is closed. Now you can edit your scene in your favorite editor and start rendering by pressing hot-keys combination ALT-G after clicking on the POV window to activate. The error messages will be displayed in the POV-Ray console.

I won't repeat what is said already and describe the POV syntax. All that is very well documented, and you will find tons of syntax examples here. I will say only that it is always a good idea to use some kind of a texture editor to rough in your texture, which can be finely tuned later manually in your favorite editor. On my Debian partition I used Truevision, 3D modeler for Gnome, converted from rpm with alien. Truevision was nice but crashed too often to be called usable, and I wrote my own texture editor TexGenPOV. Give it a try.

No matter how simple or complex textures are, each following texture if applied occupies the whole volume and lays on top of the previous one. Let's take a look at the examples.

This is just a simple texture with a color map.

plain_texture.jpg
   1:#declare C_Map = color_map {
   2:                                [ 0.0 rgbft<1,0,0,0,0> ]
   3:                                [ 0.4 rgbft<1,1,0,0,0> ]
   4:                                [ 0.6 rgbft<1,1,0,0,0> ]
   5:                                [ 1.0 rgbft<0,0,1,0,0> ]
   6:                        }
   7:
   8:
   9:#declare Plain = 
  10:        
  11:        texture {
  12:                pigment {
  13:                        wood
  14:                        color_map {C_Map}
  15:                        translate <0,0,0> scale <0.1,0.1,0.1> rotate <0,0,0>
  16:                }
  17:        }
  18:
  19:
  20:
  21:box {
  22:        <1,1,-1>,
  23:        <-1,-1,1>
  24:        texture {Plain}
  25:        
  26:} 

But if we apply a list texture, checker in this case, with the same parameters for each texture, we will get the same result.

checker1.jpg
   1:#declare Checker = 
   2:        texture {checker
   3:        texture {
   4:                pigment {
   5:                        wood
   6:                        color_map {C_Map}
   7:                        translate <0,0,0> scale <0.1,0.1,0.1> rotate <0,0,0>
   8:                }
   9:        }
  10: 
  11:        texture {
  12:                pigment {
  13:                        wood
  14:                        color_map {C_Map}
  15:                        translate <0,0,0>  scale <0.1,0.1,0.1> rotate <0,0,0>
  16:                }
  17:        }
  18:
  19:}
  20:
  21:
  22:box {
  23:        <1,1,-1>,
  24:        <-1,-1,1>
  25:        texture {Checker}
  26:}

As we see, each time a texture occupies the whole volume and in checker the second texture is not noticeable until we change something in it.

checker2.jpg
   1:#declare Checker = 
   2:        texture {checker
   3:        texture {
   4:                pigment {
   5:                      wood
   6:                      color_map {C_Map}
   7:                      translate <0,0,0> scale <0.1,0.1,0.1> rotate <0,0,0>
   8:                }
   9:        }
  10: 
  11:        texture {
  12:                pigment {
  13:                        wood
  14:                        color_map {C_Map}
  15:                        translate <0,0,0> scale 0.3 rotate <0,0,0>
  16:                }
  17:        }
  18:
  19:}
  20:
  21:
  22:box {
  23:        <1,1,-1>,
  24:        <-1,-1,1>
  25:        texture {Checker}
  26:        
  27:}

But herein lies a problem. What if we want to apply more than one patterned texture? We will get the error: "Parse Error: Cannot layer over a patterned texture". Like on this example:

   1:#declare Checker1 = texture {checker
   2:        texture {
   3:                pigment {
   4:                        wood
   5:                        color_map {C_Map}
   6:                        translate <0,0,0> scale <0.1,0.1,0.1> rotate <0,0,0>
   7:                }
   8:        }
   9: 
  10:        texture {
  11:                pigment {
  12:                        wood
  13:                        color_map {C_Map}
  14:                        translate <0,0,0> scale 0.3 rotate <0,0,0>
  15:                }
  16:        }
  17:}
  18:
  19:
  20:#declare Checker2 =texture {checker
  21:        texture {
  22:                pigment { rgbf <1,0,1,1> }
  23:        }
  24:
  25:        texture {
  26:                pigment { rgbf <1,0,1,1> }
  27:        }
  28:}
  29:
  30:
  31:#declare Patterned = texture {Checker1}
  32:                     texture {Checker2}

To fix this error we need to redeclare everything as pigment:

checker-patterned-good.jpg
   1:#declare Checker1 = pigment {checker
   2:                pigment {
   3:                        wood
   4:                        color_map {C_Map}
   5:                        translate <0,0,0> scale 0.1 rotate <0,0,0>
   6:                }
   7:                
   8:                pigment {
   9:                        wood
  10:                        color_map {C_Map}
  11:                        translate <0,0,0> scale 0.3 rotate <0,0,0>
  12:                }
  13:        }
  14:
  15:
  16:
  17:#declare Checker2 = pigment {checker 
  18:                pigment { rgbf <1,0,1,1> }
  19:                pigment { rgbf <0,1,1,1> }
  20:                }
  21:
  22:#declare Patterned = texture {Checker1}
  23:                     texture {Checker2}

That's all. Now I am going to tell you how I made Malachite.

I have never seen Malachite in reality only on pictures. I took a high resolution image of this mineral and cut a stripe out of it in Gimp. Then using an onscreen pixel ruler and a color picker I made a color map. The illustration is on the top of this page and here. The trickiest part of creating the texture was to find the values for frequency, turbulence, octaves, lambda and omega that resemble the original stone pattern. Then when everything was ready, I extruded the texture along the z-axis with warp planar, because malachite in nature is made of cylinders of mineral stratification.

POV texture Malachite

POV texture Malachite

Malchite Stone

Malachite Stone

Malachite Mineral

Malachite Mineral

Valid XHTML 1.0 Transitional The POV code of the Malachite texture is  here.


© 2007   Alex Ivanov   www.3dplumbing.net   home