#include "transforms.inc" #declare signpow = function(x,p) { pow(abs(x),p-1)*x } #declare invpow = function(x,p) { select(x,-1+pow(1-abs(x),p),1-pow(1-abs(x),p)) } #macro do_lights() //takes a while so invoke at the end of the scene (so we get parse errors for other stuff first!) //make lights #local num_lights = 110; #local num_lights_used = 0; #local skip_light_threshold = 0.3; #local dirs = array[num_lights]; #local cols = array[num_lights]; #local skipped_light_cumul = color rgb <0,0,0>; #local light_distance = 1000; #local area_ang = 15; //degrees, set to 0 to use non-area lights, adjust according to numlights (30degrees good for 20 lights) #local blursamp = 20; //blur each light's source colour, so we don't sample just one pixel of the image. #local blurang = 15; //degrees #local f_samp = function { pigment { dome } }; #local rs = seed(14); #local rs2 = seed(32); #local i = 0; #while (i < num_lights) #local j=(i+.5)/num_lights; #local dir = vrotate(vrotate(z,),<0,0,0>); //#local dir = vrotate(z,); //average together several samples in the region #local col=<0,0,0>; #local s=0; #while ( s < blursamp ) #local dir2 = vrotate(z,); #local trans = transform { Reorient_Trans(z,dir) }; #local dir2 = vtransform(dir2, trans); #local samp = f_samp(dir2.x,dir2.y,dir2.z); #local s=s+1; #local col = col*(s-1)/s + samp/s; #end #if (0.3*col.red + 0.59*col.green + 0.11*col.blue > skip_light_threshold) #local dirs[num_lights_used] = dir; #local cols[num_lights_used] = col; #local num_lights_used = num_lights_used + 1; #else #local skipped_col_cumul = skipped_col_cumul + col; #end #local i=i+1; #end #local skipped_light_compensation = skipped_light_cumul / num_lights_used; #local i = 0; #while (i < num_lights_used) light_source { dirs[i]*light_distance, (cols[i] + skipped_light_compensation)*4/num_lights #if (area_ang > 0) area_light x*light_distance*tan(radians(area_ang)), y*light_distance*tan(radians(area_ang)), 4,4 adaptive 1 jitter circular orient #end } #local i=i+1; #end #warning concat("Skipped ", str(num_lights-num_lights_used,0,0), "/", str(num_lights,0,0), " light sources") #end