Divide Framework 0.1
A free and open-source 3D Framework under heavy development
Loading...
Searching...
No Matches
SceneEnvironmentProbePool.h
Go to the documentation of this file.
1/*
2Copyright (c) 2018 DIVIDE-Studio
3Copyright (c) 2009 Ionut Cava
4
5This file is part of DIVIDE Framework.
6
7Permission is hereby granted, free of charge, to any person obtaining a copy
8of this software
9and associated documentation files (the "Software"), to deal in the Software
10without restriction,
11including without limitation the rights to use, copy, modify, merge, publish,
12distribute, sublicense,
13and/or sell copies of the Software, and to permit persons to whom the
14Software is furnished to do so,
15subject to the following conditions:
16
17The above copyright notice and this permission notice shall be included in
18all copies or substantial portions of the Software.
19
20THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21IMPLIED,
22INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
23PARTICULAR PURPOSE AND NONINFRINGEMENT.
24IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
25DAMAGES OR OTHER LIABILITY,
26WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
27IN CONNECTION WITH THE SOFTWARE
28OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29
30*/
31
32#pragma once
33#ifndef DVD_SCENE_ENVIRONMENT_PROBE_POOL_H_
34#define DVD_SCENE_ENVIRONMENT_PROBE_POOL_H_
35
38
39namespace Divide {
40class SceneGraphNode;
41
42namespace GFX {
43 class CommandBuffer;
44 struct MemoryBarrierCommand;
45}
46
48
49class Camera;
50class Pipeline;
51class ShaderProgram;
52class EnvironmentProbeComponent;
53using EnvironmentProbeList = vector<EnvironmentProbeComponent*>;
54
55class GFXDevice;
56class SceneRenderState;
58public:
59 enum class ComputationStages : U8 {
63 COUNT
64 };
65
68
69 static void Prepare(GFX::CommandBuffer& bufferInOut);
70 static void UpdateSkyLight(GFXDevice& context, GFX::CommandBuffer& bufferInOut, GFX::MemoryBarrierCommand& memCmdInOut);
71 static void OnStartup(GFXDevice& context);
72 static void OnShutdown(GFXDevice& context);
73 static RenderTargetHandle ReflectionTarget() noexcept;
74 static RenderTargetHandle PrefilteredTarget() noexcept;
75 static RenderTargetHandle IrradianceTarget() noexcept;
76 static RenderTargetHandle BRDFLUTTarget() noexcept;
77
78 const EnvironmentProbeList& sortAndGetLocked(const vec3<F32>& position);
79 const EnvironmentProbeList& getLocked() const noexcept;
80
83
84 void lockProbeList() const noexcept;
85 void unlockProbeList() const noexcept;
86
87 void prepareDebugData();
89
90 void onNodeUpdated(const SceneGraphNode& node) noexcept;
91
92 static U16 AllocateSlice(bool lock);
93 static void UnlockSlice(U16 slice) noexcept;
94
95 static bool ProbesDirty() noexcept { return s_probesDirty; }
96 static void ProbesDirty(const bool state) noexcept { s_probesDirty = state; }
97
98 static void OnTimeOfDayChange(const SceneEnvironmentProbePool& probePool) noexcept;
99
100 [[nodiscard]] static bool DebuggingSkyLight() noexcept;
101 static void DebuggingSkyLight(bool state) noexcept;
102
103 [[nodiscard]] static bool SkyLightNeedsRefresh() noexcept;
104 static void SkyLightNeedsRefresh(bool state) noexcept;
105
106 [[nodiscard]] static U16 SkyProbeLayerIndex() noexcept;
107
108protected:
110 void createDebugView(U16 layerIndex);
111 static void ProcessEnvironmentMap(U16 layerID, bool highPriority);
112
113private:
114 static void ProcessEnvironmentMapInternal(const U16 layerID, ComputationStages& stage, GFX::CommandBuffer& bufferInOut);
115 static void PrefilterEnvMap(const U16 layerID, GFX::CommandBuffer& bufferInOut);
116 static void ComputeIrradianceMap(const U16 layerID, GFX::CommandBuffer& bufferInOut);
117
118protected:
121
122 static vector<DebugView_ptr> s_debugViews;
123 static bool s_probesDirty;
126
127private:
128 struct ProbeSlice {
129 bool _available = true;
130 bool _locked = false;
131 };
132
133 static std::array<ProbeSlice, Config::MAX_REFLECTIVE_PROBES_PER_PASS> s_availableSlices;
144 static bool s_lutTextureDirty;
145};
146
148
149} //namespace Divide
150
151#endif //DVD_SCENE_ENVIRONMENT_PROBE_POOL_H_
#define POINTER_RW(...)
Convenience method to add a class member with public read access and write access.
#define FWD_DECLARE_MANAGED_STRUCT(T)
#define FWD_DECLARE_MANAGED_CLASS(T)
Rough around the edges Adapter pattern abstracting the actual rendering API and access to the GPU.
Definition: GFXDevice.h:215
Scene & parentScene() noexcept
void onNodeUpdated(const SceneGraphNode &node) noexcept
static RenderTargetHandle ReflectionTarget() noexcept
static void UpdateSkyLight(GFXDevice &context, GFX::CommandBuffer &bufferInOut, GFX::MemoryBarrierCommand &memCmdInOut)
void registerProbe(EnvironmentProbeComponent *probe)
static std::array< ProbeSlice, Config::MAX_REFLECTIVE_PROBES_PER_PASS > s_availableSlices
static Handle< ShaderProgram > s_lutComputeShader
const EnvironmentProbeList & getLocked() const noexcept
static RenderTargetHandle BRDFLUTTarget() noexcept
const EnvironmentProbeList & sortAndGetLocked(const vec3< F32 > &position)
static void Prepare(GFX::CommandBuffer &bufferInOut)
static Handle< ShaderProgram > s_irradianceComputeShader
static Handle< ShaderProgram > s_previewShader
static RenderTargetHandle IrradianceTarget() noexcept
static void PrefilterEnvMap(const U16 layerID, GFX::CommandBuffer &bufferInOut)
static void ProcessEnvironmentMapInternal(const U16 layerID, ComputationStages &stage, GFX::CommandBuffer &bufferInOut)
static void OnStartup(GFXDevice &context)
static void ProbesDirty(const bool state) noexcept
static vector< DebugView_ptr > s_debugViews
static void ComputeIrradianceMap(const U16 layerID, GFX::CommandBuffer &bufferInOut)
static void OnTimeOfDayChange(const SceneEnvironmentProbePool &probePool) noexcept
static Handle< ShaderProgram > s_prefilterComputeShader
static RenderTargetHandle PrefilteredTarget() noexcept
static void OnShutdown(GFXDevice &context)
void unregisterProbe(const EnvironmentProbeComponent *probe)
static void UnlockSlice(U16 slice) noexcept
static void ProcessEnvironmentMap(U16 layerID, bool highPriority)
Handle console commands that start with a forward slash.
Definition: AIProcessor.cpp:7
uint8_t U8
std::shared_mutex SharedMutex
Definition: SharedMutex.h:43
eastl::vector< Type > vector
Definition: Vector.h:42
uint16_t U16
vector< EnvironmentProbeComponent * > EnvironmentProbeList