Photon Engine 2.0.0-beta
A physically based renderer.
Loading...
Searching...
No Matches
lta.h
Go to the documentation of this file.
1#pragma once
2
3#include "Math/TVector3.h"
4#include "Math/math.h"
5
6#include <Common/config.h>
7#include <Common/assertion.h>
8#include <Common/primitive_type.h>
9
10#include <cmath>
11
12namespace ph::lta
13{
14
17inline real pdfA_to_pdfW(
18 const real pdfA,
19 const math::Vector3R& dAPosToTargetPos,
20 const math::Vector3R& dANormal)
21{
22 const real distSquared = dAPosToTargetPos.lengthSquared();
23 const real signedPdfW = pdfA / dAPosToTargetPos.normalize().dot(dANormal) * distSquared;
24 return std::isfinite(signedPdfW) ? std::abs(signedPdfW) : 0.0_r;
25}
26
49 const math::Vector3R& Ns,
50 const math::Vector3R& Ng,
51 const math::Vector3R& L,
52 const math::Vector3R& V)
53{
54 PH_ASSERT_NE(Ng.dot(V) * Ns.dot(L), 0.0_r);
55
56 return std::abs((Ns.dot(V) * Ng.dot(L)) / (Ng.dot(V) * Ns.dot(L)));
57}
58
74 const math::Vector3R& Ns,
75 const math::Vector3R& Ng,
76 const math::Vector3R& V)
77{
78 PH_ASSERT_NE(Ng.dot(V), 0.0_r);
79
80 return std::abs(Ns.dot(V) / Ng.dot(V));
81}
82
95 const math::Vector3R& Ns,
96 const math::Vector3R& Ng,
97 const math::Vector3R& L,
98 const math::Vector3R& V)
99{
100 const auto factor = importance_scatter_Ns_corrector(Ns, Ng, L, V);
101#if PH_STRICT_ASYMMETRIC_IMPORTANCE_TRANSPORT
102 return factor;
103#else
104 return math::safe_clamp(factor, 0.0_r, 10.0_r);
105#endif
106}
107
112 const math::Vector3R& Ns,
113 const math::Vector3R& Ng,
114 const math::Vector3R& V)
115{
116 const auto factor = importance_BSDF_Ns_corrector(Ns, Ng, V);
117#if PH_STRICT_ASYMMETRIC_IMPORTANCE_TRANSPORT
118 return factor;
119#else
120 // To my testing, the corrector for BSDF dominates the unbearable variance. Clamping to 10 seems to
121 // work well. Mitsuba 0.6 uses another approach: discards the photon if `Ng.dot(V) < 1e-2f`.
122 return math::safe_clamp(factor, 0.0_r, 10.0_r);
123#endif
124}
125
126}// end namespace ph::lta
T dot(const Derived &rhs) const
Definition TVectorNBase.ipp:14
Derived normalize() const
Normalize the vector. Notice that normalizing a integer typed vector will result in 0-vector most of ...
Definition TVectorNBase.ipp:50
T lengthSquared() const
Definition TVectorNBase.ipp:44
Miscellaneous math utilities.
Light transport algorithms.
Definition enums.h:6
real importance_scatter_Ns_corrector(const math::Vector3R &Ns, const math::Vector3R &Ng, const math::Vector3R &L, const math::Vector3R &V)
Definition lta.h:48
real pdfA_to_pdfW(const real pdfA, const math::Vector3R &dAPosToTargetPos, const math::Vector3R &dANormal)
Transform area domain PDF to solid angle domain PDF w.r.t. a position.
Definition lta.h:17
real tamed_importance_scatter_Ns_corrector(const math::Vector3R &Ns, const math::Vector3R &Ng, const math::Vector3R &L, const math::Vector3R &V)
Smoother version of importance_scatter_Ns_corrector().
Definition lta.h:94
real tamed_importance_BSDF_Ns_corrector(const math::Vector3R &Ns, const math::Vector3R &Ng, const math::Vector3R &V)
Smoother version of importance_BSDF_Ns_corrector(). See tamed_importance_scatter_Ns_corrector() for e...
Definition lta.h:111
real importance_BSDF_Ns_corrector(const math::Vector3R &Ns, const math::Vector3R &Ng, const math::Vector3R &V)
Definition lta.h:73
T safe_clamp(const T value, const T lowerBound, const T upperBound)
Clamps a value to [lowerBound, upperBound], fallback to lowerBound. If a floating-point value is non-...
Definition math.h:98