/********************************************************************************** Persistence of Vision Ray Tracer Scene Description File File name : JC_StainedStones.inc Version : 3.6.1c / MegaPOV 1.21 Description : Jim Charter's stained stone texture macro set Date : July 2006 / December 2008 Author : Jim Charter Editor : Thomas A.M. de Groot **********************************************************************************/ #declare S = seed(10000100101010101); //================================================================================ //================================== Macro set =================================== //================================================================================ #macro Stone_finish (Ambient,Diffuse,Specular,Roughness,Reflection) finish { ambient Ambient diffuse Diffuse specular Specular roughness Roughness reflection Reflection } #end //define a crackle pattern as a function with scaling and translation applied #macro Decl_Pf_Crackle (Scale) #ifdef (Pf_Crackle) #undef Pf_Crackle #end #declare Pf_Crackle = function { pigment { crackle poly_wave 1 form <1,0,0> scale Scale } } #end //define a boxed pattern as a function with scaling and translation applied #macro Decl_Pf_Boxed (Scale) #ifdef (Pf_Boxed) #undef Pf_Boxed #end #declare Pf_Boxed = function { pigment { boxed scale Scale*1.075 } } #end //define a function which scales smaller toward the edges of the stone //here a predefined crackle function nested inside the //predefined boxed function #macro Decl_Pf_Edges (Contrast) #ifdef (Pf_Edges) #undef Pf_Edges #end #declare Pf_Edges = function { pigment { function { Pf_Boxed(x,y,z).gray } pigment_map { [0.0 function { (1-Contrast )+Pf_Crackle(x,y,z).gray*Contrast } scale .08] [.12 function { (1-Contrast/2)+Pf_Crackle(x,y,z).gray*Contrast/2 } scale .16] [.36 function { (1-Contrast/3)+Pf_Crackle(x,y,z).gray*Contrast/3 } scale .24] [1.0 function { (1-Contrast/4)+Pf_Crackle(x,y,z).gray*Contrast/4 } scale .32] } } } #end //define a granite pattern as a function with scaling and translation applied #macro Decl_Pf_Granite (Scale) #ifdef (Pf_Granite) #undef Pf_Granite #end #declare Pf_Granite = function { pigment { granite scale Scale translate rand(S)*100 } } #end //define a granite pigment using a predefined granite function #macro Decl_P_Stone (Pf,PMap) #declare P_Stone = pigment { function {Pf_Granite(x,y,z).gray} pigment_map { PMap } } #end //define a bump pattern as a function with scaling and translation applied #macro Decl_Pf_Bumps (Scale) #ifdef (Pf_Bumps) #undef Pf_Bumps #end #declare Pf_Bumps = function { pigment { bumps scale Scale translate <100*rand(S),100*rand(S),0> } } #end //define a gradient pattern as a function with scaling and translation applied #macro Decl_Pf_GradientY (StoneHeight) #ifdef (Pf_GradientY) #undef Pf_GradientY #end #declare Pf_GradientY = function { pigment { gradient y scale <1,2*StoneHeight,1> translate y*StoneHeight } } #end //Apply dripping stains to underlying stone pigment. Result is a pigment #macro Decl_P_Stain (StainColor, StainScale, StonePigment) #ifdef (Pf_Edges) #declare P_Base = pigment { function {Pf_Edges(x,y,z).gray} pigment_map { [0 rgb StainColor] [1 StonePigment] } } #else #declare P_Base = StonePigment #end Decl_Pf_Bumps (StainScale) #declare P_Stain_Top = pigment { function {Pf_GradientY(x,y,z).gray} pigment_map { [0.0 P_Base ] [0.9 function {Pf_Bumps(x,y,z).gray} pigment_map { [0 rgb StainColor ] [1 P_Base ] } ] } } #declare P_Stain_Bottom = pigment { function {Pf_GradientY(x,y,z).gray} pigment_map { [0.0 average pigment_map { #local M = 0; #while(M < 5) Decl_Pf_Bumps (StainScale) //<0.25, 0.5, 0.25> [1 function {Pf_Bumps(x,y,z).gray} pigment_map { [0 rgb StainColor ] [1 P_Base ] } ] #local M = M + 1; #end } ] [0.5 P_Base ] } } #declare P_Stain = pigment { function { Pf_GradientY(x,y,z).gray } pigment_map { [ 0.00 rgb StainColor ] [ 0.01 P_Stain_Bottom ] [ 0.99 P_Stain_Top ] [ 1.00 rgb StainColor ] } } #end #macro Create_Tex (StoneWidth,StoneHeight,StoneDepth,StoneRough,Contrast,CrackScale,StainColor,StainScale,StonePig,GranScale) //produce the needed function definitions Decl_Pf_Granite (GranScale) //scale .075 Decl_Pf_Crackle (CrackScale) //scale .75 Decl_Pf_Boxed ( ) #if (StoneRough) Decl_Pf_Edges (Contrast) //Contrast = 1 1 = full #end Decl_Pf_GradientY (StoneHeight) //produce the pigment definitions Decl_P_Stone (Pf_Granite,StonePig) Decl_P_Stain (StainColor,StainScale,P_Stone) #end //================================================================================ //==================================== Usage ===================================== //================================================================================ // Texture parameters: // ------------------ // StoneWidth Width of the stone/object // StoneHeight Height of the stone/object (this is critical for a correct render) // StoneDepth Depth of the stone/object // StoneRough Boolean switching on/off Contrast and CrackScale // Contrast stone roughness structure becoming finer towards the edges [0 - 1] // CrackScale Scale of the crackle pattern (can be a vector) // StainColor Color of the stains // StainScale Mainly controls the width of the stains // StonePig Color of the stone // GranScale Scale of the stone's granite pattern (can be a vector) // Finish parameters: // ----------------- // Ambient // Diffuse // Specular // Roughness // Reflection //Dimensions of the object: #declare StoneWidth = 1; #declare StoneHeight = 2; #declare StoneDepth = 2; //contrast and color of the stains: #declare StoneRough = false; #declare Contrast = 0.8; #declare CrackScale = 0.75; #declare StainColor = <0.2, 0.1, 0.0>*0.01; #declare StainScale = <0.075, 1.5, 0.075>; #declare StonePig = pigment_map { [0 color rgb <0.8, 0.8, 0.7>] [1 color rgb <0.7, 0.7, 0.5>] } #declare GranScale = 0.075; Create_Tex (StoneWidth,StoneHeight,StoneDepth,StoneRough,Contrast,CrackScale,StainColor,StainScale,StonePig,GranScale) //================================================================================ // Texture and test object: #declare StainedStone = texture { pigment {P_Stain} normal { pigment_pattern { P_Base } bump_size 0.8 } Stone_finish(0,0.9,0.1,0.02,0) } box { <-1, -1, -1>, <1, 1, 1> texture {StainedStone} rotate 45*y } //================================================================================ // Test environment: #version 3.6; global_settings { assumed_gamma 1.0 } camera { location <0.0, 0.5, -7.0> direction 1.5*z right x*image_width/image_height look_at <0.0, 0.0, 0.0> } sky_sphere { pigment { gradient y color_map { [0.0 rgb <0.6,0.7,1.0>] [0.7 rgb <0.0,0.1,0.8>] } } } light_source { <0, 0, 0> color rgb <1, 1, 1> translate <-30, 30, -40> } light_source { <0, 0, 0> color rgb <1, 1, 1>*0.5 translate <30, 30, -30> shadowless } plane { y, -1 pigment { color rgb <0.7,0.5,0.3> } }