Photon Engine 2.0.0-beta
A physically based renderer.
Loading...
Searching...
No Matches
RussianRoulette.h
Go to the documentation of this file.
1#pragma once
2
4#include "Math/math.h"
6
7#include <Common/assertion.h>
8#include <Common/primitive_type.h>
9
10namespace ph::lta
11{
12
15class RussianRoulette final
16{
17public:
25 const math::Spectrum& s,
26 SampleFlow& sampleFlow,
27 real* out_survivalProbability) const;
28};
29
31 const math::Spectrum& s,
32 SampleFlow& sampleFlow,
33 real* const out_survivalProbability) const
34{
35 PH_ASSERT(out_survivalProbability);
36
37 // Survival rate is not allowed to be 100% to avoid immortal rays (e.g., TIR);
38 // the rate should also kill non-finite luminance as this is a good place to do it
39 const real rrSurvivalRate = math::safe_clamp(s.relativeLuminance(), 0.0_r, 0.95_r);
40 const real rrSpin = sampleFlow.flow1D();// FIXME: use something like sampleFlow.binaryPick()
41
42 // Survived
43 if(rrSpin < rrSurvivalRate)
44 {
45 PH_ASSERT(0.0_r < rrSurvivalRate && rrSurvivalRate <= 1.0_r);
46
47 *out_survivalProbability = rrSurvivalRate;
48 return true;
49 }
50 // Dead
51 else
52 {
53 return false;
54 }
55}
56
57}// end namespace ph::lta
A sample with arbitrary dimensions with fine-grained sampling control.
Definition SampleFlow.h:19
real flow1D()
Makes a 1-D sample by consuming the next dimension.
Definition SampleFlow.h:105
Russian roulette random termination scheme.
Definition RussianRoulette.h:16
bool surviveOnLuminance(const math::Spectrum &s, SampleFlow &sampleFlow, real *out_survivalProbability) const
Definition RussianRoulette.h:30
T relativeLuminance(EColorUsage usage=EColorUsage::EMR) const
Definition TSpectrumBase.ipp:124
Definition TTristimulusSpectrum.h:11
Miscellaneous math utilities.
Light transport algorithms.
Definition enums.h:6
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