Photon Engine 2.0.0-beta
A physically based renderer.
Loading...
Searching...
No Matches
HitDetail.h
Go to the documentation of this file.
1#pragma once
2
3#include "Math/TVector3.h"
5#include "Math/math.h"
6#include "Core/ECoordSys.h"
7#include "Core/HitInfo.h"
8#include "Core/FaceTopology.h"
9#include "Utility/utility.h"
10
11#include <Common/assertion.h>
12#include <Common/primitive_type.h>
13
14#include <cstddef>
15#include <utility>
16#include <cmath>
17
18namespace ph { class Primitive; }
19
20namespace ph
21{
22
25class HitDetail final
26{
27public:
28 inline static constexpr auto NO_FACE_ID = static_cast<uint64>(-1);
29
32 HitDetail();
33
43 const Primitive* primitive,
44 const math::Vector3R& uvw,
45 real rayT,
46 uint64 faceID = NO_FACE_ID,
48
49 void computeBases();
50
58 math::Vector3R getUVW() const;
61
66 real getRayT() const;
67
73 uint64 getFaceID() const;
74
79
83 const Primitive* getPrimitive() const;
84
85 const HitInfo& getHitInfo(ECoordSys coordSys = ECoordSys::World) const;
87 std::pair<real, real> getDistanceErrorFactors() const;
88 void setDistanceErrorFactors(real meanFactor, real maxFactor);
89
90private:
91 const Primitive* m_primitive;
92 math::Vector3R m_uvw;
93 real m_rayT;
94 HitInfo m_hitInfos[enum_size<ECoordSys>()];
95 uint64 m_faceID;
96 FaceTopology m_faceTopology;
97 int8 m_meanDistanceErrorFactorExp2;
98 int8 m_maxDistanceErrorFactorExp2;
99};
100
101// In-header Implementations:
102
103inline math::Vector3R HitDetail::getPos(const ECoordSys coordSys) const
104{
105 return getHitInfo(coordSys).getPos();
106}
107
109{
110 return getHitInfo(coordSys).getShadingNormal();
111}
112
114{
115 return getHitInfo(coordSys).getGeometryNormal();
116}
117
118inline math::Vector3R HitDetail::getdPdU(const ECoordSys coordSys) const
119{
120 return getHitInfo(coordSys).getdPdU();
121}
122
123inline math::Vector3R HitDetail::getdPdV(const ECoordSys coordSys) const
124{
125 return getHitInfo(coordSys).getdPdV();
126}
127
128inline math::Vector3R HitDetail::getdNdU(const ECoordSys coordSys) const
129{
130 return getHitInfo(coordSys).getdNdU();
131}
132
133inline math::Vector3R HitDetail::getdNdV(const ECoordSys coordSys) const
134{
135 return getHitInfo(coordSys).getdNdV();
136}
137
138inline const math::Basis3R& HitDetail::getGeometryBasis(const ECoordSys coordSys) const
139{
140 return getHitInfo(coordSys).getGeometryBasis();
141}
142
143inline const math::Basis3R& HitDetail::getShadingBasis(const ECoordSys coordSys) const
144{
145 return getHitInfo(coordSys).getShadingBasis();
146}
147
148inline real HitDetail::getRayT() const
149{
150 return m_rayT;
151}
152
153inline uint64 HitDetail::getFaceID() const
154{
155 return m_faceID;
156}
157
159{
160 return FaceTopology(m_faceTopology);
161}
162
164{
165 return m_primitive;
166}
167
169{
170 return m_uvw;
171}
172
173inline const HitInfo& HitDetail::getHitInfo(const ECoordSys coordSys) const
174{
175 PH_ASSERT_IN_RANGE(enum_to_value(coordSys), 0, enum_size<ECoordSys>());
176 return m_hitInfos[enum_to_value(coordSys)];
177}
178
180{
181 PH_ASSERT_IN_RANGE(enum_to_value(coordSys), 0, enum_size<ECoordSys>());
182 return m_hitInfos[enum_to_value(coordSys)];
183}
184
185inline std::pair<real, real> HitDetail::getDistanceErrorFactors() const
186{
187 return {
188 static_cast<real>(std::exp2(m_meanDistanceErrorFactorExp2)),
189 static_cast<real>(std::exp2(m_maxDistanceErrorFactorExp2))};
190}
191
192inline void HitDetail::setDistanceErrorFactors(const real meanFactor, const real maxFactor)
193{
194 // These should be absolute values
195 PH_ASSERT_GE(meanFactor, 0.0_r);
196 PH_ASSERT_GE(maxFactor, 0.0_r);
197
198 m_meanDistanceErrorFactorExp2 = static_cast<int8>(std::round(std::log2(meanFactor)));
199 m_maxDistanceErrorFactorExp2 = static_cast<int8>(std::ceil(std::log2(maxFactor)));
200}
201
202}// end namespace ph
Detailed information regarding a ray-primitive intersection.
Definition HitDetail.h:26
math::Vector3R getdPdV(ECoordSys coordSys=ECoordSys::World) const
Definition HitDetail.h:123
math::Vector3R getdPdU(ECoordSys coordSys=ECoordSys::World) const
Definition HitDetail.h:118
math::Vector3R getShadingNormal(ECoordSys coordSys=ECoordSys::World) const
Definition HitDetail.h:108
math::Vector3R getdNdU(ECoordSys coordSys=ECoordSys::World) const
Definition HitDetail.h:128
uint64 getFaceID() const
Get the face ID associated to the hit.
Definition HitDetail.h:153
const Primitive * getPrimitive() const
Definition HitDetail.h:163
math::Vector3R getUVW() const
Definition HitDetail.h:168
const math::Basis3R & getShadingBasis(ECoordSys coordSys=ECoordSys::World) const
Definition HitDetail.h:143
void setDistanceErrorFactors(real meanFactor, real maxFactor)
Definition HitDetail.h:192
HitDetail()
Creates a hit detail filled with default values.
Definition HitDetail.cpp:12
std::pair< real, real > getDistanceErrorFactors() const
Definition HitDetail.h:185
void computeBases()
Definition HitDetail.cpp:39
static constexpr auto NO_FACE_ID
Definition HitDetail.h:28
real getRayT() const
Get the parametric distance from the incident ray's origin. Notice that parametric distance is not or...
Definition HitDetail.h:148
FaceTopology getFaceTopology() const
Definition HitDetail.h:158
HitDetail & setHitIntrinsics(const Primitive *primitive, const math::Vector3R &uvw, real rayT, uint64 faceID=NO_FACE_ID, FaceTopology faceTopology=FaceTopology(EFaceTopology::General))
Set essential attributes that are independent to the coordinate system.
Definition HitDetail.cpp:23
math::Vector3R getPos(ECoordSys coordSys=ECoordSys::World) const
Definition HitDetail.h:103
math::Vector3R getdNdV(ECoordSys coordSys=ECoordSys::World) const
Definition HitDetail.h:133
math::Vector3R getGeometryNormal(ECoordSys coordSys=ECoordSys::World) const
Definition HitDetail.h:113
const HitInfo & getHitInfo(ECoordSys coordSys=ECoordSys::World) const
Definition HitDetail.h:173
const math::Basis3R & getGeometryBasis(ECoordSys coordSys=ECoordSys::World) const
Definition HitDetail.h:138
General information for a ray-primitive intersection.
Definition HitInfo.h:18
math::Vector3R getShadingNormal() const
Definition HitInfo.h:68
math::Vector3R getdNdU() const
Definition HitInfo.h:88
const math::Basis3R & getShadingBasis() const
Definition HitInfo.h:104
math::Vector3R getPos() const
Definition HitInfo.h:63
const math::Basis3R & getGeometryBasis() const
Definition HitInfo.h:98
math::Vector3R getGeometryNormal() const
Definition HitInfo.h:73
math::Vector3R getdPdU() const
Definition HitInfo.h:78
math::Vector3R getdNdV() const
Definition HitInfo.h:93
math::Vector3R getdPdV() const
Definition HitInfo.h:83
A physical shape in the scene.
Definition Primitive.h:23
Manipulate a value type where each bit is a binary flag.
Definition TBitFlags.h:17
Miscellaneous math utilities.
The root for all renderer implementations.
Definition EEngineProject.h:6
constexpr auto enum_size()
Definition utility.h:179
TEnumFlags< EFaceTopology > FaceTopology
Definition FaceTopology.h:36
ECoordSys
Definition ECoordSys.h:7
constexpr auto enum_to_value(const EnumType enumValue)
Definition utility.h:166