void PhotonMap::send_photons() { printf("Each photon used %ld bytes\n",sizeof(Photon)); std::vector<std::vector<Photon> > raw_photons(MAX_THREADS); #pragma omp parallel for for(unsigned int j=0; j<MAX_THREADS; j++) { raw_photons[j].reserve(scene->num_lights()*PHOTON_COUNT*(MAX_PHOTON_DEPTH+1)); for(unsigned int i=0; i<scene->num_lights(); i++) { SphereLight light = scene->get_lights()[i]; Color3 c=light.color; real_t prob=montecarlo(c); unsigned int photonCount=PHOTON_COUNT*prob/MAX_THREADS; printf("Sending %d photons.\n",photonCount); for(unsigned int k=0; k<photonCount; k++) { Ray ray; ray.d = random_sphere_indexed(k,photonCount); ray.e = light.position+random_sphere()*light.radius; trace_photon(raw_photons[j],c,ray,MAX_PHOTON_DEPTH); } } } std::vector<size_t> offsets(raw_photons.size()); size_t total=0; for(size_t i=0; i<raw_photons.size(); i++) { offsets[i]=total; total+=raw_photons[i].size(); raw_photons[i].shrink_to_fit(); } printf("Made %ld photons\n",total); delete all_raw_photons; all_raw_photons = new std::vector<Photon>(total); for(size_t i=0; i<raw_photons.size(); i++) { std::vector<Photon>::iterator dest=all_raw_photons->begin()+offsets[i]; while(raw_photons[i].size()>0) { assert(dest<all_raw_photons->end()); //rough attempt at page-aligning during copy size_t copySize=1024*1024; size_t extra=raw_photons[i].size()%copySize; if(extra!=0) { copySize=extra; } shift_buffer(&(raw_photons[i]),dest,copySize); } } printf("Collected %ld photons\n",all_raw_photons->size()); //TODO: organize the photons into some sort of kd-tree }
//------------------------------------------------------------------------------------------- // メインエントリーポイントです. //------------------------------------------------------------------------------------------- int main(int argc, char **argv) { auto w = 1280; // 画像の横幅. auto h = 1080; // 画像の縦幅. auto s = 10000; // s * 1000 photon paths will be traced auto c = new Vector3[ w * h ]; hpbbox.reset(); trace_ray( w, h ); trace_photon( s ); density_estimation( c, s ); save_to_bmp( "image.bmp", w, h, &c[0].x, 2.2 ); delete [] c; c = nullptr; return 0; }