Vulkan Schnee 0.0.1 (22840dc8)
High-performance rendering engine
Loading...
Searching...
No Matches
DirectionalLightComponent.h
1#pragma once
2
3#include "Engine/Component/LogicComponent.h"
4#include <glm/glm.hpp>
5
6#include <string>
7
8namespace Engine::Components
9{
13 class DirectionalLight : public Logic
14 {
15 public:
16 static constexpr bool IsUnique = true;
17 static constexpr const char * ComponentName = "DirectionalLight";
18
28 Entities::Scene * owningScene,
29 const glm::vec3 & color = glm::vec3( 1.0f ),
30 float intensity = 1.0f,
31 bool castsShadows = true,
32 float angularDiameterDegrees = 0.53f
33 );
34
35 [[nodiscard]] std::string getComponentName() const override;
36
37 void beginPlay() override;
38 void endPlay() override;
39
44 [[nodiscard]] const glm::vec3 & getColor() const { return color_; }
45
50 [[nodiscard]] float getIntensity() const { return intensity_; }
51
56 [[nodiscard]] bool isEnabled() const { return enabled_; }
57
62 [[nodiscard]] bool castsShadows() const { return castsShadows_; }
63
68 [[nodiscard]] float getAngularDiameterDegrees() const { return angularDiameterDegrees_; }
69
74 [[nodiscard]] const glm::vec3 & getDirectionOverride() const { return directionOverride_; }
75
80 [[nodiscard]] bool hasDirectionOverride() const { return hasDirectionOverride_; }
81
86 [[nodiscard]] const std::string & getDebugName() const { return debugName_; }
87
92 [[nodiscard]] const std::string & getDisableReason() const { return disableReason_; }
93
98 [[nodiscard]] bool hasDisableReason() const { return !disableReason_.empty(); }
99
104 void setColor( const glm::vec3 & color );
105
110 void setIntensity( float intensity );
111
116 void setEnabled( bool enabled );
117
123
128 void setAngularDiameterDegrees( float angularDiameterDegrees );
129
134 void setDirectionOverride( const glm::vec3 & direction );
135
140
145 void setDebugName( std::string name );
146
151 void setDisableReason( std::string reason );
152
157
158 private:
159 [[nodiscard]] bool hasActiveEnabledConflict() const;
161 void syncEcsData() const;
162
163 std::string debugName_;
164 std::string disableReason_;
165 glm::vec3 color_{ 1.0f };
166 float intensity_ = 1.0f;
167 bool enabled_ = true;
168 bool castsShadows_ = true;
170 glm::vec3 directionOverride_{ 0.0f, -1.0f, 0.0f };
172 };
173} // namespace Engine::Components
const glm::vec3 & getDirectionOverride() const
Gets the explicit light direction override.
bool castsShadows() const
Checks whether this light casts shadows.
static constexpr const char * ComponentName
Component type name.
void setCastsShadows(bool castsShadows)
Enables or disables shadow casting and syncs ECS data.
void setAngularDiameterDegrees(float angularDiameterDegrees)
Sets the apparent angular diameter and syncs ECS data.
void setDisableReason(std::string reason)
Sets the reason this light is disabled.
void clearDirectionOverride()
Clears the explicit light direction override and syncs ECS data.
void setEnabled(bool enabled)
Enables or disables the light and syncs ECS data.
void setIntensity(float intensity)
Sets the light intensity and syncs ECS data.
static constexpr bool IsUnique
Only one directional light may be active per entity.
void clearDisableReason()
Clears the stored disable reason.
bool hasDisableReason() const
Checks whether a disable reason is set.
const std::string & getDebugName() const
Gets the optional debug name appended to the component name.
void endPlay() override
Called when the component is removed or the game ends.
void beginPlay() override
Called when the component is added to the scene or the game starts.
const glm::vec3 & getColor() const
Gets the light color multiplier.
bool isEnabled() const
Checks whether this light is enabled for rendering.
DirectionalLight(Entities::Scene *owningScene, const glm::vec3 &color=glm::vec3(1.0f), float intensity=1.0f, bool castsShadows=true, float angularDiameterDegrees=0.53f)
Creates a directional light component.
std::string getComponentName() const override
Gets the component type name for debugging/UI.
float getAngularDiameterDegrees() const
Gets the apparent angular diameter used for light softness.
void setDirectionOverride(const glm::vec3 &direction)
Sets an explicit normalized light direction and syncs ECS data.
bool hasDirectionOverride() const
Checks whether an explicit light direction override is active.
const std::string & getDisableReason() const
Gets the reason this light was disabled.
float getIntensity() const
Gets the light intensity.
void setDebugName(std::string name)
Sets the debug name appended to the component name.
void setColor(const glm::vec3 &color)
Sets the light color multiplier and syncs ECS data.
Logic(Entities::Scene *owningScene)
Constructs a logic component owned by a scene.
Owns scene entities, actor lifetime, and the scene graph root.
Definition Scene.h:84