Skip to content

Commit

Permalink
Revert PSSMLT.
Browse files Browse the repository at this point in the history
  • Loading branch information
tatsy committed Jul 14, 2018
1 parent 3f5e835 commit e104adf
Show file tree
Hide file tree
Showing 14 changed files with 147 additions and 149 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Common ignore files
build/*
testdata/tmp
tests/data/tmp
.cccc
test_params.h

Expand Down
32 changes: 8 additions & 24 deletions sources/core/integrator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ Integrator::~Integrator() {
void Integrator::render(const std::shared_ptr<const Camera> &camera,
const Scene &scene,
RenderParams &params) {
this->camera_ = camera;
}

// -----------------------------------------------------------------------------
Expand All @@ -44,31 +43,16 @@ SamplerIntegrator::SamplerIntegrator(const std::shared_ptr<Sampler>& sampler)
SamplerIntegrator::~SamplerIntegrator() {
}

void SamplerIntegrator::initialize(const Scene& scene,
RenderParams& parmas,
Sampler& sampler) {
}

void SamplerIntegrator::loopStarted(const Scene& scene,
RenderParams& parmas,
Sampler& sampler) {
}

void SamplerIntegrator::loopFinished(const Scene& scene,
RenderParams& parmas,
Sampler& sampler) {
}

void SamplerIntegrator::render(const std::shared_ptr<const Camera> &camera,
const Scene& scene,
RenderParams& params) {
// Initialization
Integrator::render(camera, scene, params);
auto initSampler = sampler_->clone((unsigned int)time(0));
initialize(scene, params, *initSampler);
initialize(camera, scene, params, *initSampler);

const int width = camera_->film()->resolution().x();
const int height = camera_->film()->resolution().y();
const int width = camera->film()->resolution().x();
const int height = camera->film()->resolution().y();

const int numThreads = numSystemThreads();
auto samplers = std::vector<std::unique_ptr<Sampler>>(numThreads);
Expand All @@ -79,7 +63,7 @@ void SamplerIntegrator::render(const std::shared_ptr<const Camera> &camera,
const int numSamples = params.getInt("sampleCount");
for (int i = 0; i < numSamples; i++) {
// Before loop computations
loopStarted(scene, params, *initSampler);
loopStarted(camera, scene, params, *initSampler);

// Prepare samplers
if (i % numThreads == 0) {
Expand All @@ -99,10 +83,10 @@ void SamplerIntegrator::render(const std::shared_ptr<const Camera> &camera,
const int x = pid % width;
const Point2d randFilm = sampler->get2D();
const Point2d randLens = sampler->get2D();
const Ray ray = camera_->spawnRay(Point2i(x, y), randFilm, randLens);
const Ray ray = camera->spawnRay(Point2i(x, y), randFilm, randLens);

const Point2i pixel(width - x - 1, y);
camera_->film()->addPixel(pixel, randFilm,
camera->film()->addPixel(pixel, randFilm,
Li(scene, params, ray, *sampler, arenas[threadID]));

proc++;
Expand All @@ -113,14 +97,14 @@ void SamplerIntegrator::render(const std::shared_ptr<const Camera> &camera,
});
printf("\n");

camera_->film()->save(i + 1);
camera->film()->save(i + 1);

for (int t = 0; t < numThreads; t++) {
arenas[t].reset();
}

// After loop computations
loopFinished(scene, params, *initSampler);
loopFinished(camera, scene, params, *initSampler);
}
printf("Finish!!\n");
}
Expand Down
18 changes: 9 additions & 9 deletions sources/core/integrator.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,6 @@ class SPICA_EXPORTS Integrator : public CObject, Uncopyable {
virtual void render(const std::shared_ptr<const Camera>& camera,
const Scene& scene,
RenderParams& params);

protected:
std::shared_ptr<const Camera> camera_;
};

/**
Expand All @@ -54,17 +51,20 @@ class SPICA_EXPORTS SamplerIntegrator : public Integrator {
const Scene& scene,
RenderParams& params) override;

virtual void initialize(const Scene& scene,
virtual void initialize(const std::shared_ptr<const Camera> &camera,
const Scene& scene,
RenderParams& params,
Sampler& sampler);
Sampler& sampler) {}

virtual void loopStarted(const Scene& scene,
virtual void loopStarted(const std::shared_ptr<const Camera> &camera,
const Scene& scene,
RenderParams& params,
Sampler& sampler);
Sampler& sampler) {}

virtual void loopFinished(const Scene& scene,
virtual void loopFinished(const std::shared_ptr<const Camera> &camera,
const Scene& scene,
RenderParams& params,
Sampler& sampler);
Sampler& sampler) {}

virtual Spectrum Li(const Scene& scene,
RenderParams& params,
Expand Down
3 changes: 2 additions & 1 deletion sources/integrators/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
macro(add_integrator)
add_spica_plugin(${ARGN} TYPE integrator)
add_spica_plugin(${ARGN} TYPE integrator)
endmacro()

add_integrator(path path/path.cc path/path.h)
add_integrator(bdpt bdpt/bdpt.cc bdpt/bdpt.h)
add_integrator(gdpt gdpt/gdpt.cc gdpt/gdpt.h gdpt/gdptfilm.cc gdpt/gdptfilm.h
LINK_LIBRARIES ${SPICA_DEPENDENCY_LIBRARIES})
add_integrator(pssmlt pssmlt/pssmlt.cc pssmlt/pssmlt.h)
add_integrator(sppm sppm/sppm.cc sppm/sppm.h)
add_integrator(directlighting directlighting/directlighting.cc directlighting/directlighting.h)
add_integrator(hierarchical hierarchical/hierarchical.cc hierarchical/hierarchical.h photon_map.cc photon_map.h)
35 changes: 20 additions & 15 deletions sources/integrators/bdpt/bdpt.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ enum class VertexType : int {
double densityIBL(const Scene& scene, const Distribution1D& lightDist,
const Vector3d& w) {
double pdf = 0.0;
for (int i = 0; i < scene.lights().size(); i++) {
const int nLights = (int)scene.lights().size();
for (int i = 0; i < nLights; i++) {
const auto& light = scene.lights()[i];
if (light->type() == LightType::Envmap) {
pdf += light->pdfLi(Interaction(), -w) * lightDist(i);
Expand Down Expand Up @@ -227,8 +228,7 @@ struct Vertex {
}

bool isLight() const {
return type == VertexType::Light ||
(type == VertexType::Surface && si()->primitive()->light()->isArea());
return type == VertexType::Light || (type == VertexType::Surface && si()->primitive()->light());
}

bool isDeltaLight() const {
Expand Down Expand Up @@ -329,7 +329,8 @@ struct Vertex {
: si()->primitive()->light();
Assertion(light != nullptr, "Light is nullptr");

for (int i = 0; i < scene.lights().size(); i++) {
const int nLights = static_cast<int>(scene.lights().size());
for (int i = 0; i < nLights; i++) {
if (scene.lights()[i].get() == light) {
pdfChoise = lightDist.pdfDiscrete(i);
break;
Expand Down Expand Up @@ -711,8 +712,8 @@ void BDPTIntegrator::render(const std::shared_ptr<const Camera>& camera,
const Scene& scene,
RenderParams& params) {
// Initialization
const int width = camera_->film()->resolution().x();
const int height = camera_->film()->resolution().y();
const int width = camera->film()->resolution().x();
const int height = camera->film()->resolution().y();

const int numThreads = numSystemThreads();
auto samplers = std::vector<std::unique_ptr<Sampler>>(numThreads);
Expand All @@ -736,16 +737,20 @@ void BDPTIntegrator::render(const std::shared_ptr<const Camera>& camera,
std::atomic<int> proc(0);
parallel_for(0, numPixels, [&](int pid) {
const int threadID = getThreadID();
const auto &sampler = samplers[threadID];
sampler->startPixel();

const int y = pid / width;
const int x = pid % width;
const Point2d randFilm = samplers[threadID]->get2D();
const Point2d randFilm = sampler->get2D();

auto cameraPath = std::make_unique<Vertex[]>(maxBounces + 2);
auto lightPath = std::make_unique<Vertex[]>(maxBounces + 1);
const int nCamera = calcCameraSubpath(scene, *samplers[threadID], arenas[threadID],
maxBounces + 2, *camera_, Point2i(x, y), randFilm,

const int nCamera = calcCameraSubpath(scene, *sampler, arenas[threadID],
maxBounces + 2, *camera, Point2i(x, y), randFilm,
cameraPath.get());
const int nLight = calcLightSubpath(scene, *samplers[threadID], arenas[threadID],
const int nLight = calcLightSubpath(scene, *sampler, arenas[threadID],
maxBounces + 1, lightDist, lightPath.get());

Spectrum L(0.0);
Expand All @@ -758,28 +763,28 @@ void BDPTIntegrator::render(const std::shared_ptr<const Camera>& camera,
double misWeight = 0.0;

Spectrum Lpath = connectBDPT(scene, lightPath.get(), cameraPath.get(),
lid, cid, lightDist, *camera_, *samplers[threadID],
lid, cid, lightDist, *camera, *sampler,
&pFilm, &misWeight);
if (cid == 1 && !Lpath.isBlack()) {
pFilm = Point2d(width - pFilm.x(), pFilm.y());
mtx.lock();
camera_->film()->addPixel(pFilm, Lpath);
camera->film()->addPixel(pFilm, Lpath);
mtx.unlock();
} else {
L += Lpath;
}
}
}
camera_->film()->addPixel(Point2i(width - x - 1, y), randFilm, L);
camera->film()->addPixel(Point2i(width - x - 1, y), randFilm, L);

proc++;
if (proc % 1000 == 0) {
printf("%6.2f %% processed...\r", 100.0 * proc / numPixels);
printf("\r[ %d / %d ] %6.2f %% processed...", i + 1, numSamples, 100.0 * proc / numPixels);
fflush(stdout);
}
});

camera_->film()->saveMLT(1.0 / (i + 1), i + 1);
camera->film()->saveMLT(1.0 / (i + 1), i + 1);

for (int t = 0; t < numThreads; t++) {
arenas[t].reset();
Expand Down
10 changes: 5 additions & 5 deletions sources/integrators/gdpt/gdpt.cc
Original file line number Diff line number Diff line change
Expand Up @@ -552,9 +552,9 @@ void GDPTIntegrator::render(const std::shared_ptr<const Camera> &camera,
Integrator::render(camera, scene, params);
auto initSampler = sampler_->clone((unsigned int)time(0));

const int width = camera_->film()->resolution().x();
const int height = camera_->film()->resolution().y();
GDPTFilm film(camera_->film());
const int width = camera->film()->resolution().x();
const int height = camera->film()->resolution().y();
GDPTFilm film(camera->film());

const int numThreads = numSystemThreads();
auto samplers = std::vector<std::unique_ptr<Sampler>>(numThreads);
Expand Down Expand Up @@ -593,7 +593,7 @@ void GDPTIntegrator::render(const std::shared_ptr<const Camera> &camera,
const Point2d randFilm = samplers[threadID]->get2D();
const Point2d randLens = samplers[threadID]->get2D();
const double filterWeight = film.evalFilter(randFilm);
const Ray ray = camera_->spawnRay(Point2i(width - x - 1, y), randFilm, randLens);
const Ray ray = camera->spawnRay(Point2i(width - x - 1, y), randFilm, randLens);

// Base path
std::vector<Vertex> baseVerts;
Expand All @@ -610,7 +610,7 @@ void GDPTIntegrator::render(const std::shared_ptr<const Camera> &camera,
}

// Shift mapping
const Ray subRay = camera_->spawnRay(Point2i(width - nx - 1, ny), randFilm, randLens);
const Ray subRay = camera->spawnRay(Point2i(width - nx - 1, ny), randFilm, randLens);
TraceRecord subRecord(PathType::NotInvertible);
if (!baseVerts.empty()) {
subRecord = shiftMap(scene, params, subRay, *samplers[threadID], arenas[threadID], baseVerts);
Expand Down
8 changes: 5 additions & 3 deletions sources/integrators/hierarchical/hierarchical.cc
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,8 @@ Spectrum HierarchicalIntegrator::Li(const Scene& scene,
return L;
}

void HierarchicalIntegrator::initialize(const Scene& scene,
void HierarchicalIntegrator::initialize(const std::shared_ptr<const Camera> &camera,
const Scene& scene,
RenderParams& params,
Sampler& sampler) {
// Compute dA and copy maxError
Expand All @@ -458,11 +459,12 @@ void HierarchicalIntegrator::initialize(const Scene& scene,
hi_ = std::make_unique<Hierarchy>(radius, maxError_);
}

void HierarchicalIntegrator::loopStarted(const Scene& scene,
void HierarchicalIntegrator::loopStarted(const std::shared_ptr<const Camera> &camera,
const Scene& scene,
RenderParams& params,
Sampler& sampler) {
// Sample points with dart throwing
Point3d pCamera = camera_->cameraToWorld().apply(Point3d(0.0, 0.0, 0.0));
Point3d pCamera = camera->cameraToWorld().apply(Point3d(0.0, 0.0, 0.0));
hi_->samplePoints(scene, pCamera);

// Compute irradiance at sample points
Expand Down
6 changes: 4 additions & 2 deletions sources/integrators/hierarchical/hierarchical.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,13 @@ class SPICA_EXPORTS HierarchicalIntegrator : public SamplerIntegrator {

~HierarchicalIntegrator();

void initialize(const Scene& scene,
void initialize(const std::shared_ptr<const Camera> &camera,
const Scene& scene,
RenderParams& params,
Sampler& sampler) override;

void loopStarted(const Scene& scene,
void loopStarted(const std::shared_ptr<const Camera> &camera,
const Scene& scene,
RenderParams& params,
Sampler& sampler) override;

Expand Down
1 change: 0 additions & 1 deletion sources/integrators/path/path.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
#include "core/bxdf.h"
#include "core/bssrdf.h"

#include "core/camera.h"
#include "core/scene.h"

#include "core/integrator.h"
Expand Down
Loading

0 comments on commit e104adf

Please sign in to comment.