glm::vec3 DirectLightingIntegrator::EstimateDirectLighting(const Intersection &isx, unsigned int &n_light, unsigned int &n_brdf, const glm::vec3 &woW) { //for Light source sampling //QList<glm::vec3> light_sample_pts; glm::vec3 brdf_sampling_final(0,0,0); glm::vec3 light_sampling_final(0,0,0); glm::vec3 color_final(0,0,0); Intersection light_sample_isx; //randomly sampled intersection on the light source's surface glm::vec3 wiW; // incoming ray in world frame Ray light_sample_ray; float rand1 = unif_distribution(mersenne_generator); float rand2 = unif_distribution(mersenne_generator); int light_choice = 0; Intersection obstruction_test; //for all light sources //for (int i = 0; i < scene->lights.count(); i++) //{ //light source sampling for(unsigned int j = 0; j < n_light; j++) { light_choice = rand()%scene->lights.count(); light_sample_isx = scene->lights[light_choice]->GetRandISX(rand1, rand2, isx.normal); //take 1 sample point(intersection) on the light source for now wiW = light_sample_isx.point - isx.point; //ray direction going from world point to light source light_sample_isx.t = glm::length(wiW); wiW = glm::normalize(wiW); light_sample_ray = Ray(isx.point, wiW);//remember, the direction is from point in scene to light source obstruction_test = intersection_engine->GetIntersection(light_sample_ray); //update random point rand1 = unif_distribution(mersenne_generator); rand2 = unif_distribution(mersenne_generator); if (obstruction_test.object_hit == scene->lights[light_choice]) { light_sampling_final = light_sampling_final + LightPDFEnergy(obstruction_test, isx, light_sample_ray, woW, n_light, n_brdf); } else { //the ray contributes zero energy } } light_sampling_final = light_sampling_final/static_cast<float>(n_light); //divide by samples taken //light_sampling_final = light_sampling_final + light_sampling_temp; // accumulate energy per high source //light_sampling_temp = glm::vec3(0, 0, 0);// zero out color_temp for the next light source //} //brdf sampling for(unsigned int j = 0; j < n_brdf; j++) { brdf_sampling_final = brdf_sampling_final + BxDFPDFEnergy(isx, woW, n_light, n_brdf); } brdf_sampling_final = brdf_sampling_final/static_cast<float>(n_brdf); color_final = brdf_sampling_final + light_sampling_final; return color_final; }
void tup_show_message(const char *s) { const char *tup = " tup "; clear_progress(); color_set(stdout); /* If we get to the end, show a green bar instead of grey. */ if(cur_phase == 5) printf("[%s%s%s] ", color_final(), tup, color_end()); else printf("[%s%.*s%s%.*s] ", color_reverse(), cur_phase, tup, color_end(), 5-cur_phase, tup+cur_phase); timespan_end(&main_ts); if(display_job_time) printf("[%.3fs] ", timespan_seconds(&main_ts)); printf("%s", s); }
glm::vec3 Integrator::EstimateDirectLighting(const Intersection &isx, unsigned int &samples_taken, const glm::vec3 &woW) { //for Light source sampling //QList<glm::vec3> light_sample_pts; glm::vec3 color_temp(0,0,0); glm::vec3 color_final(0,0,0); Intersection light_sample_isx; //randomly sampled intersection on the light source's surface glm::vec3 wiW; // incoming ray in world frame Ray light_sample_ray; float rand1 = unif_distribution(mersenne_generator); float rand2 = unif_distribution(mersenne_generator); Intersection obstruction_test; //iterate through all the light sources for (int i = 0; i < scene->lights.count(); i++) { for(unsigned int j = 0; j < samples_taken; j++) { light_sample_isx = scene->lights[i]->GetRandISX(rand1, rand2, isx.normal); //take 1 sample point(intersection) on the light source for now wiW = light_sample_isx.point - isx.point; //ray direction going from world point to light source light_sample_isx.t = glm::length(wiW); wiW = glm::normalize(wiW); light_sample_ray = Ray(isx.point, wiW);//remember, the direction is from point in scene to light source obstruction_test = intersection_engine->GetIntersection(light_sample_ray); //update random point rand1 = unif_distribution(mersenne_generator); rand2 = unif_distribution(mersenne_generator); if (obstruction_test.object_hit == scene->lights[i]) { color_temp = color_temp + CalculateEnergy(light_sample_isx, isx, light_sample_ray, woW); } else { //the ray contributes zero energy } } color_temp = color_temp/static_cast<float>(samples_taken); //divide by samples taken color_final = color_final + color_temp; // accumulate energy per high source color_temp = glm::vec3(0, 0, 0);// zero out color_temp for the next light source } return color_final; }