/*****************************************************************************\ Planks.inc v1.0 [POV3.1] (c) 8/2000 Eugene Shumulinsky http://art.wickedgremlin.org/three-d/ This is a set of POV-Ray macros used to create textures which look like they're made from many planks of the same material (e.g. like a table top). Though commonly used for wood, any texture can be substituted. Textures passed in are assumed to be lined up along the Z-axis. Be warned, these macros sometimes take a while to run. /////////////////////////////////////////////////////////// The following variables can be set before this file is included with "#declare = ;". The defaults should be okay for just about all cases. Plank_seed: The random seed. Default is "seed(321)". Plank_max_rot: The max number of degrees to use for offset from the Z-axis. Default is 2. Plank_max_trans: The maximum distance to translate the texture along the Z-axis so the planks look less alike. Default is 5. /////////////////////////////////////////////////////////// T_Plank(t_plank) This macro rotates the texture t_plank by a few degrees along the X- and Y-axis to remove any regularity to the pieces. Used by all the other macros. T_Plank_Line(t_plank, pnum, plmin, plmax, gap) This macro creates a "line" of texture t_plank. It should only be used on relatively long and thin objects (e.g. stair railing), and is here for completeness and because it's used a lot by the T_Plank_Plane and T_Plank_Cube macros. pnum: Number of planks before pattern repeats. A value of 2 to 4 is good enough for most cases. plmin: The minumum length of a plank. plmax: The maximum length of a plank. A good estimate is plmin*3. gap: The gap between planks. If plmin and plmax are set to zero, then it works just like T_Plank(t_plank). T_Plank_Plane(t_plank, rnum, pwidth, pnum, plmin, plmax, gap) This macro creates a flat plane that looks like it's made up of many boards (e.g. a hardwood floor). The plane is oriented along the XZ-axis. Same arguments as T_Plank_Line, with the following additions. rnum: Number of rows of planks before the pattern repeats. The range of values depends on the scale. I use 4 to 6 for areas where required detail is low, and 11 to 12 for up close areas. pwidth: The width of the individual planks. T_Plank_Cube(t_plank, rnum, pwidth, pnum, plmin, plmax, gap) This macro creates layers of T_Plank_Planes along the Y-axis. It has the same arguments as T_Plank_Plane. T_Plank_Cylinder(t_plank, pnum, plmin, plmax, gap) This is a weird little macro that mostly works. I made it when I needed a quick barrel texture. It takes a bit of tinkering to get things to look right, since the gap changes size depending on the actual cylinders radius. pnum: The number of planks around the cylinder. \*****************************************************************************/ // // Setting default variables... // #ifndef (Plank_seed) #declare Plank_seed = seed(321); #end #ifndef (Plank_max_rot) #declare Plank_max_rot = 2; #end #ifndef (Plank_max_trans) #declare Plank_max_trans = 5; #end #declare T_Plank_gap = texture { pigment { rgbf 0 } } // // Macros // /////////////////// // Plank #macro T_Plank(t_plank) t_plank rotate <(-Plank_max_rot + rand(Plank_seed)*Plank_max_rot*2), //(-Plank_max_rot + rand(Plank_seed)*Plank_max_rot*2), 0> 0, rand(Plank_seed)*360> translate z*(-Plank_max_trans+rand(Plank_seed)*2*Plank_max_trans) #end /////////////////// // Line #macro T_Plank_Line(t_plank, pnum, plmin, plmax, gap) #if (plmin > plmax) #warning "'plmin' is greater than 'plmax'. 'plmin' set equal to 'plmax'.\n" #local plmin = plmax; #end #if (plmin = 0 & plmax = 0) T_Plank(t_plank) #else #local gradient_offset = 5000*pnum*z; #local tlen = 0; #local l = 0; #local lengths = array[pnum] #while (l < pnum) #local lengths[l] = plmin + rand(Plank_seed)*(plmax-plmin); #local tlen = tlen + lengths[l]; #local l = l + 1; #end gradient z texture_map { #local l = 0; #local tl = 0; #while (l < pnum) #local t_pl = texture { T_Plank(texture { t_plank translate gradient_offset scale 1/tlen }) } [ tl/tlen t_pl ] [ (tl+lengths[l] - gap)/tlen t_pl ] [ (tl+lengths[l] - gap)/tlen T_Plank_gap ] [ (tl+lengths[l])/tlen T_Plank_gap ] #local tl = tl + lengths[l]; #local l = l + 1; #end } scale tlen translate -gradient_offset #end #end /////////////////// // Plane #macro T_Plank_Plane(t_plank, rnum, rwidth, pnum, plmin, plmax, gap) #local gradient_offset = 5000*rwidth*x; #local lrnum = rnum*rwidth; gradient x texture_map { #local l = 0; #local l_inc = 1/rnum; #while (l < 1) #local t_pl = texture { T_Plank_Line(t_plank, pnum, plmin, plmax, gap) scale 1/lrnum translate (-Plank_max_trans+rand(Plank_seed)*2*Plank_max_trans)*z } [ l t_pl ] [ l+l_inc-gap/lrnum t_pl ] [ l+l_inc-gap/lrnum T_Plank_gap ] [ l+l_inc T_Plank_gap ] #local l = l + l_inc; #end } scale lrnum translate -gradient_offset #end /////////////////// // Cube #macro T_Plank_Cube(t_plank, rnum, rwidth, pnum, plmin, plmax, gap) #local gradient_offset = 5000*rwidth*y; #local lrnum = rnum*rwidth; gradient y texture_map { #local l = 0; #local l_inc = 1/rnum; #while (l < 1) #local t_pl = texture { T_Plank_Plane(t_plank, rnum, rwidth, pnum, plmin, plmax, gap) scale 1/lrnum translate (-Plank_max_trans+rand(Plank_seed)*2*Plank_max_trans)*z } [ l t_pl ] [ l+l_inc-gap/lrnum t_pl ] [ l+l_inc-gap/lrnum T_Plank_gap ] [ l+l_inc T_Plank_gap ] #local l = l + l_inc; #end } scale lrnum translate -gradient_offset #end /////////////////// // Cylinder #macro T_Plank_Cylinder(t_plank, pnum, plmin, plmax, gap) #local lg = gap/pnum; radial texture_map { #local l = 0; #local cur_inc = 1/pnum; #local cur = 0; #while (l < pnum) #local lt = texture { T_Plank_Line (texture { t_plank scale 1/pnum rotate (l/pnum)*360*-z rotate -90*x }, pnum, plmin, plmax, gap) } [ cur lt ] [ cur+cur_inc-lg lt ] [ cur+cur_inc-lg T_Plank_gap ] [ cur+cur_inc T_Plank_gap ] #local cur = cur + cur_inc; #local l = l + 1; #end } scale pnum rotate 90*x #end