Plasma Engine  2.0
Loading...
Searching...
No Matches
ReflectionProbeMapping.h
1#pragma once
2
3#include <RendererCore/RendererCorePCH.h>
4
5#include <RendererCore/Lights/Implementation/ReflectionProbeData.h>
6#include <RendererFoundation/RendererFoundationDLL.h>
7
11{
12 enum class Type
13 {
17 };
18
20 Type m_Type;
21};
22
25{
26public:
29 plReflectionProbeMapping(plUInt32 uiAtlasSize);
31
34
37
40
44
47
51
56 plInt32 GetReflectionIndex(plReflectionProbeId probe, bool bForExtraction = false) const;
57
60 plGALTextureHandle GetTexture() const { return m_hReflectionSpecularTexture; }
61
65
67 void PreExtraction();
68
70 void AddWeight(plReflectionProbeId probe, float fPriority);
71
73 void PostExtraction();
74
76
77public:
79
80private:
81 struct plProbeMappingFlags
82 {
83 using StorageType = plUInt8;
84
85 enum Enum
86 {
87 SkyLight = plProbeFlags::SkyLight,
88 HasCustomCubeMap = plProbeFlags::HasCustomCubeMap,
89 Sphere = plProbeFlags::Sphere,
90 Box = plProbeFlags::Box,
91 Dynamic = plProbeFlags::Dynamic,
92 Dirty = PL_BIT(5),
93 Usable = PL_BIT(6),
94 Default = 0
95 };
96
97 struct Bits
98 {
99 StorageType SkyLight : 1;
100 StorageType HasCustomCubeMap : 1;
101 StorageType Sphere : 1;
102 StorageType Box : 1;
103 StorageType Dynamic : 1;
104 StorageType Dirty : 1;
105 StorageType Usable : 1;
106 };
107 };
108
109 //PL_DECLARE_FLAGS_OPERATORS(plProbeMappingFlags);
110
111 struct SortedProbes
112 {
113 PL_DECLARE_POD_TYPE();
114
115 PL_ALWAYS_INLINE bool operator<(const SortedProbes& other) const
116 {
117 if (m_fPriority > other.m_fPriority) // we want to sort descending (higher priority first)
118 return true;
119
120 return m_uiIndex < other.m_uiIndex;
121 }
122
123 plReflectionProbeId m_uiIndex;
124 float m_fPriority = 0.0f;
125 };
126
127 struct ProbeDataInternal
128 {
130 plInt32 m_uiReflectionIndex = -1;
131 float m_fPriority = 0.0f;
133 };
134
135private:
136 void MapProbe(plReflectionProbeId id, plInt32 iReflectionIndex);
137 void UnmapProbe(plReflectionProbeId id);
138
139private:
140 plDynamicArray<ProbeDataInternal> m_RegisteredProbes;
141 plReflectionProbeId m_SkyLight;
142
143 plUInt32 m_uiAtlasSize = 32;
145
146 // GPU Data
147 plGALTextureHandle m_hReflectionSpecularTexture;
148
149 // Cleared every frame:
150 plDynamicArray<SortedProbes> m_SortedProbes; // All probes exiting in the scene, sorted by priority.
151 plDynamicArray<SortedProbes> m_ActiveProbes; // Probes that are currently mapped in the atlas.
152 plDynamicArray<plInt32> m_UnusedProbeSlots; // Probe slots are are currently unused in the atlas.
153 plDynamicArray<SortedProbes> m_AddProbes; // Probes that should be added to the atlas
154};
Definition DynamicArray.h:81
Definition Event.h:177
Definition RendererFoundationDLL.h:411
This class creates a reflection probe atlas and controls the mapping of added probes to the available...
Definition ReflectionProbeMapping.h:25
plReflectionProbeMapping(plUInt32 uiAtlasSize)
Creates a reflection probe atlas and mapping of the given size.
Definition ReflectionProbeMapping.cpp:8
void AddProbe(plReflectionProbeId probe, plBitflags< plProbeFlags > flags)
Adds a probe that will be considered for mapping into the atlas.
Definition ReflectionProbeMapping.cpp:41
plGALTextureHandle GetTexture() const
Returns the atlas texture.
Definition ReflectionProbeMapping.h:60
void PostExtraction()
Should be called in the PostExtraction phase. This will compute the best probe mapping and potentiall...
Definition ReflectionProbeMapping.cpp:140
void PreExtraction()
Should be called in the PreExtraction phase. This will reset all probe weights.
Definition ReflectionProbeMapping.cpp:115
plInt32 GetReflectionIndex(plReflectionProbeId probe, bool bForExtraction=false) const
Returns the index at which a given probe is mapped.
Definition ReflectionProbeMapping.cpp:105
void UpdateProbe(plReflectionProbeId probe, plBitflags< plProbeFlags > flags)
Marks previously added probe as dirty and potentially changes its flags.
Definition ReflectionProbeMapping.cpp:56
void ProbeUpdateFinished(plReflectionProbeId probe)
Should be called once a requested plReflectionProbeMappingEvent::Type::ProbeUpdateRequested event has...
Definition ReflectionProbeMapping.cpp:68
void RemoveProbe(plReflectionProbeId probe)
Removes a probe. If the probe was mapped, plReflectionProbeMappingEvent::Type::ProbeUnmapped will be ...
Definition ReflectionProbeMapping.cpp:86
void AddWeight(plReflectionProbeId probe, float fPriority)
Adds weight to a probe. Should be called during extraction of the probe. The mapping will map the pro...
Definition ReflectionProbeMapping.cpp:134
The plBitflags class allows you to work with type-safe bitflags.
Definition Bitflags.h:82
Definition ReflectionProbeMapping.h:98
Event generated on mapping changes.
Definition ReflectionProbeMapping.h:11
Type
Definition ReflectionProbeMapping.h:13
@ ProbeMapped
The given probe was mapped to the atlas.
@ ProbeUnmapped
The given probe was unmapped from the atlas.
@ ProbeUpdateRequested
The given probe needs to be updated after which plReflectionProbeMapping::ProbeUpdateFinished must be...