1// This work is licensed under the Creative Commons Attribution-ShareAlike 3.0 Unported License.
2// To view a copy of this license, visit http://creativecommons.org/licenses/by-sa/3.0/ or send a
3// letter to Creative Commons, 444 Castro Street, Suite 900, Mountain View, California, 94041, USA.
4
5// Persistence Of Vision raytracer sample file.
6// Updated: Feb-2013 for 3.7
7//
8// -w320 -h240
9// -w800 -h600 +a0.3
10
11#version 3.7;
12global_settings { assumed_gamma 1.3 }
13
14#include "stdinc.inc"
15#include "arrays.inc"
16
17
18
19sky_sphere {
20	pigment {gradient y
21		color_map {
22			[0 color Blue*0.6]
23			[1 color White]
24		}
25	}
26}
27
28#default {finish {ambient 0}}
29#declare RS = seed(464786);
30//----------------------------------------
31#declare CamLoc = < 5, 10,-10>;
32camera {
33	location CamLoc
34        right x*image_width/image_height // keep propotions with any aspect ratio
35	angle 45
36	look_at <0, 0, 0>
37}
38
39light_source {<-20, 30, -30>*3 color White*1.5}
40light_source {CamLoc color rgb 0.3}
41//----------------------------------------
42
43#declare Ground =
44isosurface {
45	function {y - f_snoise3d(x/7, 0, z/2)*0.5}
46	threshold 0
47	max_gradient 1.1
48	contained_by {box {<-100,-3,-100>, < 100, 1, 100>}}
49
50/*	texture {
51		pigment {color rgb < 1, 0.9, 0.65>}
52		normal {granite bump_size 0.1 scale 0.01}
53	}*/
54	texture {
55		pigment {color rgb < 1, 0.9, 0.65>}
56		normal {granite 0.2 scale 0.02}
57		finish {
58			brilliance 1.6
59			specular 0.3
60		}
61	}
62}
63object {Ground}
64
65#declare RockColors = array[5]
66{
67	color rgb < 0.5, 0.4, 0.35>,
68	color rgb < 0.4, 0.5, 0.4>,
69	color rgb < 0.8, 0.75, 0.65>,
70	color rgb 0.8,
71	color rgb 0.5
72}
73
74#declare CtrlPtrn = function {pattern {bozo scale < 7, 1, 2>}}
75#declare L = 0;
76#while(L < 750)
77	#declare Pt = trace(Ground, < rand(RS)*25 - 15, 10, rand(RS)*25 - 10>, -y);
78	#if(rand(RS) > CtrlPtrn(Pt.x, Pt.y, Pt.z))
79//		sphere {o, 0.03 + pow(rand(RS), 2)*0.15
80		isosurface {
81			function {f_r(x, y, z) - 1 + f_noise3d(x, y, z)*0.5}
82			threshold 0
83			contained_by {sphere {o, 1}}
84			#if(rand(RS) < 0.5) scale VRand_In_Box(< 1, 0.9, 1>, < 2, 1, 3>, RS) #end
85			rotate y*rand(RS)*360
86			translate -y*0.35
87			scale 0.03 + pow(rand(RS),2)*0.35
88			texture {
89				pigment {Rand_Array_Item(RockColors, RS)*RRand(0.1, 1, RS)}
90				normal {granite bump_size 0.5 scale 0.01}
91			}
92			translate Pt
93		}
94		#declare L = L + 1;
95	#end
96#end
97
98#macro MakeSpineBunch(Pt, Dir, Jitter, Len, BaseRad, Num)
99	#local L = 0;
100	#while(L < Num)
101		#local NewDir = vnormalize(Dir + Jitter*(< rand(RS), rand(RS), rand(RS)>*2 - 1));
102		cone {Pt, BaseRad, Pt + NewDir*Len, 0}
103		#local L = L + 1;
104	#end
105#end
106#macro MakeSpineRows(Body, Stretch, AltJitter, Ridges, Bunches, Spines, SpineJitter, SpineLen, SpineRad)
107	#declare J = 0;
108	#local AltDelta = 180/Bunches;
109	union {
110		#while(J < Ridges)
111			#declare K = 0;
112			#while(K < Bunches)
113				#declare Orig = vrotate(-y*50, x*(K + rand(RS)*AltJitter)*AltDelta);
114				#declare Orig = vrotate(Orig, y*(360*J/Ridges + 360/(Ridges*4)))*Stretch;
115				#declare PtNorm = y;
116				#declare Pt = trace(Body, Orig,-Orig, PtNorm);
117				MakeSpineBunch(Pt, PtNorm, SpineJitter, SpineLen, SpineRad, Spines)
118				#declare K = K + 1;
119			#end
120			#declare J = J + 1;
121		#end
122	}
123#end
124
125#declare sinw = function (x) {(sin(x) + 1)/2}
126
127#declare Ridges = 40;
128#declare RidgeDepth = 0.075;
129
130#declare cactus1Body =
131isosurface {
132	function {sqrt(x*x + pow(y - sqrt((x*x/4) + (z*z/4))*1.5, 2) + z*z) - 1 -
133		(sin(atan2(x, z)*Ridges)*0.5*RidgeDepth)
134	}
135	threshold 0
136        max_gradient 5
137
138	contained_by {sphere {< 0, 0, 0>, 3.1}}
139	texture {
140		pigment {radial
141			color_map {
142				[0.00 color rgb < 0.3, 0.65, 0.4>*0.8]
143				[0.65 color rgb < 0.3, 0.65, 0.4>*0.8]
144				[1.00 color rgb < 0.3, 0.65, 0.4>*0.2]
145			}
146			frequency Ridges sine_wave
147		}
148		normal {dents 0.1 poly_wave 2 scale < 1, 0.15, 1>}
149	}
150}
151#declare Cactus1 =
152union {
153	object {cactus1Body}
154	object {MakeSpineRows(cactus1Body, 1, 0.2, Ridges, 24, 3, 0.5, 1, 0.01)
155		texture {pigment {color rgb < 0.98, 0.98, 0.5>}}
156	}
157	scale < 1, 0.75, 1>
158	translate y*0.35
159}
160
161
162#declare Ridges = 32;
163#declare RidgeDepth = 0.1;
164#declare cactus2Body =
165
166isosurface {
167	function {
168		f_r(x, y*0.35, z) - 1 - sqrt(x*x + z*z)*0.2
169		- (sinw(atan2(x, z)*Ridges)*RidgeDepth)
170	}
171	threshold 0
172	max_gradient 5
173	contained_by {sphere {< 0, 0, 0>, 3.1}}
174	texture {
175		pigment {color rgb < 0.3, 0.65, 0.4>}
176		normal {bozo 0.1 scale < 1, 0.15, 1>}
177	}
178}
179
180#declare Cactus2 =
181union {
182	object {cactus2Body}
183	object {MakeSpineRows(cactus2Body, < 1, 3, 1>, 1, Ridges, 64, 3, 1, 0.5, 0.01)
184		texture {pigment {color rgb < 0.98, 0.98, 0.5>}}
185	}
186	translate y*2
187}
188
189
190
191#declare Ridges = 75;
192#declare RidgeDepth = 0.05;
193#declare cactus3Body =
194
195isosurface {
196	function {
197		sqrt(x*x + pow((y/1.5),2) + z*z) - 1 - sqrt(x*x + z*z)*0.2
198		- (sinw(atan2(x, z)*Ridges)*RidgeDepth)
199	}
200	threshold 0
201	max_gradient 5
202	contained_by {sphere {< 0, 0, 0>, 3.1}}
203	texture {
204		pigment {color rgb < 0.1, 0.5, 0.25>}
205		normal {bozo 0.1 scale 0.15}
206	}
207}
208#declare Cactus3 =
209union {
210	object {cactus3Body}
211	object {MakeSpineRows(cactus3Body, < 1, 1.5, 1>, 1, Ridges, 24, 5, 1, 0.35, 0.01)
212		texture {pigment {color rgb < 0.98, 0.98, 0.85>}}
213	}
214	translate y*1.25
215}
216
217object {Cactus1 translate < 3, 0,-3>}
218object {Cactus2}
219object {Cactus3 translate <-2, 0,-3.5>}
220
221//----------------------------------------
222