Divide Framework 0.1
A free and open-source 3D Framework under heavy development
Loading...
Searching...
No Matches
DirectionalLightComponent.cpp
Go to the documentation of this file.
1
2
12
13namespace Divide {
14
15namespace {
16 constexpr F32 g_defaultLightDistance = 500.0f;
17}
18
19DirectionalLightComponent::DirectionalLightComponent(SceneGraphNode* sgn, PlatformContext& context)
21 Light(sgn, -1, LightType::DIRECTIONAL, *sgn->sceneGraph()->parentScene().lightPool())
22{
23 range(g_defaultLightDistance);
24
25 _shadowProperties._lightDetails.z = 0.00001f;
26 csmSplitCount(context.config().rendering.shadowMapping.csm.splitCount);
27
28 EditorComponentField directionField = {};
29 directionField._name = "Direction";
30 directionField._dataGetter = [this](void* dataOut) noexcept { static_cast<vec3<F32>*>(dataOut)->set(directionCache()); };
31 directionField._dataSetter = [this](const void* data) { setDirection(*static_cast<const vec3<F32>*>(data)); };
33 directionField._readOnly = lockDirection();
34 directionField._basicType = PushConstantType::VEC3;
35
36 editorComponent().registerField(MOV(directionField));
37
38 for (U8 cascade = 0; cascade < Config::Lighting::MAX_CSM_SPLITS_PER_LIGHT; ++cascade) {
39 EditorComponentField sceneFitField = {};
40 Util::StringFormat( sceneFitField._name, "Fit CSM To AABB [ {} ]", cascade);
41 sceneFitField._data = &_csmUseSceneAABBFit[cascade];
43 sceneFitField._readOnly = cascade >= csmSplitCount();
44 sceneFitField._basicType = PushConstantType::BOOL;
45
46 editorComponent().registerField(MOV(sceneFitField));
47 }
48
49 EditorComponentField csmNearClipField = {};
50 csmNearClipField._name = "CSM Near Clip Offset";
51 csmNearClipField._data = &_csmNearClipOffset;
52 csmNearClipField._range = { -g_defaultLightDistance, g_defaultLightDistance };
54 csmNearClipField._readOnly = false;
55 csmNearClipField._basicType = PushConstantType::FLOAT;
56
57 editorComponent().registerField(MOV(csmNearClipField));
58
59 EditorComponentField showConeField = {};
60 showConeField._name = "Show direction cone";
61 showConeField._data = &_showDirectionCone;
63 showConeField._readOnly = false;
64 showConeField._basicType = PushConstantType::BOOL;
65
66 editorComponent().registerField(MOV(showConeField));
67
68 registerFields(editorComponent());
69
70 BoundingBox bb = {};
71 bb.setMin(-g_defaultLightDistance * 0.5f);
72 bb.setMax(-g_defaultLightDistance * 0.5f);
74
75 _positionCache.set(VECTOR3_ZERO);
76 _feedbackContainers.resize(csmSplitCount());
77}
78
79void DirectionalLightComponent::lockDirection(const bool state) noexcept {
80 _lockDirection = state;
81
82 TransformComponent* tComp = _parentSGN->get<TransformComponent>();
83 if (tComp != nullptr) {
84 tComp->editorLockRotation(lockDirection());
85 }
86}
87
88void DirectionalLightComponent::OnData(const ECS::CustomEvent& data) {
89 SGNComponent::OnData(data);
90
92 updateCache(data);
94 const SceneGraphNode::Flags flag = static_cast<SceneGraphNode::Flags>(data._flag);
95 if (flag == SceneGraphNode::Flags::SELECTED) {
96 const bool state = data._dataPair._first == 1u;
97 drawImpostor(state);
98 }
99 }
100}
101
102void DirectionalLightComponent::setDirection(const vec3<F32>& direction) {
103 TransformComponent* tComp = _parentSGN->get<TransformComponent>();
104 if (tComp != nullptr) {
105 tComp->setDirection(direction);
106 }
107}
108
109} //namespace Divide
#define MOV(...)
static void setBounds(SceneNode &node, const BoundingBox &aabb, const vec3< F32 > &worldOffset={})
Definition: SceneNode.h:231
void setMin(const vec3< F32 > &min) noexcept
void setMax(const vec3< F32 > &max) noexcept
A light object placed in the scene at a certain position.
Definition: Light.h:58
Configuration & config() noexcept
T & getNode() noexcept
constexpr U8 MAX_CSM_SPLITS_PER_LIGHT
Used for CSM or PSSM to determine the maximum number of frustum splits.
Definition: config.h:159
Str StringFormat(const char *fmt, Args &&...args)
Handle console commands that start with a forward slash.
Definition: AIProcessor.cpp:7
uint8_t U8
void lockDirection(const bool state) noexcept
DirectionalLightComponent(SceneGraphNode *sgn, PlatformContext &context)
vector< FeedBackContainer > _feedbackContainers
SGNComponent::Registrar< T, C > BaseComponentType
Definition: SGNComponent.h:207
LightType
The different types of lights supported.
void setDirection(const vec3< F32 > &direction)
static const vec3< F32 > VECTOR3_ZERO
Definition: MathVectors.h:1434
Divide::Configuration::Rendering::ShadowMapping::CSMSettings csm
struct Divide::Configuration::Rendering::ShadowMapping shadowMapping
struct Divide::Configuration::Rendering rendering
DELEGATE_STD< void, void * > _dataGetter
DELEGATE_STD< void, const void * > _dataSetter
vec2< F32 > _range
Used by slider_type as a min / max range or dropdown as selected_index / count.
EditorComponentFieldType _type
DataPair _dataPair
Definition: SGNComponent.h:77
Divide::U32 _flag
Definition: SGNComponent.h:67