Divide Framework 0.1
A free and open-source 3D Framework under heavy development
Loading...
Searching...
No Matches
ShadowMap.h
Go to the documentation of this file.
1/*
2 Copyright (c) 2018 DIVIDE-Studio
3 Copyright (c) 2009 Ionut Cava
4
5 This file is part of DIVIDE Framework.
6
7 Permission is hereby granted, free of charge, to any person obtaining a copy
8 of this software
9 and associated documentation files (the "Software"), to deal in the Software
10 without restriction,
11 including without limitation the rights to use, copy, modify, merge, publish,
12 distribute, sublicense,
13 and/or sell copies of the Software, and to permit persons to whom the
14 Software is furnished to do so,
15 subject to the following conditions:
16
17 The above copyright notice and this permission notice shall be included in
18 all copies or substantial portions of the Software.
19
20 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21 IMPLIED,
22 INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
23 PARTICULAR PURPOSE AND NONINFRINGEMENT.
24 IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
25 DAMAGES OR OTHER LIABILITY,
26 WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
27 IN CONNECTION WITH THE SOFTWARE
28 OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29
30 */
31
32#pragma once
33#ifndef DVD_SHADOW_MAP_H_
34#define DVD_SHADOW_MAP_H_
35
37
38namespace Divide {
39
40enum class ShadowType : U8 {
41 SINGLE = 0,
42 CSM,
43 CUBEMAP,
44 COUNT
45};
46
47namespace Names {
48 static const char* shadowType[] = {
49 "SINGLE", "CSM", "CUBEMAP", "UNKNOWN"
50 };
51}
52
53class Light;
54class Camera;
55class ShadowMapInfo;
56class SceneRenderState;
57
58enum class LightType : U8;
59
60namespace GFX {
61 class CommandBuffer;
62 struct MemoryBarrierCommand;
63}
64
65class LightPool;
66class SceneState;
67class PlatformContext;
69
70public:
71 virtual ~ShadowMapGenerator() = default;
72
73protected:
74 explicit ShadowMapGenerator(GFXDevice& context, ShadowType type) noexcept;
75
76 friend class ShadowMap;
77 virtual void render(const Camera& playerCamera, Light& light, U16 lightIndex, GFX::CommandBuffer& bufferInOut, GFX::MemoryBarrierCommand& memCmdInOut) = 0;
78
79 virtual void updateMSAASampleCount([[maybe_unused]] const U8 sampleCount) { }
80
81protected:
84};
85
89 public:
90 static constexpr U8 MAX_SHADOW_FRAME_LIFETIME = 32u;
91 static constexpr U8 WORLD_AO_LAYER_INDEX = (Config::Lighting::MAX_SHADOW_CASTING_DIRECTIONAL_LIGHTS * Config::Lighting::MAX_CSM_SPLITS_PER_LIGHT) ;
92
93 public:
94 // Init and destroy buffers, shaders, etc
95 static void initShadowMaps(GFXDevice& context);
96 static void destroyShadowMaps(GFXDevice& context);
97
98 static void reset();
99
100 // Reset usage flags and set render targets back to default settings
101 static void resetShadowMaps();
102
103 static void bindShadowMaps(GFX::CommandBuffer& bufferInOut);
104 static U32 getLightLayerRequirements(const Light& light);
105 static bool freeShadowMapOffset(const Light& light);
106 static bool markShadowMapsUsed(Light& light);
107 static bool generateShadowMaps(const Camera& playerCamera, Light& light, GFX::CommandBuffer& bufferInOut, GFX::MemoryBarrierCommand& memCmdInOut);
108
109 static ShadowType getShadowTypeForLightType(LightType type) noexcept;
110 static LightType getLightTypeForShadowType(ShadowType type) noexcept;
111
112 static const RenderTargetHandle& getShadowMap(LightType type);
113 static const RenderTargetHandle& getShadowMapCache(LightType type);
114
115 static const RenderTargetHandle& getShadowMap(ShadowType type);
116 static const RenderTargetHandle& getShadowMapCache(ShadowType type);
117
118 static void setDebugViewLight(GFXDevice& context, Light* light);
119
120 static void setMSAASampleCount(ShadowType type, U8 sampleCount);
121
122 static vector<Camera*>& shadowCameras(const ShadowType type) noexcept { return s_shadowCameras[to_base(type)]; }
123
124 static void generateWorldAO(const Camera& playerCamera, GFX::CommandBuffer& bufferInOut, GFX::MemoryBarrierCommand& memCmdInOut );
125
126 protected:
127 static bool commitLayerRange(Light& light);
128 static bool freeShadowMapOffsetLocked(const Light& light);
129
130 protected:
132 I64 _lightGUID = -1;
133 U16 _lifetime = MAX_SHADOW_FRAME_LIFETIME;
134 };
137 static std::array<LayerLifetimeMask, to_base(ShadowType::COUNT)> s_shadowMapLifetime;
139
140 static std::array<RenderTargetHandle, to_base(ShadowType::COUNT)> s_shadowMaps;
141 static std::array<RenderTargetHandle, to_base(ShadowType::COUNT)> s_shadowMapCaches;
143
146 static std::array<U16, to_base(ShadowType::COUNT)> s_shadowPassIndex;
147 static std::array<ShadowCameraPool, to_base(ShadowType::COUNT)> s_shadowCameras;
148};
149
150} // namespace Divide
151
152#endif //DVD_SHADOW_MAP_H_
#define FWD_DECLARE_MANAGED_STRUCT(T)
#define NOINITVTABLE
Rough around the edges Adapter pattern abstracting the actual rendering API and access to the GPU.
Definition: GFXDevice.h:215
A light object placed in the scene at a certain position.
Definition: Light.h:58
virtual ~ShadowMapGenerator()=default
const ShadowType _type
Definition: ShadowMap.h:83
virtual void updateMSAASampleCount(const U8 sampleCount)
Definition: ShadowMap.h:79
virtual void render(const Camera &playerCamera, Light &light, U16 lightIndex, GFX::CommandBuffer &bufferInOut, GFX::MemoryBarrierCommand &memCmdInOut)=0
All the information needed for a single light's shadowmap.
Definition: ShadowMap.h:88
static Light * s_shadowPreviewLight
Definition: ShadowMap.h:144
static std::array< RenderTargetHandle, to_base(ShadowType::COUNT)> s_shadowMapCaches
Definition: ShadowMap.h:141
static vector< DebugView_ptr > s_debugViews
Definition: ShadowMap.h:142
static std::array< RenderTargetHandle, to_base(ShadowType::COUNT)> s_shadowMaps
Definition: ShadowMap.h:140
static std::array< ShadowCameraPool, to_base(ShadowType::COUNT)> s_shadowCameras
Definition: ShadowMap.h:147
static vector< std::unique_ptr< ShadowMapGenerator > > s_shadowMapGenerators
Definition: ShadowMap.h:138
vector< Camera * > ShadowCameraPool
Definition: ShadowMap.h:145
vector< ShadowLayerData > LayerLifetimeMask
Definition: ShadowMap.h:135
static Mutex s_shadowMapUsageLock
Definition: ShadowMap.h:136
static vector< Camera * > & shadowCameras(const ShadowType type) noexcept
Definition: ShadowMap.h:122
static std::array< U16, to_base(ShadowType::COUNT)> s_shadowPassIndex
Definition: ShadowMap.h:146
static std::array< LayerLifetimeMask, to_base(ShadowType::COUNT)> s_shadowMapLifetime
Definition: ShadowMap.h:137
static const char * shadowType[]
Definition: ShadowMap.h:48
Handle console commands that start with a forward slash.
Definition: AIProcessor.cpp:7
std::mutex Mutex
Definition: SharedMutex.h:40
uint8_t U8
eastl::vector< Type > vector
Definition: Vector.h:42
uint16_t U16
LightType
The different types of lights supported.
ShadowType
Definition: ShadowMap.h:40
int64_t I64
uint32_t U32
constexpr auto to_base(const Type value) -> Type