Photon Engine 2.0.0-beta
A physically based renderer.
Loading...
Searching...
No Matches
SurfaceHit.h
Go to the documentation of this file.
1#pragma once
2
3#include "Core/HitProbe.h"
4#include "Core/HitDetail.h"
5#include "Core/Ray.h"
6#include "Math/math.h"
7#include "Utility/TBitFlags.h"
8
9#include <Common/assertion.h>
10#include <Common/primitive_type.h>
11
12namespace ph
13{
14
15class SurfaceOptics;
16class VolumeOptics;
17class Emitter;
18
19namespace detail
20{
21
23
28
29}// end namespace detail
30
51
53
55
58class SurfaceHit final
59{
60public:
61 SurfaceHit();
62
68 const Ray& ray,
69 const HitProbe& probe,
70 SurfaceHitReason reason);
71
73 const Ray& ray,
74 const HitProbe& probe,
75 const HitDetail& detail,
76 SurfaceHitReason reason);
77
78 SurfaceHit switchChannel(uint32 newChannel) const;
79
85 bool reintersect(const Ray& ray, HitProbe& probe) const;
86
87 bool hasSurfaceOptics() const;
88 bool hasInteriorOptics() const;
89 bool hasExteriorOptics() const;
90
91 const HitDetail& getDetail() const;
93
97 const Ray& getRay() const;
98
101 const Ray& getIncidentRay() const;
102
103 const Time& getTime() const;
104 math::Vector3R getPos() const;
107
108 const Emitter* getSurfaceEmitter() const;
109 const SurfaceOptics* getSurfaceOptics() const;
110 const VolumeOptics* getInteriorOptics() const;
111 const VolumeOptics* getExteriorOptics() const;
112
113private:
114 Ray m_ray;
115 HitProbe m_recordedProbe;
116 HitDetail m_detail;
117 SurfaceHitReason m_reason;
118};
119
120// In-header Implementations:
121
123 : m_ray {}
124 , m_recordedProbe{}
125 , m_detail {}
126 , m_reason {}
127{}
128
130 const Ray& ray,
131 const HitProbe& probe,
132 SurfaceHitReason reason)
133
134 : m_ray {ray}
135 , m_recordedProbe{probe}
136 , m_detail {}
137 , m_reason {reason}
138{
139 probe.calcFullHitDetail(ray, &m_detail);
140}
141
143 const Ray& ray,
144 const HitProbe& probe,
145 const HitDetail& detail,
146 const SurfaceHitReason reason)
147
148 : m_ray {ray}
149 , m_recordedProbe{probe}
150 , m_detail {detail}
151 , m_reason {reason}
152{}
153
154inline bool SurfaceHit::reintersect(const Ray& ray, HitProbe& probe) const
155{
156 return m_recordedProbe.reintersect(ray, probe, getRay());
157}
158
159inline const HitDetail& SurfaceHit::getDetail() const
160{
161 return m_detail;
162}
163
165{
166 return m_reason;
167}
168
169inline const Ray& SurfaceHit::getRay() const
170{
171 PH_ASSERT(!m_reason.hasExactly(ESurfaceHitReason::Invalid));
172 return m_ray;
173}
174
175inline const Ray& SurfaceHit::getIncidentRay() const
176{
177 PH_ASSERT(m_reason.has(ESurfaceHitReason::IncidentRay));
178 return getRay();
179}
180
181inline const Time& SurfaceHit::getTime() const
182{
183 return m_ray.getTime();
184}
185
187{
188 return m_detail.getPos();
189}
190
192{
193 return m_detail.getShadingNormal();
194}
195
197{
198 return m_detail.getGeometryNormal();
199}
200
201}// end namespace ph
#define PH_DEFINE_INLINE_ENUM_FLAG_OPERATORS(EnumType)
Defines operator | and operator & for EnumType.
Definition TBitFlags.h:146
An electromagnetic energy emitting source. The emitted energy can be captured by a Receiver.
Definition Emitter.h:68
Detailed information regarding a ray-primitive intersection.
Definition HitDetail.h:26
math::Vector3R getShadingNormal(ECoordSys coordSys=ECoordSys::World) const
Definition HitDetail.h:108
math::Vector3R getPos(ECoordSys coordSys=ECoordSys::World) const
Definition HitDetail.h:103
math::Vector3R getGeometryNormal(ECoordSys coordSys=ECoordSys::World) const
Definition HitDetail.h:113
Lightweight ray intersection testing and reporting object. If an intersection is found,...
Definition HitProbe.h:27
bool reintersect(const Ray &ray, HitProbe &probe, const Ray &srcRay) const
Intersect the intersected object again with a different ray. The operation is done using a copy of th...
Definition HitProbe.cpp:34
void calcFullHitDetail(const Ray &ray, HitDetail *out_detail) const
Calculates full hit information using this probe. The information is calculated using a copy of the c...
Definition HitProbe.cpp:26
Represents a ray in space.
Definition Ray.h:21
const Time & getTime() const
Get the associated time of this ray.
Definition Ray.h:204
General information about a ray-surface intersection event.
Definition SurfaceHit.h:59
math::Vector3R getGeometryNormal() const
Definition SurfaceHit.h:196
bool reintersect(const Ray &ray, HitProbe &probe) const
Intersect the intersected object again with a different ray.
Definition SurfaceHit.h:154
math::Vector3R getShadingNormal() const
Definition SurfaceHit.h:191
const VolumeOptics * getExteriorOptics() const
Definition SurfaceHit.cpp:79
const Ray & getRay() const
Definition SurfaceHit.h:169
bool hasInteriorOptics() const
Definition SurfaceHit.cpp:49
bool hasSurfaceOptics() const
Definition SurfaceHit.cpp:43
const Ray & getIncidentRay() const
Convenient method for getRay() where getReason() contains ESurfaceHitReason::IncidentRay.
Definition SurfaceHit.h:175
const Emitter * getSurfaceEmitter() const
Definition SurfaceHit.cpp:61
SurfaceHit()
Definition SurfaceHit.h:122
const SurfaceOptics * getSurfaceOptics() const
Definition SurfaceHit.cpp:67
const HitDetail & getDetail() const
Definition SurfaceHit.h:159
SurfaceHit switchChannel(uint32 newChannel) const
Definition SurfaceHit.cpp:28
const VolumeOptics * getInteriorOptics() const
Definition SurfaceHit.cpp:73
math::Vector3R getPos() const
Definition SurfaceHit.h:186
const Time & getTime() const
Definition SurfaceHit.h:181
SurfaceHitReason getReason() const
Definition SurfaceHit.h:164
bool hasExteriorOptics() const
Definition SurfaceHit.cpp:55
Describes how light interacts with a surface.
Definition SurfaceOptics.h:17
Manipulate a value type where each bit is a binary flag.
Definition TBitFlags.h:17
constexpr bool hasExactly(const FlagsSet &flagsSet) const
Checks whether this instance contains exactly the specified flags. No more, no less.
Definition TBitFlags.ipp:99
constexpr bool has(Input singleFlag) const
Checks whether this single flag is fully contained.
Definition TBitFlags.ipp:133
Definition Time.h:9
Definition VolumeOptics.h:20
Miscellaneous math utilities.
constexpr auto shr_sampled_pos_bits
Definition SurfaceHit.h:26
constexpr auto shr_incident_ray_bits
Definition SurfaceHit.h:25
uint8 SurfaceHitReasonIntType
Definition SurfaceHit.h:22
constexpr auto shr_sampled_dir_bits
Definition SurfaceHit.h:27
constexpr auto shr_unknown_bits
Definition SurfaceHit.h:24
consteval UIntType flag_bit()
Definition math.h:537
The root for all renderer implementations.
Definition EEngineProject.h:6
ESurfaceHitReason
Definition SurfaceHit.h:32