Photon Engine 2.0.0-beta
A physically based renderer.
Loading...
Searching...
No Matches
TPhotonMap.h
Go to the documentation of this file.
1#pragma once
2
6#include "Math/TVector3.h"
7
8#include <Common/assertion.h>
9#include <Common/primitive_type.h>
10#include <Common/logging.h>
11
12#include <cstddef>
13#include <type_traits>
14#include <vector>
15
16namespace ph
17{
18
22template<CPhoton Photon>
23class TPhotonMapInfo final
24{
25public:
26 std::size_t numPaths = 0;
27 uint32 minPathLength = 1;
29};
30
33template
34<
35 CPhoton Photon,
36 math::CIndexedPointKdtreeItemStorage<Photon> PhotonStorage = std::vector<Photon>
37>
38class TPhotonMap final
39{
40public:
42 {
43 static_assert(std::is_base_of_v<TPhoton<Photon>, Photon>);
44
45 math::Vector3R operator () (const Photon& photon) const
46 {
47 static_assert(Photon::template has<EPhotonData::Pos>());
48
49 return photon.template get<EPhotonData::Pos>();
50 }
51 };
52
55
57
60 std::size_t numPaths = 0;
61
65 uint32 minPathLength = 1;
66
71
79 const std::size_t viewPathLength,
80 const std::size_t minFullPathLength,
81 const std::size_t maxFullPathLength) const
82 {
83 PH_ASSERT_LE(minFullPathLength, maxFullPathLength);
84 const auto minFullPathLengthFromMap = viewPathLength + minPathLength;
85 const auto maxFullPathLengthFromMap = viewPathLength + maxPathLength;
86 return maxFullPathLength >= minFullPathLengthFromMap &&
87 minFullPathLength <= maxFullPathLengthFromMap;
88 }
89
92 void find(
93 const math::Vector3R& position,
94 const real kernelRadius,
95 std::vector<Photon>& photons) const
96 {
97 map.findWithinRange(position, kernelRadius, photons);
98 }
99
103 void find(
104 const math::Vector3R& position,
105 const real kernelRadius,
106 const std::size_t viewPathLength,
107 const std::size_t minFullPathLength,
108 const std::size_t maxFullPathLength,
109 std::vector<Photon>& photons) const
110 {
111 if(!canContribute(viewPathLength, minFullPathLength, maxFullPathLength))
112 {
113 return;
114 }
115
116 if constexpr(Photon::template has<EPhotonData::PathLength>())
117 {
118 const auto kernelRadius2 = kernelRadius * kernelRadius;
119
121 position,
122 kernelRadius2,
123 [
124 this, kernelRadius2, viewPathLength, minFullPathLength, maxFullPathLength,
125 &position, &photons
126 ]
127 (const Photon& photon)
128 {
129 const auto pos = PhotonCenterCalculator{}(photon);
130 const auto dist2 = (pos - position).lengthSquared();
131 const auto fullPathLen = viewPathLength + photon.template get<EPhotonData::PathLength>();
132 if(dist2 < kernelRadius2 &&
133 minFullPathLength <= fullPathLen && fullPathLen <= maxFullPathLength)
134 {
135 photons.push_back(photon);
136 }
137 });
138 }
139 else
140 {
141 // No path length available, this is an error.
142 PH_DEFAULT_LOG(ErrorOnce,
143 "The photon type in this photon map contains no path length info. Cannot find "
144 "photon for the specified full path length in [{}, {}]. This photon map "
145 "contains path length in [{}, {}].",
146 minFullPathLength, maxFullPathLength, minPathLength, maxPathLength);
147 }
148 }
149
151 {
152 return {
153 .numPaths = numPaths,
154 .minPathLength = minPathLength,
155 .maxPathLength = maxPathLength};
156 }
157};
158
159}// end namespace ph
static constexpr uint32 DEFAULT_MAX_PATH_LENGTH
Definition PMCommonParams.h:15
Default photon map type. Should be adequate for most cases.
Definition TPhotonMap.h:39
uint32 maxPathLength
Definition TPhotonMap.h:70
uint32 minPathLength
Definition TPhotonMap.h:65
math::TIndexedPointKdtree< Photon, uint32, PhotonCenterCalculator, PhotonStorage > MapType
Definition TPhotonMap.h:53
bool canContribute(const std::size_t viewPathLength, const std::size_t minFullPathLength, const std::size_t maxFullPathLength) const
Definition TPhotonMap.h:78
MapType map
Definition TPhotonMap.h:56
TPhotonMapInfo< Photon > getInfo() const
Definition TPhotonMap.h:150
void find(const math::Vector3R &position, const real kernelRadius, std::vector< Photon > &photons) const
Find all photons in a radius.
Definition TPhotonMap.h:92
void find(const math::Vector3R &position, const real kernelRadius, const std::size_t viewPathLength, const std::size_t minFullPathLength, const std::size_t maxFullPathLength, std::vector< Photon > &photons) const
Find all photons in a radius that can contribute given the path requirements.
Definition TPhotonMap.h:103
std::size_t numPaths
Definition TPhotonMap.h:60
Carries common informatiom for a photon map.
Definition TPhotonMap.h:24
uint32 minPathLength
Definition TPhotonMap.h:27
std::size_t numPaths
Definition TPhotonMap.h:26
uint32 maxPathLength
Definition TPhotonMap.h:28
Definition TIndexedPointKdtree.h:42
void findWithinRange(const math::Vector3R &location, const real searchRadius, std::vector< Item > &results) const
Definition TIndexedPointKdtree.h:120
void rangeTraversal(const math::Vector3R &location, const real squaredSearchRadius, ItemHandler itemHandler) const
Definition TIndexedPointKdtree.h:232
Definition TPhoton.h:24
Definition TIndexedPointKdtree.h:25
The root for all renderer implementations.
Definition EEngineProject.h:6
Definition TPhotonMap.h:42
math::Vector3R operator()(const Photon &photon) const
Definition TPhotonMap.h:45
Definition TIndexedPointKdtree.h:47