From 3de850f4e25b151f2d2bb6159c8a5abbdeb124bc Mon Sep 17 00:00:00 2001 From: Wenzel Jakob Date: Wed, 8 Sep 2010 01:55:50 +0200 Subject: [PATCH] fix point sources in the RTRT preview --- include/mitsuba/render/preview.h | 7 +++++-- src/libhw/vpl.cpp | 2 +- src/librender/preview.cpp | 16 +++++++++------- src/qtgui/preview.cpp | 10 ++++++---- src/qtgui/preview_proc.cpp | 8 ++++++-- src/qtgui/preview_proc.h | 5 ++++- 6 files changed, 31 insertions(+), 17 deletions(-) diff --git a/include/mitsuba/render/preview.h b/include/mitsuba/render/preview.h index df7a4041..0106ff70 100644 --- a/include/mitsuba/render/preview.h +++ b/include/mitsuba/render/preview.h @@ -31,10 +31,12 @@ MTS_NAMESPACE_BEGIN class MTS_EXPORT_RENDER PreviewWorker : public WorkProcessor { public: inline PreviewWorker(int blockSize, Point cameraO, Vector cameraTL, - Vector cameraDx, Vector cameraDy, const VPL &vpl, Float minDist, bool coherent) + Vector cameraDx, Vector cameraDy, const VPL &vpl, Float minDist, bool coherent, + bool diffuseSources, bool diffuseReceivers) : m_blockSize(blockSize), m_cameraO(cameraO), m_cameraTL(cameraTL), m_cameraDx(cameraDx), m_cameraDy(cameraDy), m_vpl(vpl), - m_minDist(minDist), m_coherent(coherent) { + m_minDist(minDist), m_coherent(coherent), m_diffuseSources(diffuseSources), + m_diffuseReceivers(diffuseReceivers) { } void processIncoherent(const WorkUnit *workUnit, WorkResult *workResult, @@ -68,6 +70,7 @@ private: Float m_minDist; const std::vector *m_shapes; bool m_coherent; + bool m_diffuseSources, m_diffuseReceivers; }; MTS_NAMESPACE_END diff --git a/src/libhw/vpl.cpp b/src/libhw/vpl.cpp index c8e02104..f08dd7d1 100644 --- a/src/libhw/vpl.cpp +++ b/src/libhw/vpl.cpp @@ -192,7 +192,7 @@ void VPLShaderManager::setVPL(const VPL &vpl) { for (int i=1; i<=sampleCount; ++i) { Vector dir; Point2 seed(i*invSampleCount, radicalInverse(2, i)); // Hammersley seq. - if (vpl.type == ELuminaireVPL && vpl.luminaire->getType() & Luminaire::EOnSurface) + if (vpl.type == ESurfaceVPL || vpl.luminaire->getType() & Luminaire::EOnSurface) dir = vpl.its.shFrame.toWorld(squareToHemispherePSA(seed)); else dir = squareToSphere(seed); diff --git a/src/librender/preview.cpp b/src/librender/preview.cpp index 27b90cbb..5a20a046 100644 --- a/src/librender/preview.cpp +++ b/src/librender/preview.cpp @@ -108,9 +108,10 @@ void PreviewWorker::processIncoherent(const WorkUnit *workUnit, WorkResult *work EmissionRecord eRec(m_vpl.luminaire, ShapeSamplingRecord(m_vpl.its.p, m_vpl.its.shFrame.n), toIts); eRec.type = EmissionRecord::EPreview; - value += m_vpl.P * bsdfVal * m_vpl.luminaire->f(eRec) * - ((m_vpl.luminaire->getType() == Luminaire::EOnSurface ? - (Float) 1 : dot(m_vpl.its.shFrame.n, toIts)) / (length*length)); + value += m_vpl.P * bsdfVal * m_vpl.luminaire->f(eRec) + * ((m_vpl.luminaire->getType() & Luminaire::EOnSurface ? + dot(m_vpl.its.shFrame.n, toIts) : (Float) 1) + / (length*length)); } block->setPixel(pos++, value); } @@ -178,7 +179,7 @@ void PreviewWorker::processCoherent(const WorkUnit *workUnit, WorkResult *workRe bool diffuseVPL = false, vplOnSurface = false; Spectrum vplWeight; - if (m_vpl.type == ESurfaceVPL && m_vpl.its.shape->getBSDF()->getType() == BSDF::EDiffuseReflection) { + if (m_vpl.type == ESurfaceVPL && (m_diffuseSources || m_vpl.its.shape->getBSDF()->getType() == BSDF::EDiffuseReflection)) { diffuseVPL = true; vplOnSurface = true; vplWeight = m_vpl.its.shape->getBSDF()->getDiffuseReflectance(m_vpl.its) * m_vpl.P / M_PI; @@ -324,7 +325,7 @@ void PreviewWorker::processCoherent(const WorkUnit *workUnit, WorkResult *workRe /* Fast path */ direct[idx] = (bsdf->getDiffuseReflectance(its) * vplWeight) * (std::max((Float) 0.0f, dot(wo, its.shFrame.n)) - * (vplOnSurface ? std::max(cosThetaLight.f[idx], (Float) 0.0f) * INV_PI : 0.0f) + * (vplOnSurface ? std::max(cosThetaLight.f[idx], (Float) 0.0f) * INV_PI : 1.0f) * invLengthSquared.f[idx]); } else { wi.x = -primRay4.d[0].f[idx]; @@ -355,7 +356,7 @@ void PreviewWorker::processCoherent(const WorkUnit *workUnit, WorkResult *workRe } } - if (EXPECT_TAKEN(ctLight > 0)) { + if (EXPECT_TAKEN(ctLight >= 0)) { direct[idx] = (bsdf->fCos(BSDFQueryRecord(its, wo)) * vplWeight * ((vplOnSurface ? std::max(ctLight, (Float) 0.0f) : 1.0f) * invLengthSquared.f[idx])); } else { @@ -402,7 +403,8 @@ void PreviewWorker::processCoherent(const WorkUnit *workUnit, WorkResult *workRe ref PreviewWorker::clone() const { return new PreviewWorker(m_blockSize, m_cameraO, m_cameraTL, - m_cameraDx, m_cameraDy, m_vpl, m_minDist, m_coherent); + m_cameraDx, m_cameraDy, m_vpl, m_minDist, m_coherent, + m_diffuseSources, m_diffuseReceivers); } MTS_IMPLEMENT_CLASS(PreviewWorker, false, WorkProcessor) diff --git a/src/qtgui/preview.cpp b/src/qtgui/preview.cpp index 6ea9ffde..9043e90f 100644 --- a/src/qtgui/preview.cpp +++ b/src/qtgui/preview.cpp @@ -545,10 +545,10 @@ void PreviewThread::rtrtRenderVPL(PreviewQueueEntry &target, const VPL &vpl) { for (int i=1; i<=sampleCount; ++i) { Vector dir; Point2 seed(i*invSampleCount, radicalInverse(2, i)); // Hammersley seq. - if (vpl.type == ELuminaireVPL && vpl.luminaire->getType() == Luminaire::EDeltaPosition) - dir = squareToSphere(seed); - else + if (vpl.type == ESurfaceVPL || vpl.luminaire->getType() & Luminaire::EOnSurface) dir = vpl.its.shFrame.toWorld(squareToHemispherePSA(seed)); + else + dir = squareToSphere(seed); ray.setDirection(dir); if (m_context->scene->rayIntersect(ray, its)) { @@ -578,7 +578,9 @@ void PreviewThread::rtrtRenderVPL(PreviewQueueEntry &target, const VPL &vpl) { m_previewProc->configure(vpl, minDist, jitter, m_accumBuffer ? m_accumBuffer->getBitmap() : NULL, target.buffer->getBitmap(), - m_context->previewMethod == ERayTraceCoherent); + m_context->previewMethod == ERayTraceCoherent, + m_context->diffuseSources, + m_context->diffuseReceivers); m_mutex->unlock(); ref sched = Scheduler::getInstance(); diff --git a/src/qtgui/preview_proc.cpp b/src/qtgui/preview_proc.cpp index dd04ed79..b0080bf8 100644 --- a/src/qtgui/preview_proc.cpp +++ b/src/qtgui/preview_proc.cpp @@ -72,7 +72,8 @@ void PreviewProcess::processResult(const WorkResult *result, bool cancelled) { } void PreviewProcess::configure(const VPL &vpl, Float minDist, const Point2 &jitter, - const Bitmap *source, Bitmap *target, bool coherent) { + const Bitmap *source, Bitmap *target, bool coherent, bool diffuseSources, + bool diffuseReceivers) { BlockedImageProcess::init(m_film->getCropOffset(), m_film->getCropSize(), m_blockSize); m_source = source; m_target = target; @@ -80,6 +81,8 @@ void PreviewProcess::configure(const VPL &vpl, Float minDist, const Point2 &jitt m_vpl = &vpl; m_minDist = minDist; m_coherent = coherent; + m_diffuseSources = diffuseSources; + m_diffuseReceivers = diffuseReceivers; /* It is not necessary to shoot normalized rays. Instead, interpolate: here, we generate the upper left corner ray as well as the @@ -104,7 +107,8 @@ void PreviewProcess::configure(const VPL &vpl, Float minDist, const Point2 &jitt ref PreviewProcess::createWorkProcessor() const { return new PreviewWorker(m_blockSize, m_cameraO, m_cameraTL, - m_cameraDx, m_cameraDy, *m_vpl, m_minDist, m_coherent); + m_cameraDx, m_cameraDy, *m_vpl, m_minDist, m_coherent, + m_diffuseSources, m_diffuseReceivers); } diff --git a/src/qtgui/preview_proc.h b/src/qtgui/preview_proc.h index 3e4e63bb..79f842dd 100644 --- a/src/qtgui/preview_proc.h +++ b/src/qtgui/preview_proc.h @@ -17,7 +17,8 @@ public: PreviewProcess(const Scene *scene, int sceneResID, int blockSize); void configure(const VPL &vpl, Float minDist, const Point2 &jitter, - const Bitmap *source, Bitmap *target, bool coherent); + const Bitmap *source, Bitmap *target, bool coherent, + bool diffuseSources, bool diffuseReceivers); inline int getRayCount() const { return m_numRays; } inline const Scene *getScene() const { return m_scene; } @@ -42,6 +43,8 @@ private: const VPL *m_vpl; Float m_minDist; bool m_coherent; + bool m_diffuseSources; + bool m_diffuseReceivers; }; #endif /* __PREVIEW_PROC_H */