#version 3.8; global_settings {assumed_gamma 1.0 } #include "math.inc" #include "transforms.inc" #declare Zoom = 160; camera { orthographic right x*image_width/Zoom up y*image_height/Zoom location <0, 0, -10> look_at <0, 0, 0> } light_source {<5, 3, -6> rgb 1} sky_sphere {pigment {rgb 1}} #include "functions.inc" #declare Object = sphere {0, 1} //################################################################################################################### #macro ObjectAsIso (_Object, _Sorg, _Depth) #local ObjectAsIsoPattern = function {pattern {object {_Object}}} #local ObjectAsIsoProx = function (x,y,z,S) { ( ObjectAsIsoPattern( x, y, z ) + ObjectAsIsoPattern( x+(S*0.118898), y+(S*0.917706 ), z+(S*0.379049) ) + ObjectAsIsoPattern( x+(S*0.707714), y+(S*0.481318 ), z+(S*0.517179) ) + ObjectAsIsoPattern( x+(S*0.610501), y+(S*0.773853 ), z-(S*0.168644) ) + ObjectAsIsoPattern( x+(S*0.052713), y+(S*0.747854 ), z-(S*0.661767) ) + ObjectAsIsoPattern( x+(S*0.623082), y+(S*0.285055 ), z-(S*0.728363) ) + ObjectAsIsoPattern( x+(S*0.385597), y-(S*0.825183 ), z+(S*0.412781) ) + ObjectAsIsoPattern( x+(S*0.845586), y-(S*0.247858 ), z+(S*0.472811) ) + ObjectAsIsoPattern( x+(S*0.255258), y-(S*0.298976 ), z+(S*0.919487) ) + ObjectAsIsoPattern( x+(S*0.938207), y-(S*0.218780 ), z-(S*0.268146) ) + ObjectAsIsoPattern( x+(S*0.174757), y-(S*0.938110 ), z-(S*0.299015) ) + ObjectAsIsoPattern( x+(S*0.446882), y-(S*0.440226 ), z-(S*0.778780) ) + ObjectAsIsoPattern( x-(S*0.937512), y+(S*0.347669 ), z+(S*0.014056) ) + ObjectAsIsoPattern( x-(S*0.532628), y+(S*0.620243 ), z+(S*0.575852) ) + ObjectAsIsoPattern( x-(S*0.447006), y+(S*0.887248 ), z-(S*0.113917) ) + ObjectAsIsoPattern( x-(S*0.622939), y+(S*0.414059 ), z-(S*0.663704) ) + ObjectAsIsoPattern( x-(S*0.045097), y+(S*0.083557 ), z-(S*0.995482) ) + ObjectAsIsoPattern( x-(S*0.887956), y-(S*0.327793 ), z+(S*0.322623) ) + ObjectAsIsoPattern( x-(S*0.327528), y-(S*0.727050 ), z+(S*0.603427) ) + ObjectAsIsoPattern( x-(S*0.446895), y-(S*0.053668 ), z+(S*0.892975) ) + ObjectAsIsoPattern( x-(S*0.535803), y-(S*0.837654 ), z-(S*0.106071) ) + ObjectAsIsoPattern( x-(S*0.869977), y-(S*0.246679 ), z-(S*0.426953) ) + ObjectAsIsoPattern( x-(S*0.287314), y-(S*0.580587 ), z-(S*0.761820) ) ) } #local ObjectAsPatternBsearch = array[_Depth+1]; #local Cur = 0; // Below must eliminate run of very small constant values arg2 outside object to object surface #local ObjectAsPatternBsearch[Cur]= function (x,y,z,S,Sorg,Depth) { select(S-(2*(Sorg/pow(2,Depth-1))),0,S/Sorg,S/Sorg) } #local Cur = 1; #while (Cur <=_Depth) #local ObjectAsPatternBsearch[Cur]= function (x,y,z,S,Sorg,Depth) { select(23-ObjectAsIsoProx(x,y,z,S),0, ObjectAsPatternBsearch[Cur-1](x,y,z,S+(Sorg/pow(2,Depth+1)),Sorg,Depth+1), ObjectAsPatternBsearch[Cur-1](x,y,z,S-(Sorg/pow(2,Depth+1)),Sorg,Depth+1) ) } #local Cur = Cur + 1; #end select(23-ObjectAsIsoProx(x,y,z,_Sorg),1,1, select(ObjectAsIsoProx(x,y,z,_Sorg),0,0, ObjectAsPatternBsearch[_Depth](x,y,z,_Sorg-(_Sorg/2),_Sorg,1) ) ) #end //################################################################################################################### #declare E = 0.000001; // / image_width; //#declare ObjectFunction = function {0.1 - ObjectAsIso (Object, 0.05, 20) + (f_noise3d(30*x, 30*y, 30*z)/5)} #declare ObjectFunction = function {ObjectAsIso (Object, 0.05, 20)} #declare GradientX = function {(ObjectFunction (x+E,y,z) - ObjectFunction (x,y,z))/E} #declare GradientY = function {(ObjectFunction (x,y+E,z) - ObjectFunction (x,y,z))/E} #declare GradientZ = function {(ObjectFunction (x,y,z+E) - ObjectFunction (x,y,z))/E} #declare GradientVector = function { sqrt ( pow (GradientX(x,y,z),2) + pow (GradientY(x,y,z),2) + pow (GradientZ(x,y,z),2) ) } #declare NormalX = function {(GradientX(x,y,z) / GradientVector(x,y,z))*0.5+0.5} #declare NormalY = function {(GradientY(x,y,z) / GradientVector(x,y,z))*0.5+0.5} #declare NormalZ = function {(GradientZ(x,y,z) / GradientVector(x,y,z))*0.5+0.5} //---------------------------------- #declare P_Red = pigment { slope x sine_wave frequency 0.5 //function {NormalX (x,y,z)} color_map { [0 rgb 0] [1 rgb <3, 0, 0>] } } //---------------------------------- #declare P_Green = pigment { slope y sine_wave frequency 0.5 //function {NormalY (x,y,z)} color_map { [0 rgb 0] [1 rgb <0, 3, 0>] } } //---------------------------------- #declare P_Blue = pigment { slope z sine_wave frequency 0.5 //function {NormalZ (x,y,z)} color_map { [0 rgb 0] [1 rgb <0, 0, 3>] } } //---------------------------------- #declare ColorByNormal = texture{ pigment { average pigment_map { [1 P_Red] [1 P_Green] [1 P_Blue] } } //finish {ambient 1 emission 0} } //---------------------------------- #declare Gradient = 21; #declare Min_factor= 0.7; isosurface { function {0.1 - ObjectFunction(x,y,z)} //open threshold 0 max_gradient Gradient evaluate Gradient*Min_factor, sqrt(Gradient/(Gradient*Min_factor)), min (0.7, 1.0) accuracy 0.01 //accuracy 0.0001 contained_by {box {<-1, -1, -1>*1, <1, 1, 1>*1}} //texture {pigment {rgb 0.2}} interior_texture {pigment {rgb <1, 0, 0>} finish {specular 0.4}} texture {ColorByNormal} }