<!-- This file copyright Persistence of Vision Raytracer Pty. Ltd. 2003-2004 --> <html> <head> <!-- NOTE: In order to users to help find information about POV-Ray using --> <!-- web search engines, we ask you to *not* let them index documentation --> <!-- mirrors because effectively, when searching, users will get hundreds --> <!-- of results containing the same information! For this reason, the two --> <!-- meta tags below disable archiving and indexing of this page by all --> <!-- search engines that support these meta tags. --> <meta content="noarchive" name="robots"> <meta content="noindex" name="robots"> <meta content="no-cache" http-equiv="Pragma"> <meta content="0" http-equiv="expires"> <title>2.2.5 Simple Texture Options</title> <link href="povray35.css" rel="stylesheet" type="text/css"> </head> <body> <table class="NavBar" width="100%"> <tr> <td align="left" nowrap="" valign="middle" width="32"> <a href="s_60.html"><img alt="previous" border="0" src="prev.png"></a> </td> <td align="left" valign="middle" width="30%"> <a href="s_60.html">2.2.4 The Light Source</a> </td> <td align="center" valign="middle"> <strong class="NavBar">POV-Ray 3.6 for UNIX documentation</strong><br> <strong>2.2.5 Simple Texture Options</strong> </td> <td align="right" valign="middle" width="30%"> <a href="s_62.html">2.2.6 Using the Camera</a> </td> <td align="right" nowrap="" valign="middle" width="32"> <a href="s_62.html"><img alt="next" border="0" src="next.png"></a> </td> </tr> </table> <h3><a name="s02_02_05">2.2.5 </a>Simple Texture Options</h3> <a name="s02_02_05_i1"> <p> The pictures rendered so far where somewhat boring regarding the appearance of the objects. Let's add some fancy features to the texture. </p> <h4><a name="s02_02_05_01">2.2.5.1 </a>Surface Finishes</h4> <p> One of the main features of a ray-tracer is its ability to do interesting things with surface finishes such as highlights and reflection. Let's add a nice little Phong highlight (shiny spot) to a sphere. To do this we need to add a <code>finish</code> keyword followed by a parameter. We change the definition of the sphere to this: </p> <pre> sphere { <0, 1, 2>, 2 texture { pigment { color Yellow } //Yellow is pre-defined in COLORS.INC finish { phong 1 } } } </pre> <p> We render the scene. The <code><a href="s_117.html#s03_05_03_03_01">phong</a></code> keyword adds a highlight the same color of the light shining on the object. It adds a lot of credibility to the picture and makes the object look smooth and shiny. Lower values of phong will make the highlight less bright (values should be between 0 and 1). </p> <h4><a name="s02_02_05_02">2.2.5.2 </a>Adding Bumpiness</h4> <a name="s02_02_05_02_i1"> <p> The highlight we have added illustrates how much of our perception depends on the reflective properties of an object. Ray-tracing can exploit this by playing tricks on our perception to make us see complex details that are not really there. </p> <p> Suppose we wanted a very bumpy surface on the object. It would be very difficult to mathematically model lots of bumps. We can however simulate the way bumps look by altering the way light reflects off of the surface. Reflection calculations depend on a vector called a <em>surface normal</em>. This is a vector which points away from the surface and is perpendicular to it. By artificially modifying (or perturbing) this normal vector we can simulate bumps. We change the scene to read as follows and render it: </p> <pre> sphere { <0, 1, 2>, 2 texture { pigment { color Yellow } normal { bumps 0.4 scale 0.2 } finish { phong 1 } } } </pre> <p> This tells POV-Ray to use the <code>bumps</code> pattern to modify the surface normal. The value 0.4 controls the apparent depth of the bumps. Usually the bumps are about 1 unit wide which does not work very well with a sphere of radius 2. The scale makes the bumps 1/5th as wide but does not affect their depth. </p> <h4><a name="s02_02_05_03">2.2.5.3 </a>Creating Color Patterns</h4> <a name="s02_02_05_03_i1"><a name="s02_02_05_03_i2"><a name="s02_02_05_03_i3"><a name="s02_02_05_03_i4"> <p> We can do more than assigning a solid color to an object. We can create complex patterns in the pigment block like in these examples: </p> <pre> sphere { <0, 1, 2>, 2 texture { pigment { wood color_map { [0.0 color DarkTan] [0.9 color DarkBrown] [1.0 color VeryDarkBrown] } turbulence 0.05 scale <0.2, 0.3, 1> } finish { phong 1 } } } sphere { <0, 1, 2>, 2 texture { pigment { wood color_map { [0.0 color Red] [0.5 color Red] [0.5 color Blue] [1.0 color Blue] } scale <0.2, 0.3, 1> } finish { phong 1 } } } </pre> <p> The keyword <code><a href="#l21">wood</a></code> specifies a pigment <a href="s_125.html#s03_05_11">pattern</a> of concentric rings like rings in wood. For every position in POV-space, a pattern returns a float value in the range from zero to one. Values outside the zero to one range are ignored. The <code><a href="s_115.html#s03_05_01_03">color_map</a></code> specifies what color vector is assigned to that float value. In the first example the color of the wood blends from <code>DarkTan</code> to <code>DarkBrown</code> over the first 90% of the vein and from <code>DarkBrown</code> to <code>VeryDarkBrown</code> over the remaining 10%. In the second example the colors do not blend from one to an other, but change abrupt. The <code><a href="#l22">turbulence</a></code> keyword slightly stirs up the pattern so the veins are not perfect circles and the <code><a href="#l23">scale</a></code> keyword adjusts the size of the pattern. </p> <p> Most patterns are set up by default to give us one <em>feature</em> across a sphere of radius 1.0. A feature is very roughly defined as a color transition. For example, a wood texture would have one band on a sphere of radius 1.0. In this example we scale the pattern using the <code>scale</code> keyword followed by a vector. In this case we scaled 0.2 in the x direction, 0.3 in the y direction and the z direction is scaled by 1, which leaves it unchanged. Scale values larger than one will stretch an element. Scale values smaller than one will squish an element. A scale value of one will leave an element unchanged. </p> <h4><a name="s02_02_05_04">2.2.5.4 </a>Pre-defined Textures</h4> <a name="s02_02_05_04_i1"> <p> POV-Ray has some very sophisticated textures pre-defined in the standard include files <code>glass.inc</code>, <code>metals.inc</code>, <code>stones.inc</code> and <code>woods.inc</code>. Some are entire textures with pigment, normal and/or finish parameters already defined. Some are just pigments or just finishes. </p> <p> We change the definition of our sphere to the following and then re-render it: </p> <pre> sphere { <0, 1, 2>, 2 texture { pigment { DMFWood4 // pre-defined in textures.inc scale 4 // scale by the same amount in all // directions } finish { Shiny } // pre-defined in finish.inc } } </pre> <p> The pigment identifier <code>DMFWood4</code> has already been scaled down quite small when it was defined. For this example we want to scale the pattern larger. Because we want to scale it uniformly we can put a single value after the scale keyword rather than a vector of x, y, z scale factors. </p> <p> We look through the file <code>textures.inc</code> to see what pigments and finishes are defined and try them out. We just insert the name of the new pigment where <code>DMFWood4</code> is now or try a different finish in place of <code>Shiny</code> and re-render our file. </p> <p> Here is an example of using a complete texture identifier rather than just the pieces. </p> <pre> sphere { <0, 1, 2>, 2 texture { PinkAlabaster } } </pre> <p> <a name="l21"> <small><strong>More about "wood"</strong></small> </a> <ul> <li><small> <a href="s_125.html#s03_05_11_36">3.5.11.36 Wood</a> in 3.5.11 Patterns </small> <li><small> <a href="s_148.html#s03_07_17_03">3.7.17.3 Woods</a> in 3.7.17 textures.inc </small> </ul> </p> <p> <a name="l22"> <small><strong>More about "turbulence"</strong></small> </a> <ul> <li><small> <a href="s_126.html#s03_05_12">3.5.12 Pattern Modifiers</a> in 3.5 Textures </small> <li><small> <a href="s_126.html#s03_05_12_05">3.5.12.5 Turbulence</a> in 3.5.12 Pattern Modifiers </small> <li><small> <a href="s_97.html#s03_02_01_04_05">3.2.1.4.5 Functions</a> in 3.2.1.4 Vector Expressions </small> </ul> </p> <p> <a name="l23"> <small><strong>More about "scale"</strong></small> </a> <ul> <li><small> <a href="s_157.html#s03_08_05">3.8.5 Transformations</a> in 3.8 Quick Reference </small> <li><small> <a href="s_63.html#s02_02_07_01_02">2.2.7.1.2 Scale</a> in 2.2.7.1 Transformations </small> </ul> </p> <br> <table class="NavBar" width="100%"> <tr> <td align="left" nowrap="" valign="middle" width="32"> <a href="s_60.html"><img alt="previous" border="0" src="prev.png"></a> </td> <td align="left" valign="middle" width="30%"> <a href="s_60.html">2.2.4 The Light Source</a> </td> <td align="center" valign="middle"> <strong>2.2.5 Simple Texture Options</strong> </td> <td align="right" valign="middle" width="30%"> <a href="s_62.html">2.2.6 Using the Camera</a> </td> <td align="right" nowrap="" valign="middle" width="32"> <a href="s_62.html"><img alt="next" border="0" src="next.png"></a> </td> </tr> </table> </body> </html>