Skip to content

Commit

Permalink
Added renderer_ptmis
Browse files Browse the repository at this point in the history
  • Loading branch information
hi2p-perim committed Oct 20, 2016
1 parent 99f3cc5 commit bd612df
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 7 deletions.
3 changes: 3 additions & 0 deletions TODO.md
Expand Up @@ -34,6 +34,9 @@ TODO
- [ ] Improve the versionining of the scene file
- [ ] Versioning of the interfaces. Introduce a feature to detect a change in APIs
- [ ] Define flags based on the environment in .travis.yml
- [ ] Redesign parallel scheduler
- [ ] Support for 2D light transport simulation
- [ ] Rendering with automatic differenciation

Discussions
--------------------
Expand Down
3 changes: 2 additions & 1 deletion cmake/LMVersion.cmake
Expand Up @@ -29,10 +29,11 @@
# Version number and codename
# 2.0.0 - cocoa
# 2.0.1 - sansha-sanyou
# 2.0.2 - stella
set(LM_VERSION_MAJOR "2")
set(LM_VERSION_MINOR "0")
set(LM_VERSION_PATCH "1")
set(LM_VERSION_CODENAME "sansha-sanyou")
set(LM_VERSION_CODENAME "stella")

# Execute git command in the project root and check revision number
find_package(Git REQUIRED)
Expand Down
1 change: 1 addition & 0 deletions src/liblightmetrica/asset/film/film_hdr.cpp
Expand Up @@ -28,6 +28,7 @@
#include <lightmetrica/logger.h>
#include <lightmetrica/enum.h>
#include <FreeImage.h>
#include <signal.h>

LM_NAMESPACE_BEGIN

Expand Down
56 changes: 50 additions & 6 deletions src/liblightmetrica/renderer/renderer_ptmis.cpp
Expand Up @@ -36,6 +36,11 @@
#include <lightmetrica/surfacegeometry.h>
#include <lightmetrica/primitive.h>
#include <lightmetrica/scheduler.h>
#include <lightmetrica/detail/parallel.h>

#define LM_PTMIS_DEBUG_WEIGHT_IMAGE 0
#define LM_PTMIS_DEBUG_SIMPLIFY_PT_ONLY 0
#define LM_PTMIS_DEBUG_SIMPLIFY_DIRECT_ONLY 0

LM_NAMESPACE_BEGIN

Expand Down Expand Up @@ -63,7 +68,13 @@ class Renderer_PTMIS final : public Renderer

LM_IMPL_F(Render) = [this](const Scene* scene, Random* initRng, Film* film_) -> void
{
sched_->Process(scene, film_, initRng, [&](Film* film, Random* rng)
#if LM_PTMIS_DEBUG_WEIGHT_IMAGE
assert(Parallel::GetNumThreads() == 1);
auto filmW1 = ComponentFactory::Clone<Film>(film_);
auto filmW2 = ComponentFactory::Clone<Film>(film_);
#endif

const long long processed = sched_->Process(scene, film_, initRng, [&](Film* film, Random* rng)
{
#pragma region Sample a sensor
const auto* E = scene->SampleEmitter(SurfaceInteractionType::E, rng->Next());
Expand Down Expand Up @@ -115,6 +126,7 @@ class Renderer_PTMIS final : public Renderer
// --------------------------------------------------------------------------------

#pragma region Direct light sampling
#if !LM_PTMIS_DEBUG_SIMPLIFY_PT_ONLY
if (numVertices + 1 >= minNumVertices_)
{
#pragma region Sample a light
Expand Down Expand Up @@ -146,10 +158,14 @@ class Renderer_PTMIS final : public Renderer

// --------------------------------------------------------------------------------

#pragma region MIS weight
#pragma region MIS
#if LM_PTMIS_DEBUG_SIMPLIFY_DIRECT_ONLY
const auto w = 1_f;
#else
const auto pdfD_DirectLight = pdfPL.ConvertToProjSA(geom, geomL).v * pdfL.v;
const auto pdfD_BSDF = primitive->EvaluateDirectionPDF(geom, type, wi, ppL, true).v;
const auto w = pdfD_DirectLight / (pdfD_DirectLight + pdfD_BSDF);
#endif
#pragma endregion

// --------------------------------------------------------------------------------
Expand All @@ -166,9 +182,14 @@ class Renderer_PTMIS final : public Renderer

// Accumulate to film
film->Splat(rp, w * C);

#if LM_PTMIS_DEBUG_WEIGHT_IMAGE
filmW1->Splat(rp, SPD(w));
#endif
}
#pragma endregion
}
#endif
#pragma endregion

// --------------------------------------------------------------------------------
Expand Down Expand Up @@ -217,24 +238,38 @@ class Renderer_PTMIS final : public Renderer
// --------------------------------------------------------------------------------

#pragma region Handle hit with light source
#if !LM_PTMIS_DEBUG_SIMPLIFY_DIRECT_ONLY
if ((isect.primitive->Type() & SurfaceInteractionType::L) > 0)
{
// Accumulate to film
if (numVertices + 1 >= minNumVertices_)
{
// MIS weight
#if LM_PTMIS_DEBUG_SIMPLIFY_PT_ONLY
const auto w = 1_f;
#else
const auto pdfD_BSDF = pdfD.v;
const auto pdfD_DirectLight = isect.primitive->EvaluatePositionGivenPreviousPositionPDF(geom, isect.geom, true).v * scene->EvaluateEmitterPDF(isect.primitive).v;
const auto pdfD_DirectLight =
(type & SurfaceInteractionType::S) > 0
? 0_f
: isect.primitive->EvaluatePositionGivenPreviousPositionPDF(isect.geom, geom, true).ConvertToProjSA(isect.geom, geom).v *
scene->EvaluateEmitterPDF(isect.primitive).v;
const auto w = pdfD_BSDF / (pdfD_BSDF + pdfD_DirectLight);
#endif

// Contribution
const auto C =
throughput
* isect.primitive->EvaluateDirection(isect.geom, SurfaceInteractionType::L, Vec3(), -ray.d, TransportDirection::EL, false)
* isect.primitive->EvaluatePosition(isect.geom, false);
throughput
* isect.primitive->EvaluateDirection(isect.geom, SurfaceInteractionType::L, Vec3(), -ray.d, TransportDirection::EL, false)
* isect.primitive->EvaluatePosition(isect.geom, false);
film->Splat(rasterPos, w * C);

#if LM_PTMIS_DEBUG_WEIGHT_IMAGE
filmW2->Splat(rasterPos, SPD(w));
#endif
}
}
#endif
#pragma endregion

// --------------------------------------------------------------------------------
Expand Down Expand Up @@ -267,6 +302,15 @@ class Renderer_PTMIS final : public Renderer
#pragma endregion
}
});

#if LM_PTMIS_DEBUG_WEIGHT_IMAGE
filmW1->Rescale(1_f / processed);
filmW2->Rescale(1_f / processed);
filmW1->Save("ptmis_w1");
filmW2->Save("ptmis_w2");
#else
LM_UNUSED(processed);
#endif
};

};
Expand Down

0 comments on commit bd612df

Please sign in to comment.