Photon Engine 2.0.0-beta
A physically based renderer.
Loading...
Searching...
No Matches
SidednessAgreement.h
Go to the documentation of this file.
1#pragma once
2
3#include "Core/SurfaceHit.h"
4#include "Math/TVector3.h"
5
6#include <Common/assertion.h>
7
8namespace ph::lta
9{
10
17{
20
22 Strict,
23
26
29};
30
32{
33public:
35 explicit SidednessAgreement(ESidednessPolicy policy);
36
38 const math::Vector3R& Ng,
39 const math::Vector3R& Ns,
40 const math::Vector3R& vec) const;
41
43 const SurfaceHit& X,
44 const math::Vector3R& vec) const;
45
53 const SurfaceHit& X,
54 const math::Vector3R& vec) const;
55
63 const SurfaceHit& X,
64 const math::Vector3R& vec) const;
65
73 const SurfaceHit& X,
74 const math::Vector3R& vecA,
75 const math::Vector3R& vecB) const;
76
84 const SurfaceHit& X,
85 const math::Vector3R& vecA,
86 const math::Vector3R& vecB) const;
87
89
90private:
91 ESidednessPolicy m_policy;
92};
93
94// In-header Implementations:
95
99
101 m_policy(policy)
102{}
103
105 const math::Vector3R& Ng,
106 const math::Vector3R& Ns,
107 const math::Vector3R& vec) const
108{
109 switch(m_policy)
110 {
114 {
115 // No agreement issue with single input vector with these policies
116 return true;
117 }
118
120 {
121 return Ng.dot(vec) * Ns.dot(vec) > 0.0_r;
122 }
123
124 default:
125 PH_ASSERT_UNREACHABLE_SECTION();
126 return false;
127 }
128}
129
131 const SurfaceHit& X,
132 const math::Vector3R& vec) const
133{
135}
136
138 const SurfaceHit& X,
139 const math::Vector3R& vec) const
140{
141 switch(m_policy)
142 {
145 {
146 const math::Vector3R& Ng = X.getGeometryNormal();
147
148 return Ng.dot(vec) > 0.0_r;
149 }
150
152 {
153 const math::Vector3R& Ns = X.getShadingNormal();
154
155 return Ns.dot(vec) > 0.0_r;
156 }
157
159 {
160 const math::Vector3R& N = X.getGeometryNormal();
161
162 return isSidednessAgreed(X, vec) && // The vector need to be strictly agreed on sidedness.
163 vec.dot(N) > 0.0_r; // Then testing hemisphere with either normal
164 // (the other normal would yield the same sign)
165 }
166
167 default:
168 PH_ASSERT_UNREACHABLE_SECTION();
169 return false;
170 }
171}
172
174 const SurfaceHit& X,
175 const math::Vector3R& vec) const
176{
177 switch(m_policy)
178 {
181 {
182 const math::Vector3R& Ng = X.getGeometryNormal();
183
184 return Ng.dot(vec) < 0.0_r;
185 }
186
188 {
189 const math::Vector3R& Ns = X.getShadingNormal();
190
191 return Ns.dot(vec) < 0.0_r;
192 }
193
195 {
196 const math::Vector3R& N = X.getGeometryNormal();
197
198 return isSidednessAgreed(X, vec) && // The vector need to be strictly agreed on sidedness.
199 vec.dot(N) < 0.0_r; // Then testing hemisphere with either normal
200 // (the other normal would yield the same sign)
201 }
202
203 default:
204 PH_ASSERT_UNREACHABLE_SECTION();
205 return false;
206 }
207}
208
210 const SurfaceHit& X,
211 const math::Vector3R& vecA,
212 const math::Vector3R& vecB) const
213{
214 switch(m_policy)
215 {
218 {
219 const math::Vector3R& Ng = X.getGeometryNormal();
220
221 return Ng.dot(vecA) * Ng.dot(vecB) > 0.0_r;
222 }
223
225 {
226 const math::Vector3R& Ns = X.getShadingNormal();
227
228 return Ns.dot(vecA) * Ns.dot(vecB) > 0.0_r;
229 }
230
232 {
233 const math::Vector3R& N = X.getGeometryNormal();
234
235 return isSidednessAgreed(X, vecA) && // Both vectors need to be strictly
236 isSidednessAgreed(X, vecB) && // agreed on sidedness.
237 vecA.dot(N) * vecB.dot(N) > 0.0_r;// Then testing hemisphere with either normal
238 // (the other normal would yield the same sign)
239 }
240
241 default:
242 PH_ASSERT_UNREACHABLE_SECTION();
243 return false;
244 }
245}
246
248 const SurfaceHit& X,
249 const math::Vector3R& vecA,
250 const math::Vector3R& vecB) const
251{
252 switch(m_policy)
253 {
256 {
257 const math::Vector3R& Ng = X.getGeometryNormal();
258
259 return Ng.dot(vecA) * Ng.dot(vecB) < 0.0_r;
260 }
261
263 {
264 const math::Vector3R& Ns = X.getShadingNormal();
265
266 return Ns.dot(vecA) * Ns.dot(vecB) < 0.0_r;
267 }
268
270 {
271 const math::Vector3R& N = X.getGeometryNormal();
272
273 return isSidednessAgreed(X, vecA) && // Both vectors need to be strictly
274 isSidednessAgreed(X, vecB) && // agreed on sidedness.
275 vecA.dot(N) * vecB.dot(N) < 0.0_r;// Then testing hemisphere with either normal
276 // (the other normal would yield same sign)
277 }
278
279 default:
280 PH_ASSERT_UNREACHABLE_SECTION();
281 return false;
282 }
283}
284
286 SurfaceHit& X) const
287{
288 // Currently no adjustment
289}
290
291}// end namespace ph::lta
General information about a ray-surface intersection event.
Definition SurfaceHit.h:59
math::Vector3R getGeometryNormal() const
Definition SurfaceHit.h:196
math::Vector3R getShadingNormal() const
Definition SurfaceHit.h:191
Definition SidednessAgreement.h:32
void adjustForSidednessAgreement(SurfaceHit &X) const
Definition SidednessAgreement.h:285
bool isOppositeHemisphere(const SurfaceHit &X, const math::Vector3R &vecA, const math::Vector3R &vecB) const
Definition SidednessAgreement.h:247
bool isSidednessAgreed(const math::Vector3R &Ng, const math::Vector3R &Ns, const math::Vector3R &vec) const
Definition SidednessAgreement.h:104
bool isBackHemisphere(const SurfaceHit &X, const math::Vector3R &vec) const
Definition SidednessAgreement.h:173
SidednessAgreement()
Definition SidednessAgreement.h:96
bool isSameHemisphere(const SurfaceHit &X, const math::Vector3R &vecA, const math::Vector3R &vecB) const
Definition SidednessAgreement.h:209
bool isFrontHemisphere(const SurfaceHit &X, const math::Vector3R &vec) const
Definition SidednessAgreement.h:137
T dot(const Derived &rhs) const
Definition TVectorNBase.ipp:14
Light transport algorithms.
Definition enums.h:6
ESidednessPolicy
Definition SidednessAgreement.h:17