Photon Engine 2.0.0-beta
A physically based renderer.
Loading...
Searching...
No Matches
BsdfSampleQuery.h
Go to the documentation of this file.
1#pragma once
2
4#include "Math/TVector3.h"
5#include "Core/SurfaceHit.h"
8
9#include <Common/assertion.h>
10
11#include <cmath>
12#include <string>
13#include <utility>
14
15namespace ph
16{
17
20class BsdfSampleInput final
21{
22public:
23 void set(const BsdfEvalInput& evalInput);
24 void set(const SurfaceHit& X, const math::Vector3R& V);
25
26 const SurfaceHit& getX() const;
27
31 const math::Vector3R& getV() const;
32
33private:
34 SurfaceHit m_X;
36#if PH_DEBUG
37 bool m_hasSet{false};
38#endif
39};
40
45{
46public:
47 void setL(const math::Vector3R& L);
48
58 const math::Spectrum& pdfAppliedBsdfCos,
59 real cos,
60 bool inferMeasurability = true);
61
65 const math::Vector3R& getL() const;
66
73 real getCos() const;
74
80
92
98 real getRelativeIor() const;
99
103 real getRelativeIor2() const;
104
111 bool isMeasurable() const;
112
115 void setMeasurability(bool measurability);
116
119 void setMeasurability(const math::Spectrum& reference);
120
124 void setRelativeIor(real relativeIor);
125
128 operator bool () const;
129
130private:
131 math::Vector3R m_L{0};
132 math::Spectrum m_pdfAppliedBsdfCos{0};
133 real m_cos{0};
134 real m_relativeIor{1};
135 bool m_isMeasurable{false};
136};
137
153
154// In-header Implementations:
155
158{
159 this->context = std::move(context);
160
161 // (rest of the fields are initialized via setters)
162}
163
164inline void BsdfSampleInput::set(const SurfaceHit& X, const math::Vector3R& V)
165{
166 // Not querying from uninitialized surface hit
168
169 PH_ASSERT_IN_RANGE(V.lengthSquared(), 0.9_r, 1.1_r);
170
171 m_X = X;
172 m_V = V;
173
174#if PH_DEBUG
175 m_hasSet = true;
176#endif
177}
178
180{
181 PH_ASSERT(m_hasSet);
182
183 return m_X;
184}
185
187{
188 PH_ASSERT(m_hasSet);
189
190 return m_V;
191}
192
194{
195 PH_ASSERT_IN_RANGE(L.lengthSquared(), 0.9_r, 1.1_r);
196
197 m_L = L;
198}
199
201 const math::Spectrum& pdfAppliedBsdfCos,
202 const real cos,
203 const bool inferMeasurability)
204{
205 m_pdfAppliedBsdfCos = pdfAppliedBsdfCos;
206 m_cos = cos;
207
208 if(inferMeasurability)
209 {
210 setMeasurability(pdfAppliedBsdfCos);
211 setMeasurability(isMeasurable() && 0.0_r < cos && cos < 1.1_r);
212 }
213}
214
216{
217 PH_ASSERT(isMeasurable());
218 PH_ASSERT_IN_RANGE(m_L.lengthSquared(), 0.9_r, 1.1_r);
219
220 return m_L;
221}
222
223inline real BsdfSampleOutput::getCos() const
224{
225 PH_ASSERT(isMeasurable());
226 PH_ASSERT_IN_RANGE_EXCLUSIVE(m_cos, 0.0_r, 1.1_r);
227
228 return m_cos;
229}
230
232{
233 const auto pdfAppliedBsdf = getPdfAppliedBsdfCos() / getCos();
234 return pdfAppliedBsdf.isFinite() ? pdfAppliedBsdf : math::Spectrum(0);
235}
236
238{
239 // When a sample report being measurable, it must not be some crazy values
240 PH_ASSERT(isMeasurable());
241 PH_ASSERT_MSG(m_pdfAppliedBsdfCos.isFinite(), m_pdfAppliedBsdfCos.toString());
242
243 return m_pdfAppliedBsdfCos;
244}
245
247{
248 PH_ASSERT(isMeasurable());
249 PH_ASSERT_MSG(std::isfinite(m_relativeIor) && m_relativeIor > 0, std::to_string(m_relativeIor));
250
251 return m_relativeIor;
252}
253
255{
256 const real relativeIor = getRelativeIor();
257 return relativeIor * relativeIor;
258}
259
261{
262 return m_isMeasurable;
263}
264
265inline void BsdfSampleOutput::setMeasurability(const bool measurability)
266{
267 m_isMeasurable = measurability;
268}
269
271{
272 setMeasurability(reference.isFinite());
273}
274
275inline void BsdfSampleOutput::setRelativeIor(const real relativeIor)
276{
277 m_relativeIor = relativeIor;
278}
279
280inline BsdfSampleOutput::operator bool () const
281{
282 return isMeasurable();
283}
284
285}// end namespace ph
Input for BsdfEvalQuery.
Definition BsdfEvalQuery.h:20
The environment a BSDF query is performed under.
Definition BsdfQueryContext.h:13
Input for BsdfSampleQuery.
Definition BsdfSampleQuery.h:21
const SurfaceHit & getX() const
Definition BsdfSampleQuery.h:179
const math::Vector3R & getV() const
Definition BsdfSampleQuery.h:186
void set(const BsdfEvalInput &evalInput)
Definition BsdfSampleQuery.cpp:7
Output for BsdfSampleQuery.
Definition BsdfSampleQuery.h:45
void setL(const math::Vector3R &L)
Definition BsdfSampleQuery.h:193
real getRelativeIor2() const
Definition BsdfSampleQuery.h:254
void setRelativeIor(real relativeIor)
Definition BsdfSampleQuery.h:275
real getRelativeIor() const
Definition BsdfSampleQuery.h:246
void setMeasurability(bool measurability)
Set measurability directly.
Definition BsdfSampleQuery.h:265
const math::Vector3R & getL() const
Definition BsdfSampleQuery.h:215
const math::Spectrum & getPdfAppliedBsdfCos() const
Definition BsdfSampleQuery.h:237
bool isMeasurable() const
Tells whether this sample has potential to contribute. All sampled data should be usable if true is r...
Definition BsdfSampleQuery.h:260
real getCos() const
Definition BsdfSampleQuery.h:223
math::Spectrum getPdfAppliedBsdf() const
Definition BsdfSampleQuery.h:231
void setPdfAppliedBsdfCos(const math::Spectrum &pdfAppliedBsdfCos, real cos, bool inferMeasurability=true)
Definition BsdfSampleQuery.h:200
Information for generating a BSDF sample.
Definition BsdfSampleQuery.h:141
Input inputs
Definition BsdfSampleQuery.h:147
BsdfQueryContext context
Definition BsdfSampleQuery.h:146
BsdfSampleQuery()=default
Output outputs
Definition BsdfSampleQuery.h:148
General information about a ray-surface intersection event.
Definition SurfaceHit.h:59
SurfaceHitReason getReason() const
Definition SurfaceHit.h:164
constexpr bool hasExactly(const FlagsSet &flagsSet) const
Checks whether this instance contains exactly the specified flags. No more, no less.
Definition TBitFlags.ipp:99
std::string toString() const
Definition TArithmeticArrayBase.ipp:825
bool isFinite() const
Definition TArithmeticArrayBase.ipp:585
Definition TTristimulusSpectrum.h:11
T lengthSquared() const
Definition TVectorNBase.ipp:44
LinearSRGBSpectrum Spectrum
Definition spectrum_fwd.h:33
The root for all renderer implementations.
Definition EEngineProject.h:6