Photon Engine 2.0.0-beta
A physically based renderer.
Loading...
Searching...
No Matches
HitInfo.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
8#include <Common/assertion.h>
9
10namespace ph
11{
12
13class Primitive;
14
17class HitInfo final
18{
19public:
20 HitInfo();
21
22 void setAttributes(
23 const math::Vector3R& pos,
24 const math::Vector3R& geometryNormal,
25 const math::Vector3R& shadingNormal);
26
27 void setDerivatives(
28 const math::Vector3R& dPdU,
29 const math::Vector3R& dPdV,
30 const math::Vector3R& dNdU,
31 const math::Vector3R& dNdV);
32
33 void computeBases();
34
35 math::Vector3R getPos() const;
38 math::Vector3R getdPdU() const;
39 math::Vector3R getdPdV() const;
40 math::Vector3R getdNdU() const;
41 math::Vector3R getdNdV() const;
42 const math::Basis3R& getGeometryBasis() const;
43 const math::Basis3R& getShadingBasis() const;
44
45private:
46 math::Vector3R m_pos;
47
48 math::Vector3R m_dPdU;
49 math::Vector3R m_dPdV;
50 math::Vector3R m_dNdU;
51 math::Vector3R m_dNdV;
52
53 math::Basis3R m_geometryBasis;
54 math::Basis3R m_shadingBasis;
55
56#if PH_DEBUG
57 bool m_isBasesComputed{false};
58#endif
59};
60
61// In-header Implementations:
62
64{
65 return m_pos;
66}
67
69{
70 return m_shadingBasis.getYAxis();
71}
72
74{
75 return m_geometryBasis.getYAxis();
76}
77
79{
80 return m_dPdU;
81}
82
84{
85 return m_dPdV;
86}
87
89{
90 return m_dNdU;
91}
92
94{
95 return m_dNdV;
96}
97
99{
100 PH_ASSERT(m_isBasesComputed);
101 return m_geometryBasis;
102}
103
105{
106 PH_ASSERT(m_isBasesComputed);
107 return m_shadingBasis;
108}
109
111 const math::Vector3R& pos,
112 const math::Vector3R& geometryNormal,
113 const math::Vector3R& shadingNormal)
114{
115 m_pos = pos;
116 m_geometryBasis.setYAxis(geometryNormal);
117 m_shadingBasis.setYAxis(shadingNormal);
118
119#if PH_DEBUG
120 m_isBasesComputed = false;
121#endif
122}
123
125 const math::Vector3R& dPdU,
126 const math::Vector3R& dPdV,
127 const math::Vector3R& dNdU,
128 const math::Vector3R& dNdV)
129{
130 m_dPdU = dPdU;
131 m_dPdV = dPdV;
132 m_dNdU = dNdU;
133 m_dNdV = dNdV;
134
135#if PH_DEBUG
136 m_isBasesComputed = false;
137#endif
138}
139
141{
142 // FIXME: currently this is a hacky way to avoid crossing two parallel vectors
143 // (this condition can rarely happen)
144 // (which will result in 0-length vector and cause normalization to fail)
145
146 m_geometryBasis.setXAxis(m_geometryBasis.getYAxis().cross(m_dPdU));
147 if(m_geometryBasis.getXAxis().lengthSquared() > 0.0_r)
148 {
149 m_geometryBasis.renormalizeXAxis();
150 m_geometryBasis.setZAxis(m_geometryBasis.getXAxis().cross(m_geometryBasis.getYAxis()));
151 }
152 else
153 {
154 m_geometryBasis = math::Basis3R::makeFromUnitY(m_geometryBasis.getYAxis());
155 }
156
157 m_shadingBasis.setXAxis(m_shadingBasis.getYAxis().cross(m_dNdU));
158 if(m_shadingBasis.getXAxis().lengthSquared() > 0.0_r)
159 {
160 m_shadingBasis.renormalizeXAxis();
161 m_shadingBasis.setZAxis(m_shadingBasis.getXAxis().cross(m_shadingBasis.getYAxis()));
162 }
163 else
164 {
165 m_shadingBasis = math::Basis3R::makeFromUnitY(m_shadingBasis.getYAxis());
166 }
167
168 PH_ASSERT_MSG(m_geometryBasis.getYAxis().isFinite() && m_shadingBasis.getYAxis().isFinite(), "\n"
169 "m_geometryBasis.getYAxis() = " + m_geometryBasis.getYAxis().toString() + "\n"
170 "m_shadingBasis.getYAxis() = " + m_shadingBasis.getYAxis().toString() + "\n");
171
172#if PH_DEBUG
173 m_isBasesComputed = true;
174#endif
175}
176
177}// end namespace ph
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
void computeBases()
Definition HitInfo.h:140
HitInfo()
Definition HitInfo.cpp:11
const math::Basis3R & getGeometryBasis() const
Definition HitInfo.h:98
math::Vector3R getGeometryNormal() const
Definition HitInfo.h:73
void setDerivatives(const math::Vector3R &dPdU, const math::Vector3R &dPdV, const math::Vector3R &dNdU, const math::Vector3R &dNdV)
Definition HitInfo.h:124
math::Vector3R getdPdU() const
Definition HitInfo.h:78
math::Vector3R getdNdV() const
Definition HitInfo.h:93
math::Vector3R getdPdV() const
Definition HitInfo.h:83
void setAttributes(const math::Vector3R &pos, const math::Vector3R &geometryNormal, const math::Vector3R &shadingNormal)
Definition HitInfo.h:110
TVector3< T > getYAxis() const
Definition TOrthonormalBasis3.ipp:272
static TOrthonormalBasis3 makeFromUnitY(const TVector3< real > &unitYAxis)
Definition TOrthonormalBasis3.ipp:16
TVector3< T > getXAxis() const
Definition TOrthonormalBasis3.ipp:266
TOrthonormalBasis3 & setXAxis(const TVector3< T > &axis)
Definition TOrthonormalBasis3.ipp:229
TOrthonormalBasis3 & setZAxis(const TVector3< T > &axis)
Definition TOrthonormalBasis3.ipp:245
TOrthonormalBasis3 & renormalizeXAxis()
Definition TOrthonormalBasis3.ipp:205
TOrthonormalBasis3 & setYAxis(const TVector3< T > &axis)
Definition TOrthonormalBasis3.ipp:237
TVector3 cross(const TVector3 &rhs) const
Definition TVector3.ipp:75
std::string toString() const
Definition TArithmeticArrayBase.ipp:825
bool isFinite() const
Definition TArithmeticArrayBase.ipp:585
T lengthSquared() const
Definition TVectorNBase.ipp:44
Miscellaneous math utilities.
The root for all renderer implementations.
Definition EEngineProject.h:6