Nameless Engine
Loading...
Searching...
No Matches
SpotlightNode.h
1#pragma once
2
3// Custom.
4#include "game/node/SpatialNode.h"
5#include "math/GLMath.hpp"
6#include "shader/VulkanAlignmentConstants.hpp"
7#include "shader/general/resource/LightingShaderResourceManager.h"
8#include "misc/shapes/Cone.h"
9#include "render/general/resource/shadow/ShadowMapHandle.h"
10
11#include "SpotlightNode.generated.h"
12
13namespace ne RNAMESPACE() {
15 class RCLASS(Guid("e7b203dc-0f47-43f2-b26d-3b09a5ec1661")) SpotlightNode : public SpatialNode {
16 // Renderer reads shadow map handle and index into viewProjection matrix array.
17 friend class Renderer;
18
19 public:
21
27 SpotlightNode(const std::string& sNodeName);
28
29 virtual ~SpotlightNode() override = default;
30
36 static constexpr float getMaxLightConeAngle() { return maxConeAngle; }
37
43 void setLightColor(const glm::vec3& color);
44
50 void setLightIntensity(float intensity);
51
57 void setLightDistance(float distance);
58
66 void setLightInnerConeAngle(float innerConeAngle);
67
75 void setLightOuterConeAngle(float outerConeAngle);
76
82 glm::vec3 getLightColor() const;
83
89 float getLightIntensity() const;
90
96 float getLightDistance() const;
97
103 float getLightInnerConeAngle() const;
104
110 float getLightOuterConeAngle() const;
111
123 std::pair<std::mutex, Cone>* getShape();
124
125 protected:
133 virtual void onAfterDeserialized() override;
134
147 virtual void onSpawning() override;
148
158 virtual void onDespawning() override;
159
169 virtual void onWorldLocationRotationScaleChanged() override;
170
171 private:
174 SpotlightShaderData() = default;
175
180 alignas(iVkMat4Alignment) glm::mat4 viewProjectionMatrix = glm::identity<glm::mat4>();
181
183 alignas(iVkVec4Alignment) glm::vec4 position = glm::vec4(0.0F, 0.0F, 0.0F, 1.0F);
184
186 alignas(iVkVec4Alignment) glm::vec4 direction = glm::vec4(0.0F, 0.0F, 0.0F, 0.0F);
187
189 alignas(iVkVec4Alignment) glm::vec4 color = glm::vec4(1.0F, 1.0F, 1.0F, 1.0F);
190
192 alignas(iVkScalarAlignment) float intensity = 1.0F;
193
195 alignas(iVkScalarAlignment) float distance = 1.0F;
196
203 alignas(iVkScalarAlignment) float cosInnerConeAngle = 0.0F;
204
211 alignas(iVkScalarAlignment) float cosOuterConeAngle = 0.0F;
212
214 alignas(iVkScalarAlignment) float coneBottomRadius = 0.0F;
215
217 alignas(iVkScalarAlignment) unsigned int iShadowMapIndex = 0;
218 };
219
221 struct ShaderData {
222 ShaderData() = default;
223
226 ShadowPassDataGroup() = default;
227
229 std::unique_ptr<ShaderLightArraySlot> pSlot;
230
233 };
234
236 std::unique_ptr<ShaderLightArraySlot> pSpotlightArraySlot;
237
240
243 };
244
252 ShadowMapHandle* getShadowMapHandle() const;
253
260 unsigned int getIndexIntoShadowPassInfoShaderArray();
261
267 void onShadowMapArrayIndexChanged(unsigned int iNewIndexIntoArray);
268
275 void* onStartedUpdatingShaderData();
276
281 void onFinishedUpdatingShaderData();
282
289 void* onStartedUpdatingShadowPassData();
290
295 void onFinishedUpdatingShadowPassData();
296
302 void recalculateShadowMappingShaderData();
303
310 void recalculateAndMarkShaderDataToBeCopiedToGpu();
311
318 void markShaderDataToBeCopiedToGpu();
319
325 void recalculateShape();
326
328 std::pair<std::recursive_mutex, ShaderData> mtxShaderData;
329
335 std::pair<std::mutex, Cone> mtxShape;
336
342 std::unique_ptr<ShadowMapHandle> pShadowMapHandle;
343
345 RPROPERTY(Serialize)
346 glm::vec3 color = glm::vec3(1.0F, 1.0F, 1.0F);
347
349 RPROPERTY(Serialize)
350 float intensity = 1.0F;
351
353 RPROPERTY(Serialize)
354 float distance = 15.0F; // NOLINT: seems like a pretty good default value
355
360 RPROPERTY(Serialize)
361 float innerConeAngle = 25.0F;
362
367 RPROPERTY(Serialize)
368 float outerConeAngle = 45.0F;
369
371 static constexpr float maxConeAngle = 80.0F; // NOLINT: max angle that won't cause any visual issues
372
373 ne_SpotlightNode_GENERATED
374 };
375}
376
377File_SpotlightNode_GENERATED
Definition: GuidProperty.h:30
Definition: Renderer.h:43
Definition: SerializeProperty.h:42
Definition: ShadowMapHandle.h:23
Definition: SpatialNode.h:12
Definition: SpotlightNode.h:15
std::pair< std::mutex, Cone > mtxShape
Definition: SpotlightNode.h:335
std::unique_ptr< ShadowMapHandle > pShadowMapHandle
Definition: SpotlightNode.h:342
static constexpr float getMaxLightConeAngle()
Definition: SpotlightNode.h:36
std::pair< std::recursive_mutex, ShaderData > mtxShaderData
Definition: SpotlightNode.h:328
Definition: LightingShaderResourceManager.h:38
ShadowPassLightShaderInfo shaderData
Definition: SpotlightNode.h:232
std::unique_ptr< ShaderLightArraySlot > pSlot
Definition: SpotlightNode.h:229
Definition: SpotlightNode.h:221
ShadowPassDataGroup shadowPassData
Definition: SpotlightNode.h:239
std::unique_ptr< ShaderLightArraySlot > pSpotlightArraySlot
Definition: SpotlightNode.h:236
SpotlightShaderData shaderData
Definition: SpotlightNode.h:242
Definition: SpotlightNode.h:173