Skip to content

Commit

Permalink
Update hierarchical integrator to consider both indirect and direct l…
Browse files Browse the repository at this point in the history
…ighting at sample points.
  • Loading branch information
tatsy committed Mar 21, 2016
1 parent b7930be commit c66c084
Show file tree
Hide file tree
Showing 6 changed files with 261 additions and 247 deletions.
4 changes: 2 additions & 2 deletions example/pathtracing_example.cc
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ int main(int argc, char **argv) {
//VolPathIntegrator integr(camera, sampler);
//PathIntegrator integr(camera, sampler);

IrradCacheIntegrator integr(camera, sampler);
//HierarchicalIntegrator integr(camera, sampler);
//IrradCacheIntegrator integr(camera, sampler);
HierarchicalIntegrator integr(camera, sampler);
//PPMProbIntegrator integr(camera, sampler);
integr.render(scene, params);

Expand Down
2 changes: 1 addition & 1 deletion sources/bxdf/bssrdf.cc
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ double DiffusionReflectance::Ft(const Vector3d& w) const {
double DiffusionReflectance::Fdr() const {
if (eta_ >= 1.0) {
return -1.4399 / (eta_ * eta_) + 0.7099 / eta_ + 0.6681 +
0.0636f * eta_;
0.0636 * eta_;
} else {
return -0.4399f + 0.7099 / eta_ - 0.3319 / (eta_ * eta_) +
0.0636 / (eta_ * eta_ * eta_);
Expand Down
81 changes: 81 additions & 0 deletions sources/core/sampling.cc
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,87 @@ void sampleUniformHemisphere(const Normal3d& normal, Vector3d* direction, const
*direction = (u * cos(t) * z2s + v * sin(t) * z2s + w * sqrt(1.0 - z2)).normalized();
}

void samplePoissonDisk(const Scene& scene, const Point3d& pCamera,
double minDist, std::vector<Interaction>* points) {
std::vector<Triangle> tris;
for (const auto& p : scene.primitives()) {
if (p->material()->isSubsurface()) {
auto ts = p->triangulate();
tris.insert(tris.end(), ts.begin(), ts.end());
}
}

// Initialize utility variables in this method
const auto seed = static_cast<unsigned int>(time(0));
Random rng(seed);

// Sample random points on trimesh
Bounds3d bounds;
std::vector<Point3d> candPoints;
std::vector<Normal3d> candNormals;
for (int i = 0; i < tris.size(); i++) {
const Triangle& tri = tris[i];
const double A = tri.area();
const int nSample = static_cast<int>(std::ceil(4.0 * A / (minDist * minDist)));
for (int k = 0; k < nSample; k++) {
double u = rng.nextReal();
double v = rng.nextReal();
if (u + v >= 1.0) {
u = 1.0 - u;
v = 1.0 - v;
}
Point3d p = (1.0 - u - v) * tri[0] + u * tri[1] + v * tri[2];
Normal3d n = (1.0 - u -v) * tri.normal(0) + u * tri.normal(1) +
v * tri.normal(2);
candPoints.push_back(p);
candNormals.push_back(n);
bounds.merge(p);
}
}

// Create hash grid
const int numCands = static_cast<int>(candPoints.size());
Vector3d bsize = bounds.posMax() - bounds.posMin();
const double scale = 1.0 / (2.0 * minDist);
const int numPoints = candPoints.size();
HashGrid<int> hashgrid;
hashgrid.init(numPoints, scale, bounds);

RandomQueue<int> que;
for (int i = 0; i < numCands; i++) {
que.push(i);
}

std::vector<int> sampledIDs;
Vector3d margin(2.0 * minDist, 2.0 * minDist, 2.0 * minDist);
while (!que.empty()) {
int id = que.pop();
Point3d v = candPoints[id];
const std::vector<int>& cellvs = hashgrid[v];

bool accept = true;
for (int k = 0; k < cellvs.size(); k++) {
if ((candPoints[cellvs[k]] - v).squaredNorm() < minDist * minDist) {
accept = false;
break;
}
}

if (accept) {
Point3d boxMin = v - margin;
Point3d boxMax = v + margin;
hashgrid.add(id, boxMin, boxMax);
sampledIDs.push_back(id);
}
}

// Store sampled points
std::vector<int>::iterator it;
for (auto i : sampledIDs) {
points->emplace_back(candPoints[i], candNormals[i]);
}
}

void samplePoissonDisk(const Scene& scene, const Point3d& pCamera,
double minDist, std::vector<SurfaceInteraction>* points) {
// Initialize utility variables in this method
Expand Down
4 changes: 4 additions & 0 deletions sources/core/sampling.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ SPICA_EXPORTS Vector3d sampleCosineHemisphere(const Point2d& rands);
SPICA_EXPORTS inline double cosineHemispherePdf(double cosTheta) { return cosTheta * INV_PI; }
SPICA_EXPORTS void sampleUniformHemisphere(const Normal3d& normal, Vector3d* direction, const Point2d& rands);

SPICA_EXPORTS
void samplePoissonDisk(const Scene& scene, const Point3d& pCamera,
double minDist, std::vector<Interaction>* points);

SPICA_EXPORTS
void samplePoissonDisk(const Scene& scene, const Point3d& pCamera,
double minDist, std::vector<SurfaceInteraction>* points);
Expand Down
Loading

0 comments on commit c66c084

Please sign in to comment.