//////////////////////////////// // // // Blobtower example scene // // by: Dominik Iske (Icewind) // // // //////////////////////////////// // easyblob macro by: Rune, http://runevision.com/ //-------------------------// #macro easyblob (_threshold,_visibleradius,_blobbiness) #local _strength = (1+1/_blobbiness)*_threshold; #local _actualradius = _visibleradius/sqrt(1-sqrt(_threshold/_strength)); _actualradius, _strength #end #macro RVector(Vmin, Vmax, RandSeed) #local xMin = Vmin.x; #local yMin = Vmin.y; #local zMin = Vmin.z; #local xMax = Vmax.x; #local yMax = Vmax.y; #local zMax = Vmax.z; #local RandVector = <(rand(RandSeed)*(xMax-xMin) + xMin), (rand(RandSeed)*(yMax-yMin) + yMin), (rand(RandSeed)*(zMax-zMin) + zMin)>; (RandVector) #end //-------------------------// #macro BlobTower(_Size, _N, _RMax, _RMin, _RStream, _Spline2Power, _Photons, _Spline1, _Spline2, _BaseShapeSwitch, _BaseLandscape, _MaxFails) // _Size : Size of the box, containing the tower // _N : Maximum number of components // _RMax, _RMin : Maximal and minimal radius of the spheres // _RStream : Random-number stream // _Spline2Power : pow(_Spline2(RadSV).x, _Spline2Power), making the tower "sharper" for higher values // _Photons : Switch photons on/off for that tower // _Spline1, _Spline2 : _Spline1 modifies the probability for different radii of the spheres, _Spline2 modifies the probability of placement in a spedific distance from the y-axis // _BaseShapeSwitch : Switch between a plane as base-object for placement [0] or any form you like [1] // _BaseLandscape) : If _BaseShapeSwitch is set to 1, this is the base-object to place the tower on #local Norm = <0,0,0>; #local I = 0; #local J = 0; #local IFails = 0; #local ISucces = 0; #local MaxFails = _MaxFails; //Maximal number of fails, before a component is discarded. #local Positions = array[_N][2]; #local Rads = array[_N]; #if(_BaseShapeSwitch <= 0) #local Stuff = plane{y, 0} #else #local Stuff = object{_BaseLandscape} #end #while (I < _N) #local K1 = 1; #while(K1) //This loop determines the random starting-position using _Spline2 #local RStartVector = RVector(<-_Size.x/2,_Size.y+1000,-_Size.z/2>, <_Size.x/2,_Size.y+1000,_Size.z/2>, _RStream); #local RadSV = sqrt(pow(2*RStartVector.x/_Size.x,2) + pow(2*RStartVector.z/_Size.z,2)); #if(pow(_Spline2(RadSV).x, _Spline2Power) >= rand(_RStream)) #local K1 = 0; #end #end #local K2 = 1; #while(K2) //This loop determines the random sphere-radius using _Spline1 #local RandVal = rand(_RStream); #if(_Spline1(RandVal).x >= rand(_RStream)) #local K2 = 0; #local Rad = RandVal*(_RMax-_RMin)+_RMin; #end #end #local InterPos = trace(Stuff, RStartVector, <0,-1,0>, Norm); //Drop the sphere on the ground (and tower) #if(InterPos.y+Rad<=_Size.y & vlength(Norm) != 0) #local Stuff = union { //Add the sphere to the existing tower object {Stuff} sphere {InterPos, Rad} } #local Positions[I][0] = InterPos; //...and save position... #local Positions[I][1] = Norm; //...normal vector... #local Rads[I] = Rad; //...and radius. #local I = I+1; #local J = 0; #local ISucces = ISucces+1; #else #local J = J+1; #if(J >= MaxFails) #local Positions[I][0] = <0,0,0>; #local Positions[I][1] = <0,0,0>; #local Rads[I] = 0; #local I = I+1; #local J = 0; #local IFails = IFails+1; #end #end #end #local I = 0; #local Blobtower = blob { //Read the saved data and feed them into the blob-components threshold 0.5 #while(I < _N) #if(vlength(Positions[I][1]) != 0 & Rads[I] != 0) sphere {Positions[I][0], easyblob (0.5,Rads[I]*0.8,1.0)} #end #local I = I+1; #end #if(_Photons = on) photons{ target 1.0 refraction on reflection on } #end } object {Blobtower} #debug concat("\nComponents placed = ", str(ISucces,0,0),"\nComponents discarded = ", str(IFails,0,0),"\n") #end //-------------------------// light_source {<600,500,-200> rgb 1} camera { location <4,8,-20> look_at <0,3,0> } #declare Tex1 = texture { pigment {rgb 1} finish { specular 1 roughness 0.01 } }//Yeah, i know, very complicated texture... :p #declare Tex2 = texture { pigment {rgb <0.5,0.7,1.0>} finish { specular 1 roughness 0.01 reflection 0.5 } } #declare Landscape = union { plane{y,0} sphere {<-4,0,0>, 3} sphere {< 4,0,0>, 3} texture {Tex1} } #declare Spline1 = spline { natural_spline 0.0, 1.00 1/3, 0.36 2/3, 0.06 1.0, 0.00 } global_settings {max_trace_level 256} #declare Seed = seed(12345); object {BlobTower(<10,15,10>, 1000, 0.7, 0.2, Seed, 1, off, Spline1, Spline1, 1, Landscape, 10) texture {Tex2}} object{Landscape} //plane{y,0 texture {Tex1}}