void Radiosity::Reset() { delete [] area; delete [] undistributed; delete [] absorbed; delete [] radiance; // create and fill the data structures num_faces = mesh->numFaces(); area = new float[num_faces]; undistributed = new glm::vec3[num_faces]; absorbed = new glm::vec3[num_faces]; radiance = new glm::vec3[num_faces]; for (int i = 0; i < num_faces; i++) { Face *f = mesh->getFace(i); f->setRadiosityPatchIndex(i); setArea(i,f->getArea()); glm::vec3 emit = f->getMaterial()->getEmittedColor(); setUndistributed(i,emit); setAbsorbed(i,glm::vec3(0,0,0)); setRadiance(i,emit); } // find the patch with the most undistributed energy findMaxUndistributed(); }
double Radiosity::Iterate() { if (formfactors == NULL) ComputeFormFactors(); assert (formfactors != NULL); // ========================================== // ASSIGNMENT: IMPLEMENT RADIOSITY ALGORITHM // ========================================== for (int i = 0; i < num_faces; ++i) { Face *f1 = mesh->getFace(i); Material *m = f1->getMaterial(); Vec3f p_i = m->getDiffuseColor(); int j = max_undistributed_patch; if (i == j) { continue; } Vec3f ff = formfactors[i * num_faces + j] * getUndistributed(j); setRadiance(i, getRadiance(i) + ff * p_i); setUndistributed(i, getUndistributed(i) + ff * p_i); setAbsorbed(i, getAbsorbed(i) + (Vec3f(1,1,1)-p_i) * ff); } setUndistributed(max_undistributed_patch, Vec3f(0,0,0)); // return the total light yet undistributed // (so we can decide when the solution has sufficiently converged) findMaxUndistributed(); return total_undistributed; }
float Radiosity::Iterate() { if (formfactors == NULL) ComputeFormFactors(); assert (formfactors != NULL); // ========================================== // ASSIGNMENT: IMPLEMENT RADIOSITY ALGORITHM // ========================================== //Compute the radiosity matrix. I feel like I shouldn't have to do this //every time. Maybe this is what the form factors matrix was meant for //save the radiances std::vector<glm::vec3> radiations, absorbeds; for (int i=0; i<num_faces; i++){ Face* face=mesh->getFace(i); glm::vec3 ro_i=face->getMaterial()->getDiffuseColor(); glm::vec3 ones(1,1,1); glm::vec3 abso_i=ones-ro_i; glm::vec3 radiance=face->getMaterial()->getEmittedColor(); glm::vec3 absorbed_i(0,0,0);//=getAbsorbed(i); for (int j=0; j<num_faces; j++){ //new_row.push_back(-ro_i*getFormFactor(i,j)) //might need to reverse that j,i radiance+=ro_i*getFormFactor(j,i)*getRadiance(j); absorbed_i+=abso_i*getFormFactor(j,i)*getRadiance(j); } //the undistributed light is the stuff we got on this iteration setUndistributed(i, radiance-getRadiance(i)); //std::cout<<glm::length(radiance)<<' '; radiations.push_back(radiance); absorbeds.push_back(absorbed_i); } //std::cout<<std::endl; //set the computed radiances for(int i=0; i<num_faces; i++){ setRadiance(i, radiations[i]); setAbsorbed(i, absorbeds[i]); } //now we must calculate the undistributed light float total_undistributed = 0; glm::vec3 ambient; for (int i=0; i<num_faces;i++){ total_undistributed+=glm::length(getUndistributed(i)); ambient+=getUndistributed(i); } //uncomment this for the ambient lighting term. This implementation, while simple //breaks my visualization for undistributed #if 1 ambient/=float(num_faces); for (int i=0; i<num_faces; i++){ setRadiance(i, getRadiance(i)+ambient); } #endif // return the total light yet undistributed // (so we can decide when the solution has sufficiently converged) std::cout<<total_undistributed<<std::endl; return total_undistributed; }
float Radiosity::Iterate() { if (formfactors == NULL) ComputeFormFactors(); assert (formfactors != NULL); // ========================================== // ASSIGNMENT: IMPLEMENT RADIOSITY ALGORITHM // ========================================== //printf("\n\n"); //take the thing with the most undistributed radiosity findMaxUndistributed(); float totalUnd = 0; for(int j = 0; j<num_faces; j++) { if (j == max_undistributed_patch) { continue; } //use max_undistributed_patch for the thing giving away radience //the j panel absorbs some of the light and reflects the rest /*printf("MaxUndist: (%f %f %f)\tJDiffuseColor: (%f %f %f)\tAbsorbed: (%f %f %f)\tRadiance: (%f %f %f)\tUndistributed: (%f %f %f)\t\n\n", getUndistributed(max_undistributed_patch).x, getUndistributed(max_undistributed_patch).y, getUndistributed(max_undistributed_patch).z, mesh->getFace(j)->getMaterial()->getDiffuseColor().x, mesh->getFace(j)->getMaterial()->getDiffuseColor().y, mesh->getFace(j)->getMaterial()->getDiffuseColor().z, getAbsorbed(j).x, getAbsorbed(j).y, getAbsorbed(j).z, getRadiance(j).x, getRadiance(j).y, getRadiance(j).x, getUndistributed(j).x, getUndistributed(j).y, getUndistributed(j).z);//*/ //give it to everyone else based on form factor setRadiance(j, getUndistributed(max_undistributed_patch)*(getFormFactor(max_undistributed_patch, j)/ totalFormFactori[max_undistributed_patch])*mesh->getFace(j)->getMaterial()->getDiffuseColor() +//- getAbsorbed(j) + *******INSTEAD OF GET ABSORBED THIS SHOULD BE PANEL COLOR) getRadiance(j));//*/ setAbsorbed(j, (getUndistributed(max_undistributed_patch)*(1.0f-mesh->getFace(j)->getMaterial()->getDiffuseColor()))* (getFormFactor(max_undistributed_patch, j)/totalFormFactori[max_undistributed_patch]) + (getAbsorbed(j)));//*/ setUndistributed(j, getUndistributed(max_undistributed_patch)*(getFormFactor(max_undistributed_patch, j)/ totalFormFactori[max_undistributed_patch])*mesh->getFace(j)->getMaterial()->getDiffuseColor() + getUndistributed(j));//*/ totalUnd += glm::length(getUndistributed(j)); /*printf("MaxUndist: (%f %f %f)\tJDiffuseColor: (%f %f %f)\tAbsorbed: (%f %f %f)\tRadiance: (%f %f %f)\tUndistributed: (%f %f %f)\t\n", getUndistributed(max_undistributed_patch).x, getUndistributed(max_undistributed_patch).y, getUndistributed(max_undistributed_patch).z, mesh->getFace(j)->getMaterial()->getDiffuseColor().x, mesh->getFace(j)->getMaterial()->getDiffuseColor().y, mesh->getFace(j)->getMaterial()->getDiffuseColor().z, getAbsorbed(j).x, getAbsorbed(j).y, getAbsorbed(j).z, getRadiance(j).x, getRadiance(j).y, getRadiance(j).x, getUndistributed(j).x, getUndistributed(j).y, getUndistributed(j).z); printf("***************************************************************************************\n");//*/ } //setRadiance(max_undistributed_patch, glm::vec3(0,0,0)); setUndistributed(max_undistributed_patch, glm::vec3(0, 0, 0)); //============================================== // return the total light yet undistributed //============================================== // (so we can decide when the solution has sufficiently converged) //printf("TotalUndistributed: %f", totalUnd); return totalUnd; }