//------------------------------------------------------------------------------ // Octree_test.pov // 01/12/2012 // Robert W. McGregor, rob@mcgregorfineart.com //------------------------------------------------------------------------------ // Command-line: +w1280 +h720 +a0.2 +r3 +kfi0 +kff9 //------------------------------------------------------------------------------ #version 3.7; #include "shapes.inc" #include "rand.inc" default { finish { ambient 0 specular 0 emission 0 diffuse 0.8 reflection 0 } pigment { rgb 0.5 } } background { rgb 0.25 } //------------------------------------------------------------------------------ // Scene/Render Configuration //------------------------------------------------------------------------------ #declare Soft_Shadows = 1; #declare Build_Voxels = 1; #declare MAX_DEPTH = frame_number+1; #declare R = seed(4); global_settings { assumed_gamma 1 radiosity {} } //------------------------------------------------------------------------------ // Camera & Lights //------------------------------------------------------------------------------ #declare Cam_Loc = -3.5*vnormalize(<-0.5, 0.5, 1>); camera { location Cam_Loc look_at <0, 0, 0> right x*image_width/image_height angle 60 } #declare Light_Pos = <100, 50, -100>; light_source { Light_Pos rgb 10 fade_power 3 fade_distance VDist(0, Light_Pos)/2 #if (Soft_Shadows) area_light <5, 0, 0>, <0, 0, 5>, 7, 7 adaptive 2 jitter orient circular #end } light_source { <-100, -50, 100> rgb 0.25 } //------------------------------------------------------------------------------ // Environment //------------------------------------------------------------------------------ #if (1=frame_number) sphere { 0, 100000 hollow inverse pigment { image_map { exr "ak-business-school" interpolate 3 map_type 1 }} finish { ambient 0.5 emission 0.5 diffuse 0 } no_image } #end sky_sphere { pigment { gradient -y color_map { [0 srgb 0.5] [1 srgb 0.035] } } } //------------------------------------------------------------------------------ // Octree test //------------------------------------------------------------------------------ #declare OUTSIDE = 0; #declare PARTIAL = 1; #declare INSIDE = 2; #declare _nDepth = 0; #declare _nBoxes = 0; #declare _nNullBoxes = 0; //------------------------------------------------------------------------------ // macro BuildDisplayVoxel() // check each box vertex for inside() //------------------------------------------------------------------------------ #macro GetBoxState(obj, bbox) #local bmin = min_extent(bbox); #local bmax = max_extent(bbox); #local n = 0; #if (inside(obj,)) #local n = n + 1; #end #if (inside(obj,)) #local n = n + 1; #end #if (inside(obj,)) #local n = n + 1; #end #if (inside(obj,)) #local n = n + 1; #end #if (inside(obj,)) #local n = n + 1; #end #if (inside(obj,)) #local n = n + 1; #end #if (inside(obj,)) #local n = n + 1; #end #if (inside(obj,)) #local n = n + 1; #end #switch (n) #case (0) #local state = OUTSIDE; #break #case (8) #local state = INSIDE; #break #else #local state = PARTIAL; #break #end state #end //------------------------------------------------------------------------------ // macro BuildDisplayVoxel() //------------------------------------------------------------------------------ #macro BuildDisplayVoxel(bbox) #local clr1 = srgb <225, 180, 105>/255; #local clr2 = srgb <105, 90, 30>/255; #local gry = srgb RRand(0.1,0.9,R); #local bmin = min_extent(bbox); #local bmax = max_extent(bbox); #local ctr = (bmin+bmax)/2; #local p = pigment{ bozo scale 0.15 turbulence 0.5 color_map { [0 color (clr1+gry)/2] [1 color (clr2+gry)/2] } } sphere { 0, 1 scale _rootScale texture { pigment { p } normal { agate 0.1 scale 0.2 turbulence 0.15 } finish { specular 0.2 roughness 0.02 reflection { 0,0.5 fresnel on } conserve_energy } translate RRand(0,1000,R) } scale vlength(ctr-bmax) translate ctr interior { ior 1.5 } } #declare _nBoxes=_nBoxes+1; #end //------------------------------------------------------------------------------ // macro SubdivideVoxel() //------------------------------------------------------------------------------ #macro SubdivideVoxel(root, bbParent) #if (_nNullBoxes>0) #if (mod(_nNullBoxes,5000)=0) #debug concat("SubdivideVoxel() -- Null Voxels: ", str(_nNullBoxes,0,0), ", Voxels: ", str(_nBoxes,0,0),"\n") #end #end #declare _nDepth = _nDepth + 1; #if (_nDepth <= MAX_DEPTH) // break into 8 sub-boxes #local aBox = array[8]; #local bmin = min_extent(bbParent); #local bmax = max_extent(bbParent); #local midX = (bmin.x+bmax.x)/2; #local midY = (bmin.y+bmax.y)/2; #local midZ = (bmin.z+bmax.z)/2; #local aBox[0] = box { , } #local aBox[1] = box { , } #local aBox[2] = box { , } #local aBox[3] = box { , } #local aBox[4] = box { , } #local aBox[5] = box { , } #local aBox[6] = box { , } #local aBox[7] = box { , } #local n = 0; #while (n < 8) #if (INSIDE=GetBoxState(root, aBox[n])) BuildDisplayVoxel(aBox[n]) #else #if (PARTIAL=GetBoxState(root, aBox[n])) SubdivideVoxel(root, aBox[n]) // need more granularity #else // may need more granularity #declare _nNullBoxes=_nNullBoxes+1; #local isect = intersection { object { root } object { aBox[n] } } #local bmin = min_extent(isect); #if (bmin.x > -10000000000) SubdivideVoxel(root, aBox[n]) #else #debug concat("Skipped null voxel ", str(_nNullBoxes, 0, 0), "\n") #end #end #end #local n = n + 1; #end #end #declare _nDepth=_nDepth-1; #end //------------------------------------------------------------------------------ // macro SubdivideVoxelMain() //------------------------------------------------------------------------------ #macro SubdivideVoxelMain(root, bbParent) #local aBox = array[8]; #local bmin = min_extent(bbParent); #local bmax = max_extent(bbParent); #local midX = (bmin.x+bmax.x)/2; #local midY = (bmin.y+bmax.y)/2; #local midZ = (bmin.z+bmax.z)/2; #local aBox[0] = box { , } #local aBox[1] = box { , } #local aBox[2] = box { , } #local aBox[3] = box { , } #local aBox[4] = box { , } #local aBox[5] = box { , } #local aBox[6] = box { , } #local aBox[7] = box { , } #local n = 0; #while (n < 8) #if (INSIDE=GetBoxState(root, aBox[n])) BuildDisplayVoxel(aBox[n]) #else #if (PARTIAL=GetBoxState(root, aBox[n])) SubdivideVoxel(root, aBox[n]) #else SubdivideVoxel(root, aBox[n]) #end #end #local n=n+1; #end #end //------------------------------------------------------------------------------ // create root //------------------------------------------------------------------------------ #declare rootObj = julia_fractal{ <-0.083,0.0,-0.83,-0.025> quaternion sqr max_iteration 8 precision 1024 } #declare bmin = min_extent(rootObj); #declare bmax = max_extent(rootObj); // make sure voxels are cubic #declare ctr = (bmin+bmax)/2; #declare bbRoot = box { vtransform(ctr, transform { translate -bmax }), vtransform(ctr, transform { translate bmax }) } #declare _rootScale = 1/vlength(ctr-bmax)*2; //------------------------------------------------------------------------------ // Build the voxel array //------------------------------------------------------------------------------ #if (Build_Voxels) union { SubdivideVoxelMain(rootObj, bbRoot) interior { ior 1.5 } } #end //------------------------------------------------------------------------------ // rootObj //------------------------------------------------------------------------------ object { rootObj texture { pigment{ bozo scale 0.15 turbulence 0.5 color_map { #switch (frame_number) #case (0) [0 srgb <225, 180, 105>/255 transmit 0] [1 srgb <105, 90, 30>/255 transmit 0] #break #case (1) [0 srgb <225, 180, 105>/255 transmit 0.65] [1 srgb <105, 90, 30>/255 transmit 0.65] #break #case (2) [0 srgb <225, 180, 105>/255 transmit 0.95] [1 srgb <105, 90, 30>/255 transmit 0.95] #break #case (3) #case (4) [0 srgb <225, 180, 105>/255 transmit 0.99] [1 srgb <105, 90, 30>/255 transmit 0.99] #break #else [0 rgbt 0.995][1 rgbt 0.995] #end } } normal { agate 0.1 scale 0.1 turbulence 0.15 } finish { #switch (frame_number) #case (0) specular 0.1 roughness 0.02 reflection {0,1 fresnel on} conserve_energy #break #case (1) specular 0.1 roughness 0.02 reflection {0,0.5 fresnel on} conserve_energy #break #case (2) specular 0.1 roughness 0.02 reflection {0,0.1 fresnel on} conserve_energy #break #case (3) specular 0.1 roughness 0.02 reflection {0,0.05 fresnel on} conserve_energy #break #case (4) specular 0.05 roughness 0.05 reflection {0,0.01 fresnel on} conserve_energy #break #else reflection 0 specular 0.01 #end } } #switch (frame_number) #case (0) interior { ior 1.5 } #break #case (1) interior { ior 1.05 } #break #case (2) #case (3) #case (4) interior { ior 1.01 } #break #else interior { ior 1 } #end } //------------------------------------------------------------------------------ // Text display //------------------------------------------------------------------------------ union { text { ttf "verdana.ttf", "Octree Space Partitioning", 0.025, 0 texture { pigment{ srgb 1 } finish { specular 0 emission 1 reflection 0 diffuse 0} } scale 0.085 rotate -y*25 rotate -z*1 translate <-3, 2.75, 0> } text { ttf "verdana.ttf", concat("Iteration ", str(frame_number+1,0,0), ", Sparse Voxels: ", str(_nBoxes,0,0)), 0.025, 0 texture { pigment{ srgb 1 } finish { specular 0 emission 1 reflection 0 diffuse 0 } } scale 0.085 rotate -y*25 rotate -z*1.5 translate <-2.975, 2.625, 0> } translate <-0.8, 0, 0> }