diff --git a/src/subsurface/dipole.cpp b/src/subsurface/dipole.cpp index 5758e20a..04768763 100644 --- a/src/subsurface/dipole.cpp +++ b/src/subsurface/dipole.cpp @@ -396,9 +396,11 @@ public: Float actualRadius = m_radius / std::sqrt(m_sampleMultiplier * 20); blueNoisePointSet(scene, m_shapes, actualRadius, points, sa, aabb, job); - /* 2. gather irradiance in parallel */ + /* 2. Gather irradiance in parallel */ + const Sensor *sensor = scene->getSensor(); ref proc = new IrradianceSamplingProcess( - points, 1024, m_irrSamples, m_irrIndirect, job); + points, 1024, m_irrSamples, m_irrIndirect, + sensor->getShutterOpen() + 0.5f * sensor->getShutterOpenTime(), job); /* Create a sampler instance for every core */ ref sampler = static_cast (PluginManager::getInstance()-> @@ -411,8 +413,11 @@ public: } int samplerResID = sched->registerMultiResource(samplers); + int integratorResID = sched->registerResource( + const_cast(scene->getIntegrator())); proc->bindResource("scene", sceneResID); + proc->bindResource("integrator", integratorResID); proc->bindResource("sampler", samplerResID); scene->bindUsedResources(proc); m_proc = proc; @@ -423,6 +428,7 @@ public: samplers[i]->decRef(); sched->unregisterResource(samplerResID); + sched->unregisterResource(integratorResID); if (proc->getReturnStatus() != ParallelProcess::ESuccess) return false; diff --git a/src/subsurface/irrproc.cpp b/src/subsurface/irrproc.cpp index aa61bca6..ff038022 100644 --- a/src/subsurface/irrproc.cpp +++ b/src/subsurface/irrproc.cpp @@ -26,18 +26,20 @@ MTS_NAMESPACE_BEGIN /* Parallel irradiance sampling implementation (worker) */ class IrradianceSamplingWorker : public WorkProcessor { public: - IrradianceSamplingWorker(int irrSamples, bool irrIndirect) - : m_irrSamples(irrSamples), m_irrIndirect(irrIndirect) { + IrradianceSamplingWorker(int irrSamples, bool irrIndirect, Float time) + : m_irrSamples(irrSamples), m_irrIndirect(irrIndirect), m_time(time) { } IrradianceSamplingWorker(Stream *stream, InstanceManager *manager) { m_irrSamples = stream->readInt(); m_irrIndirect = stream->readBool(); + m_time = stream->readFloat(); } void serialize(Stream *stream, InstanceManager *manager) const { stream->writeInt(m_irrSamples); stream->writeBool(m_irrIndirect); + stream->writeFloat(m_time); } ref createWorkUnit() const { @@ -50,8 +52,8 @@ public: void prepare() { m_scene = static_cast(getResource("scene")); - m_integrator = static_cast(m_scene->getIntegrator()); m_sampler = static_cast(getResource("sampler")); + m_integrator = static_cast(getResource("integrator")); m_scene->wakeup(NULL, m_resources); } @@ -60,7 +62,6 @@ public: const PositionSampleVector &positions = *static_cast(workUnit); IrradianceSampleVector *result = static_cast(workResult); const SamplingIntegrator *integrator = m_integrator.get(); - Float time = m_scene->getSensor()->getShutterOpen(); result->clear(); @@ -71,7 +72,7 @@ public: its.p = sample.p; its.shFrame = Frame(sample.n); its.shape = m_scene->getShapes()[sample.shapeIndex].get(); - its.time = time; + its.time = m_time; its.hasUVPartials = false; result->put(IrradianceSample( @@ -83,7 +84,7 @@ public: } ref clone() const { - return new IrradianceSamplingWorker(m_irrSamples, m_irrIndirect); + return new IrradianceSamplingWorker(m_irrSamples, m_irrIndirect, m_time); } MTS_DECLARE_CLASS() @@ -95,6 +96,7 @@ private: ref m_integrator; int m_irrSamples; bool m_irrIndirect; + Float m_time; }; void PositionSampleVector::load(Stream *stream) { @@ -144,10 +146,10 @@ std::string IrradianceSampleVector::toString() const { } IrradianceSamplingProcess::IrradianceSamplingProcess(PositionSampleVector *positions, - size_t granularity, int irrSamples, bool irrIndirect, + size_t granularity, int irrSamples, bool irrIndirect, Float time, const void *data) : m_positionSamples(positions), m_granularity(granularity), - m_irrSamples(irrSamples), m_irrIndirect(irrIndirect) { + m_irrSamples(irrSamples), m_irrIndirect(irrIndirect), m_time(time) { m_resultMutex = new Mutex(); m_irradianceSamples = new IrradianceSampleVector(); m_irradianceSamples->reserve(positions->size()); @@ -161,7 +163,7 @@ IrradianceSamplingProcess::~IrradianceSamplingProcess() { } ref IrradianceSamplingProcess::createWorkProcessor() const { - return new IrradianceSamplingWorker(m_irrSamples, m_irrIndirect); + return new IrradianceSamplingWorker(m_irrSamples, m_irrIndirect, m_time); } ParallelProcess::EStatus IrradianceSamplingProcess::generateWork(WorkUnit *unit, int worker) { diff --git a/src/subsurface/irrproc.h b/src/subsurface/irrproc.h index 33c82d25..39ec8f7f 100644 --- a/src/subsurface/irrproc.h +++ b/src/subsurface/irrproc.h @@ -194,7 +194,7 @@ class IrradianceSamplingProcess : public ParallelProcess { public: IrradianceSamplingProcess(PositionSampleVector *positions, size_t granularity, int irrSamples, bool irrIndirect, - const void *data); + Float time, const void *data); inline IrradianceSampleVector *getIrradianceSampleVector() { return m_irradianceSamples.get(); @@ -223,6 +223,7 @@ private: size_t m_samplesRequested, m_granularity; int m_irrSamples; bool m_irrIndirect; + Float m_time; ref m_resultMutex; ProgressReporter *m_progress; AABB m_aabb;