6#include <Common/assertion.h>
7#include <Common/config.h>
8#include <Common/primitive_type.h>
94 std::byte m_cache[PH_HIT_PROBE_CACHE_BYTES];
96 uint8 m_hitDetailChannel;
98 bool m_hasBaseHitSet{
false};
106 , m_hitRayT (
std::numeric_limits<real>::max())
109 , m_hitDetailChannel(0)
114 m_hitStack.
push(hitTarget);
119 m_hitStack.
push(hitTarget);
123 m_hasBaseHitSet =
true;
135 m_hitStack.
push(newTopHit);
140 PH_ASSERT(m_hasBaseHitSet);
141 m_hitRayT = newHitRayT;
146 m_hitDetailChannel = channel;
151 return m_hitDetailChannel;
156 return m_hitStack.
top();
161 PH_ASSERT(m_hasBaseHitSet);
168 static_assert(std::is_trivially_copyable_v<T>,
169 "target type is not cacheable");
170 static_assert(
sizeof(T) <=
sizeof(m_cache),
171 "not enough cache to store target type, consider increasing config.PH_HIT_PROBE_CACHE_BYTES");
173 PH_ASSERT_MSG(m_cacheHead +
sizeof(T) <=
sizeof(m_cache),
174 "ran out of cache, consider increasing config.PH_HIT_PROBE_CACHE_BYTES \n"
175 "m_cacheHead = " + std::to_string(m_cacheHead) +
"\n" +
176 "sizeof(T) = " + std::to_string(
sizeof(T)) +
"\n" +
177 "sizeof(m_cache) = " + std::to_string(
sizeof(m_cache)));
179 std::memcpy(m_cache + m_cacheHead, &data,
sizeof(T));
180 m_cacheHead +=
sizeof(T);
186 static_assert(std::is_trivially_copyable_v<T>);
187 static_assert(
sizeof(T) <=
sizeof(m_cache));
189 PH_ASSERT_IN_RANGE_INCLUSIVE(m_cacheHead,
sizeof(T),
sizeof(m_cache));
190 m_cacheHead -=
sizeof(T);
193 std::memcpy(&data, m_cache + m_cacheHead,
sizeof(T));
Detailed information regarding a ray-primitive intersection.
Definition HitDetail.h:26
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
const Intersectable * getTopHit() const
Definition HitProbe.h:154
void replaceTopHit(const Intersectable *newTopHit)
Definition HitProbe.h:132
uint8 getChannel() const
Definition HitProbe.h:149
void pushCache(const T &data)
Definition HitProbe.h:166
void popHit()
Removes the most recent hit target from the stack.
Definition HitProbe.h:127
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
HitProbe()
Definition HitProbe.h:104
T popCache()
Definition HitProbe.h:184
void setChannel(uint8 channel)
Definition HitProbe.h:144
void pushIntermediateHit(const Intersectable *hitTarget)
Adds a hit target that will participate in hit detail's calculation to the stack.
Definition HitProbe.h:112
void replaceBaseHitRayT(real newHitRayT)
Definition HitProbe.h:138
void calcHitDetail(const Ray &ray, HitDetail *out_detail) const
Calculates basic hit information using this probe. The information is calculated using a copy of the ...
Definition HitProbe.cpp:16
void pushBaseHit(const Intersectable *hitTarget, real hitRayT)
Adds the first hit target to the stack. Similar to pushIntermediateHit(), except the parametric hit d...
Definition HitProbe.h:117
bool isOnDefaultChannel() const
Definition HitProbe.cpp:43
real getHitRayT() const
Definition HitProbe.h:159
An object in the scene that a ray can intersect with.
Definition Intersectable.h:31
Represents a ray in space.
Definition Ray.h:21
void push(U &&item)
Adds an item to the stack. The item originally at the target index will be overwritten.
Definition TArrayStack.ipp:19
T & top()
Definition TArrayStack.ipp:35
void pop()
Removes the top item from the stack. The item originally at the target index is still alive after thi...
Definition TArrayStack.ipp:27
The root for all renderer implementations.
Definition EEngineProject.h:6