// Can't remember where I found this algorithm ... // converts to // hue : 0 = red, .333 = green, .667 = blue, 1 = red // sat : 0 = gray, 1 = full colour // val : 0 = black, 1 = full brightness #macro hsv2rgb ( vec ) #local H = mod(vec.x*6, 6); #local P = floor(H); #local S = H - P; #local A = (1 - vec.y)*vec.z; #local B = (1 - (S*vec.y))*vec.z; #local C = (1 - ((1-S)*vec.y))*vec.z; #switch (P) #case (0) #declare R2H_vec = ; #break #case (1) #declare R2H_vec = ; #break #case (2) #declare R2H_vec = ; #break #case (3) #declare R2H_vec = ; #break #case (4) #declare R2H_vec = ; #break #case (5) #declare R2H_vec = ; #break #end R2H_vec #end // Adapted from Giles Trans' Maketree.pov //========================================= // macro mAlign //----------------------------------------- // returns a matrix operation that aligns an object or texture along P2-P1 // the object is translated to P1 // translate to P2-P1 if you want the object to be on P2 #macro mAlign(P1,P2) #local yV1=vnormalize(P2-P1); #local xV1=vnormalize(vcross(yV1,z)); #local zV1=vcross(xV1,yV1); matrix #end //----------------------------------------- // end of mAlign macro //========================================= #declare phd = 4; #declare CD = true; // chromatic dispersion? global_settings { assumed_gamma 1.0 max_trace_level 20 photons { gather 30, 200 radius .05*phd, 2, .1*phd jitter .2 autostop 0 } } // Build colour spectrum array - r,g and b each total 1 #declare maxC = 19; #declare tCol = 0*x; #declare cA = array [maxC] #declare Count = 1; #while (Count < maxC) #declare cA[Count] = x; #declare cA[Count] = hsv2rgb(<0.85*(Count/maxC)+0.9, 1, 1>); #declare cA[Count] = cA[Count]*cA[Count]; #declare cA[Count] = vnormalize(cA[Count]) * (sin(pi*Count/maxC)); #declare tCol = tCol + cA[Count]; #declare Count = Count + 1; #end #declare Count = 1; #while (Count < maxC) #declare cA[Count] = cA[Count] / tCol; #declare Count = Count + 1; #end // Photon spotlight definition #declare SpotLight = union { light_source { 0*x colour rgb 1.0 colour_map { #declare Count = 1; #while (Count < maxC) [1 rgb cA[Count]*0.5 ] #declare Count = Count + 1; #end } photons{ reflection on refraction on } } difference { sphere { 0, 1.1 } sphere { 0, 1 } plane { y, -0.8 } pigment { rgb 1 } finish { ambient 0 diffuse 1 reflection 0.1 } photons { ignore_photons } } // Lens curvature radius calc from Fresnel lens macro #declare IOR = 2.3; #declare F = 1.0; #declare R = sqrt(1-0.8*0.8); #declare C = max(R, (IOR-1)*F); #declare O = sqrt(C*C-R*R); // #debug concat("Lens radius = ", str(R, 0, 3), "\n") // #debug concat("Lens curvature = ", str(C, 0, 3), "\n") // #debug concat("Lens offset = ", str(O, 0, 3), "\n") intersection { sphere { 0, 1 scale C translate O*y photons { ignore_photons } } plane { y, 0 } photons { density .01*phd reflection off refraction on ignore_photons } pigment { rgbf 1 } // normal { spotted 0.02 scale 0.0001 } finish { ambient 0 diffuse 0 reflection 0 } interior { ior IOR dispersion 1.05 } bounded_by { sphere { 0, R } } translate -0.8*y } rotate 180*x } background { color rgb <0.2,0.4,0.6> } #declare camPos = <-5, 20, -30>; #declare camLookAt = <0,-10,0>; #declare camAngle = 90; camera { up <0, 3/4, 0> right <1, 0, 0> location camPos direction <0.0, 0.0, 1> angle camAngle look_at camLookAt } // photon spotlight object { SpotLight mAlign(<25,70,-10>, <0,0,0>) } plane { y, -10 pigment { rgb 1 } finish { ambient .025 diffuse .33 reflection 0.05 } } // faceted crystal ... intersection { #declare maxC = 5; #declare C1 = 0; #while (C1 < maxC) #declare C2 = 0; #while (C2 < C1*maxC) plane { y, 5 rotate <90*(C1+0.5)/maxC, 360*(C2+0.5)/(C1*maxC), 0> } plane { -y, 5 rotate <90*(C1+0.5)/maxC, 360*(C2+0.5)/(C1*maxC), 0> } #declare C2 = C2 + 1; #end #declare C1 = C1 + 1; #end pigment { rgbf 0.95 } finish { ambient .05 diffuse .1 reflection .05 } interior { ior 2.47 dispersion 1.05 } hollow photons { ignore_photons } bounded_by { sphere { 0, 7 } } }