// for interpolation void CollectFacesWithVertex(Vertex *have, Face *f, std::vector<Face*> &faces) { for (unsigned int i = 0; i < faces.size(); i++) { if (faces[i] == f) return; } if (have != (*f)[0] && have != (*f)[1] && have != (*f)[2] && have != (*f)[3]) return; faces.push_back(f); for (int i = 0; i < 4; i++) { Edge *ea = f->getEdge()->getOpposite(); Edge *eb = f->getEdge()->getNext()->getOpposite(); Edge *ec = f->getEdge()->getNext()->getNext()->getOpposite(); Edge *ed = f->getEdge()->getNext()->getNext()->getNext()->getOpposite(); if (ea != NULL) CollectFacesWithVertex(have,ea->getFace(),faces); if (eb != NULL) CollectFacesWithVertex(have,eb->getFace(),faces); if (ec != NULL) CollectFacesWithVertex(have,ec->getFace(),faces); if (ed != NULL) CollectFacesWithVertex(have,ed->getFace(),faces); } }
void Radiosity::insertInterpolatedColor(int index, Face *f, Vertex *v) { std::vector<Face*> faces; CollectFacesWithVertex(v,f,faces); double total = 0; Vec3f color = Vec3f(0,0,0); Vec3f normal = f->computeNormal(); for (unsigned int i = 0; i < faces.size(); i++) { Vec3f normal2 = faces[i]->computeNormal(); double area = faces[i]->getArea(); if (normal.Dot3(normal2) < 0.5) continue; assert (area > 0); total += area; color += area * whichVisualization(RENDER_RADIANCE,faces[i],faces[i]->getRadiosityPatchIndex()); } assert (total > 0); color /= total; insertColor(color); }
// different visualization modes glm::vec3 Radiosity::setupHelperForColor(Face *f, int i, int j) { assert (mesh->getFace(i) == f); assert (j >= 0 && j < 4); if (args->render_mode == RENDER_MATERIALS) { return f->getMaterial()->getDiffuseColor(); } else if (args->render_mode == RENDER_RADIANCE && args->interpolate == true) { std::vector<Face*> faces; CollectFacesWithVertex((*f)[j],f,faces); float total = 0; glm::vec3 color = glm::vec3(0,0,0); glm::vec3 normal = f->computeNormal(); for (unsigned int i = 0; i < faces.size(); i++) { glm::vec3 normal2 = faces[i]->computeNormal(); float area = faces[i]->getArea(); if (glm::dot(normal,normal2) < 0.5) continue; assert (area > 0); total += area; color += float(area) * getRadiance(faces[i]->getRadiosityPatchIndex()); } assert (total > 0); color /= total; return color; } else if (args->render_mode == RENDER_LIGHTS) { return f->getMaterial()->getEmittedColor(); } else if (args->render_mode == RENDER_UNDISTRIBUTED) { return getUndistributed(i); } else if (args->render_mode == RENDER_ABSORBED) { return getAbsorbed(i); } else if (args->render_mode == RENDER_RADIANCE) { return getRadiance(i); } else if (args->render_mode == RENDER_FORM_FACTORS) { if (formfactors == NULL) ComputeFormFactors(); float scale = 0.2 * total_area/getArea(i); float factor = scale * getFormFactor(max_undistributed_patch,i); return glm::vec3(factor,factor,factor); } else { assert(0); } exit(0); }