/********************************************************************************** Persistence of Vision Ray Tracer Scene Description File File name : Eval_pigmentTest_carpet.pov Version : 3.7 Description : Use of eval_pigment() to place objects in combination with trace() on a height_field or an isosurface with thanks to Norbert Kern's "Warm-up" (1st place IRTC May-June 2001) Date : March 2005/2016 Author : Thomas de Groot Copyright (C) 2005/2016. All rights reserved. **********************************************************************************/ #version 3.7; #include "colors.inc" #include "functions.inc" #include "rand.inc" #include "transforms.inc" global_settings { assumed_gamma 1.0 } default { texture { pigment { rgb <1,0,0> } } } #declare Grey = texture{pigment{Gray50}} // ---------------------------------------- camera { location <0.0, 2, -3.0> direction 1.5*z right x*image_width/image_height angle 50 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> // light's position (translated below) color rgb <1, 1, 1> // light's color translate <-30, 30, -30> } // ---------------------------------------- plane { y, -1 pigment { color rgb <0.7,0.5,0.3> } } #declare SpottedMap = pigment { image_map { jpeg "Oriental Carpets/Carpet_01.jpg" } rotate x*90 translate <-0.5,-0.5,-0.5> scale <1905, 1, 2526>/1000 //carpet dimensions } #declare HF = height_field { png "plasma3.png" //smooth translate <-0.5,-0.5,-0.5> scale <1905, 200, 2526>/1000 //carpet dimensions texture { pigment { SpottedMap } } //normal {granite} finish { diffuse 0.7 } } // -------- Placing objects ------------- #declare Seed = seed(2); //#include "Thomas de Groot/Eval_pigment.mcr" //--------------------- C A R P E T ------------------------------------ // (1) ------------------------------------------------------------------------------- // Based on code by Kirk Andrews (LandscapeTutorial.pov) // ===================================================== //a box for random locations #declare Box = box { <-0.5, -0.1, -0.5>, <0.5, 0.1, 0.5> scale <1905, 1, 2526>/1000 //carpet dimensions translate 1000*y } #declare Rod = cone {<0, 0, 0>, 0.1, <0, 1, 0>, 0.05 scale 0.04} #declare N = 0; #declare P = 10000; //maximum number of 'objects' to place. #declare WriteStrands = off; //set to 'on' for the first pass. // (2) ------------------------------------------------------------------------------- // writing random locations to file: #if (WriteStrands) #debug "Writing carpet strand locations and colours...\n" #fopen StrandLocs "StrandLocs.inc" write #while (N <= P) #local Norm = <0, 0, 0>; // Pick a random place within the scope of the terrain #declare Start = VRand_In_Obj(Box, Seed); // Find out where that random spot is on the height_field and its colour there #declare Pos = trace(HF, Start, -y, Norm); #declare Shader = eval_pigment(SpottedMap,); //Writing the last line in the file: #if (N = P) #write (StrandLocs, Pos,", ",Norm, ", <", str(Shader.x,0,5), ",", str(Shader.y,0,5), ",", str(Shader.z,0,5), ">\n") #else #write (StrandLocs, Pos,", ",Norm, ", <", str(Shader.x,0,5), ",", str(Shader.y,0,5), ",", str(Shader.z,0,5), ">,\n") #end //Just a little code to let me know how the posing is coming along: #if (mod(N,P/100) = 0) #debug concat(" Strands: ", str(N,5,0), "\n") #end #local N = N + 1; #end //of while loop #fclose StrandLocs #end //of Write // (3) ------------------------------------------------------------------------------- // Reading object locations: #debug "Reading carpet strand locations and colours...\n" #fopen StrandLocs "StrandLocs.inc" read #declare Count = 0; #declare Strands = union { #while (defined(StrandLocs)) #read (StrandLocs, Pos, Norm, Shade) #declare Count = Count + 1; //Just a little code to let me know how the posing is coming along: #if (mod(Count, P/100) = 0) #debug concat(" Strands: ", str(Count,5,0), "\n") #end object {Rod pigment {rgb Shade} scale <1, RRand(0.95, 1.05, Seed), 1> Reorient_Trans(y, Norm) translate Pos } #end //of while defined } //end of union #debug "Done.\n\n" union { object {Strands} object {HF} rotate 60*y }