//+kfi0 +kff100 +orand1/rand //abstract random scene #version unofficial megapov 1.21; #include "rad_def.inc" #include "transforms.inc" //THE SEED: #declare the_seed = seed(frame_number+0); #macro connect_spheres( p0, r0, p1, r1, cin, cout ) //if spheres are far apart stick a cylinder in & 2 toroids, otherwise stick in 1 torus. #debug concat("connect_spheres(") #debug concat(" <",str(p0.x,0,2),",",str(p0.y,0,2),",",str(p0.z,0,2),">,") #debug concat(" ",str(r0,0,2),",") #debug concat(" <",str(p1.x,0,2),",",str(p1.y,0,2),",",str(p1.z,0,2),">,") #debug concat(" ",str(r1,0,2),",") #debug concat(" ",str(cin,0,2),",") #debug concat(" ",str(cout,0,2)," )\n") //debug: #if ( cout >= r0 ) #error "cout > r0\n" #end //you're trying to connect 2 spheres with a connector wider than the sphere. #if ( cout >= r1 ) #error "cout > r1\n" #end #if ( sqrt(pow(r0+cin,2)-pow(cout+cin,2)) + sqrt(pow(r1+cin,2)-pow(cout+cin,2)) < vlength( p1 - p0 ) ) #local pp0 = sqrt(pow(r0+cin,2)-pow(cout+cin,2))*vnormalize(p1-p0) + p0; #local pp1 = sqrt(pow(r1+cin,2)-pow(cout+cin,2))*vnormalize(p0-p1) + p1; difference { merge { cylinder { pp0*1.001-0.001*pp1, pp1*1.001-0.001*pp0, cout } //.001's remove coincedent faces cone { p0, 0, pp0, cout+cin } cone { p1, 0, pp1, cout+cin } } merge { torus { cout+cin, cin Reorient_Trans(y,p1-p0) translate pp0 } torus { cout+cin, cin Reorient_Trans(y,p0-p1) translate pp1 } } bounded_by { cone { p0+(pp0-p0)*r0/(r0+cin), (cout+cin)*r0/(r0+cin), p1+(pp1-p1)*r1/(r1+cin), (cout+cin)*r1/(r1+cin) } } } #else difference { #local dot = vdot(p1-p0,p1-p0); #local d = pow(r0+cin,2) - pow(r1+cin,2) + dot; #local i = p0 + (p1-p0) * d / (2*dot); #local q = sqrt(pow(r0+cin,2)-(d*d)/(4*dot)); merge { cone { p0, 0, i*1.001-0.001*p0, q } //.001's remove coincedent faces cone { p1, 0, i*1.001-0.001*p1, q } } torus { q, cin Reorient_Trans(y,p1-p0) translate i } //bound by shape covering just the connection region, since the other bits will be inside spheres bounded_by { cone { p0+(i-p0)*r0/(r0+cin), q*r0/(r0+cin), p1+(i-p1)*r1/(r1+cin), q*r1/(r1+cin) } } } #end #end camera { right x up y*image_height/image_width direction z*2.5 location -z*20 } #include "pprocess.inc" PP_Init_Alpha_Colors_Outputs() global_settings { max_trace_level 20 assumed_gamma 1 //not needed with so many lights radiosity { Rad_Settings(Radiosity_Fast,on,on) brightness 1 } photons { spacing 0.003 } #include "CIE.inc" } #default { pigment { RGB_CIE(1) } finish { ambient 0 diffuse 1 brilliance 2 } } #declare rs = rand(the_seed); sky_sphere { pigment { crackle solid scale .5+.6*rand(rs) translate 100*rand(rs) rotate poly_wave 1 colour_map { [.5 RGB_CIE(0)][1 RGB_CIE(2)] } } } #macro vpow(V,P) #end #macro col_temp(T) vpow(<1,.5,0>*pow(T,1)+pow((1-T),1)*<0,.5,1>,3) //sort of like a colour temp #end #local num_lights = 12; #local ii=num_lights; #while (ii > 0) light_source { -z*20, RGB_CIE( 2*col_temp(rand(rs))*pow(ii/num_lights,3) ) fade_power 2 fade_distance 20 //parallel point_at 0 area_light x*1,y*1,2,2 adaptive 1 jitter orient rotate #if ( ii > num_lights-2 ) photons { refraction on reflection on } #end } #local ii=ii-1; #end #declare plane_dir = vrotate(-y,<-rand(rs)*45,rand(rs)*45,0>); #declare furthest = 0; difference { #local num_spheres = 5;//12; #local pos = array[num_spheres]; #local rad = array[num_spheres]; //setup the shape #local ii=0; #while ( ii < num_spheres ) #local rad[ii] = (1-ii/num_spheres)*(rand(rs)*.5+.5); #if ( ii > 0 ) #local pos[ii] = pos[int((ii-1)/2)] + vrotate( z*(rad[int((ii-1)/2)]+rad[ii]+rand(rs)*.5), <90*(rand(rs)*2-1)*pow(rand(rs),1.5),360*rand(rs),0> ); #else #local pos[ii] = <0,0,0>; #end #declare furthest = max(furthest, vdot(plane_dir,pos[ii])+rad[ii]); #local ii=ii+1; #end merge { #local ii=0; #while ( ii < num_spheres ) sphere { pos[ii], rad[ii] } #if ( ii > 0 ) #local m = min(rad[int((ii-1)/2)],rad[ii]); #local cout = m*(rand(rs)*.5+.5); connect_spheres( pos[ii], rad[ii], pos[int((ii-1)/2)], rad[int((ii-1)/2)], cout, cout*rand(rs) ) #end #local ii=ii+1; #end } //bubbles inside merge { #local ii=0; #while ( ii < num_spheres ) sphere { pos[ii], (rad[ii]-.05)*pow(rand(rs),.5) } #local ii=ii+1; #end } #if ( rand(rs) > .7 ) pigment { RGB_CIE( ) } finish { diffuse .3 phong 1 phong_size 10 metallic .5 reflection { .7 metallic 1 } } normal { spotted scale .001 } //imperfection #else pigment { rgbt 1 } finish { diffuse 0 reflection { 0, .98 fresnel } conserve_energy phong 5 phong_size 2000 } interior { ior 1.4 fade_power 2 fade_colour RGB_CIE( ) fade_distance .03 } #end photons{ target 1.0 refraction on reflection on } } plane { -plane_dir, -furthest normal { spotted scale .01 } } #local wall=0; #while (wall < 5) plane { z, -30 rotate pigment { RGB_CIE( *.5+.5) } finish { diffuse 1 ambient pow(rand(rs),9) } } #local wall = wall+1; #end //scene test: //sphere { 0, 2.5 finish { diffuse 0 reflection 1 } }