Divide Framework 0.1
A free and open-source 3D Framework under heavy development
Loading...
Searching...
No Matches
SceneShaderData.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_SHADER_DATA_H_
34#define DVD_SCENE_SHADER_DATA_H_
35
39
40namespace Divide
41{
42
43class GFXDevice;
44
45namespace GFX
46{
47 class CommandBuffer;
48 struct MemoryBarrierCommand;
49};
50
51FWD_DECLARE_MANAGED_CLASS(ShaderBuffer);
52
54constexpr U16 GLOBAL_PROBE_COUNT = 512u;
55
57{
59 {
60 // w - altitude
61 vec4<F32> _sunDirection = {-0.3f, -0.8f, 0.5f, 1.f};
62 // w - azimuth
64 // x,y,z - direction, w - speed
66 // x - elapsed game time (ms), x - elapsed app time, z - material debug flag, w - unused
71 };
72
73 public:
74 explicit SceneShaderData(GFXDevice& context);
75
76 void appData(const U32 elapsedGameTimeMS, const U32 elapsedAppTimeMS,const MaterialDebugFlag materialDebugFlag)
77 {
78 if (!COMPARE(_sceneBufferData._appData.x, to_F32(elapsedGameTimeMS)))
79 {
80 _sceneBufferData._appData.x = to_F32(elapsedGameTimeMS);
81 _sceneDataDirty = true;
82 }
83 if (!COMPARE(_sceneBufferData._appData.y, to_F32(elapsedAppTimeMS)))
84 {
85 _sceneBufferData._appData.y = to_F32(elapsedAppTimeMS);
86 _sceneDataDirty = true;
87 }
88 if (!COMPARE(_sceneBufferData._appData.z, to_F32(materialDebugFlag)))
89 {
90 _sceneBufferData._appData.z = to_F32(materialDebugFlag);
91 _sceneDataDirty = true;
92 }
93 }
94
95 void sunDetails(const vec3<F32>& sunDirection, const FColour3& colour, const F32 altitude, const F32 azimuth) noexcept
96 {
97 if (_sceneBufferData._sunDirection.xyz != sunDirection ||
101 {
102 _sceneBufferData._sunDirection.set( sunDirection, altitude );
103 _sceneBufferData._sunColour.set(colour, azimuth);
104 _sceneDataDirty = true;
105 }
106 }
107
108 void fogDetails(const FogDetails& details) noexcept
109 {
110 if (_sceneBufferData._fogDetails != details)
111 {
113 _sceneDataDirty = true;
114 }
115 }
116
117 void fogDensity(F32 density, F32 scatter) noexcept
118 {
119 CLAMP_01(density);
120 CLAMP_01(scatter);
123 {
126 _sceneDataDirty = true;
127 }
128 }
129
130 void windDetails(const F32 directionX, const F32 directionY, const F32 directionZ, const F32 speed) noexcept
131 {
132 if (!COMPARE(_sceneBufferData._windDetails.x, directionX) ||
133 !COMPARE(_sceneBufferData._windDetails.y, directionY) ||
134 !COMPARE(_sceneBufferData._windDetails.z, directionZ) ||
136 {
137 _sceneBufferData._windDetails.set(directionX, directionY, directionZ, speed);
138 _sceneDataDirty = true;
139 }
140 }
141
142 bool waterDetails(const U8 index, const WaterBodyData& data) noexcept
143 {
144 if (index < GLOBAL_WATER_BODIES_COUNT && _sceneBufferData._waterEntities[index] != data)
145 {
146 _sceneBufferData._waterEntities[index] = data;
147 _sceneDataDirty = true;
148 return true;
149 }
150
151 return false;
152 }
153
154 bool probeState(const U16 index, const bool state) noexcept
155 {
156 if (index < GLOBAL_PROBE_COUNT)
157 {
158 ProbeData& data = _probeData[index];
159 const F32 fState = state ? 1.f : 0.f;
160 if (!COMPARE(data._positionW.w, fState))
161 {
162 data._positionW.w = fState;
163 _probeDataDirty = true;
164 return true;
165 }
166 }
167
168 return false;
169 }
170
171 bool probeData(const U16 index, const vec3<F32>& center, const vec3<F32>& halfExtents) noexcept
172 {
173 if (index < GLOBAL_PROBE_COUNT)
174 {
175 ProbeData& data = _probeData[index];
176 if (data._positionW.xyz != center ||
177 data._halfExtents.xyz != halfExtents)
178 {
179 data._positionW.xyz = center;
180 data._halfExtents.xyz = halfExtents;
181 _probeDataDirty = true;
182 }
183 return true;
184 }
185
186 return false;
187 }
188
190
191 private:
192 using ProbeBufferData = std::array<ProbeData, GLOBAL_PROBE_COUNT>;
193
195 bool _sceneDataDirty = true;
196 bool _probeDataDirty = true;
200 ShaderBuffer_uptr _sceneShaderData;
201 ShaderBuffer_uptr _probeShaderData;
202};
203} //namespace Divide
204
205#endif //DVD_SCENE_SHADER_DATA_H_
#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
bool probeData(const U16 index, const vec3< F32 > &center, const vec3< F32 > &halfExtents) noexcept
ProbeBufferData _probeData
std::array< ProbeData, GLOBAL_PROBE_COUNT > ProbeBufferData
void fogDetails(const FogDetails &details) noexcept
bool probeState(const U16 index, const bool state) noexcept
SceneShaderBufferData _sceneBufferData
void windDetails(const F32 directionX, const F32 directionY, const F32 directionZ, const F32 speed) noexcept
ShaderBuffer_uptr _probeShaderData
bool waterDetails(const U8 index, const WaterBodyData &data) noexcept
void appData(const U32 elapsedGameTimeMS, const U32 elapsedAppTimeMS, const MaterialDebugFlag materialDebugFlag)
void updateSceneDescriptorSet(GFX::CommandBuffer &bufferInOut, GFX::MemoryBarrierCommand &memCmdInOut)
void sunDetails(const vec3< F32 > &sunDirection, const FColour3 &colour, const F32 altitude, const F32 azimuth) noexcept
ShaderBuffer_uptr _sceneShaderData
Generic scene data that doesn't change per shader.
void fogDensity(F32 density, F32 scatter) noexcept
void set(const T *v) noexcept
set the 4 components of the vector manually using a source pointer to a (large enough) array
Definition: MathVectors.h:1241
vec3< T > xyz
Definition: MathVectors.h:1374
FColour4 WHITE
Random stuff added for convenience.
Definition: Colours.cpp:8
Handle console commands that start with a forward slash.
Definition: AIProcessor.cpp:7
::value constexpr void CLAMP_01(T &n) noexcept
Definition: MathHelper.inl:120
MaterialDebugFlag
Definition: MaterialEnums.h:37
uint8_t U8
constexpr F32 to_F32(const T value)
uint16_t U16
constexpr U16 GLOBAL_PROBE_COUNT
bool COMPARE(T X, U Y) noexcept
constexpr U8 GLOBAL_WATER_BODIES_COUNT
uint32_t U32
static const vec4< F32 > VECTOR4_ZERO
Definition: MathVectors.h:1435
vec4< F32 > _colourAndDensity
Definition: SceneState.h:74
vec4< F32 > _colourSunScatter
Definition: SceneState.h:75
vec4< F32 > _positionW
Definition: SceneState.h:68
vec4< F32 > _halfExtents
Definition: SceneState.h:69
WaterBodyData _waterEntities[GLOBAL_WATER_BODIES_COUNT]