#include "dxstdafx.h" #include ".\hdrisampler.h" #include "Vector.hpp" #include "color.h" #include "resolu.h" #define M_PI 3.14159265358979323846 #define M_PI_2 1.57079632679489661923 #define M_PI_4 0.785398163397448309616 HdriSampler::HdriSampler(void) { h2.SetBase(2); h3.SetBase(3); h5.SetBase(5); hdriMap = NULL; } HdriSampler::~HdriSampler(void) { } Vector HdriSampler::getRadianceAt(const Vector& dir) const { bool edge = false; float xval, yval; int upper, left; float fx, fy, fz; fx = fabsf(dir.x); fy = fabsf(dir.y); fz = fabsf(dir.z); if(dir.z > 0.0 && fz >= fy && fz >= fx) { upper = resolutiony / 4; left = resolutionx / 3; xval = dir.x / dir.z; yval = dir.y / dir.z; } else if(dir.z < 0.0 && fz >= fy && fz >= fx) { upper = 3 * resolutiony / 4; left = resolutionx / 3; xval = - dir.x / dir.z; yval = dir.y / dir.z; } else if(dir.x > 0.0 && fx >= fy && fx >= fz) { upper = resolutiony / 4; left = 2 * resolutionx / 3; xval = - dir.z / dir.x; yval = dir.y / dir.x; } else if(dir.x < 0.0 && fx >= fy && fx >= fz) { upper = resolutiony / 4; left = 0; xval = - dir.z / dir.x; yval = - dir.y / dir.x; } else if(dir.y > 0.0 && fy >= fx && fy >= fz) { upper = 0; left = resolutionx / 3; xval = dir.x / dir.y; yval = - dir.z / dir.y; } else if(dir.y < 0.0 && fy >= fx && fy >= fz) { upper = resolutiony / 2; left = resolutionx / 3; xval = - dir.x / dir.y; yval = - dir.z / dir.y; } else edge = true; if(!edge) { upper += ((-yval + 1.0f) * resolutiony) / 8.0; left += ((xval + 1.0f) * resolutionx) / 6.0; return hdriMap[left + upper * resolutionx]; } else return Vector::RGBBLACK; } double HdriSampler::getImportance(const Vector& px) { // return 1.0; Vector rad = getRadianceAt(px); return rad.sum(); } // HdriSampler commands void HdriSampler::findMaxImportance() { maxImportance = 0.0; for(int k=0; k maxImportance) maxImportance = c; } } void HdriSampler::calculatePowers() { powers.clear(); calculateRadii(); for(int i=0; i= 4); for(int i=0; i::iterator a = voro.tris.begin(); std::vector::iterator end = voro.tris.end(); while(a != end) { Vector la = (voro.dirs[a->bi] - voro.dirs[a->ai]); Vector lb = (voro.dirs[a->ci] - voro.dirs[a->ai]); double lcos = la * lb; if(lcos >= 1.0) lcos = 1.0; double triArea = sqrt(la.norm2() * la.norm2() * (1.0 - lcos * lcos)) / 4.0; voronoiRadii[a->ai] += triArea; voronoiRadii[a->bi] += triArea; voronoiRadii[a->ci] += triArea; a++; } float xx; for(int g=0; g < samplePoints.size(); g++) { xx = sqrt(voronoiRadii[g] / 3.14); voronoiRadii[g] = xx; } return; }