CSEngine
Loading...
Searching...
No Matches
CSE::LightComponent Class Reference
Inheritance diagram for CSE::LightComponent:
CSE::SComponent CSE::CameraBase CSE::SObject CSE::SISComponent CSE::VariableBinder

Public Types

enum  LIGHT { NONE = 0 , DIRECTIONAL = 1 , POINT = 2 , SPOT = 3 }
 
- Public Types inherited from CSE::CameraBase
enum  BackgroundType { NONE = 0 , SOLID = 1 , SKYBOX = 2 }
 

Public Member Functions

 COMPONENT_DEFINE_CONSTRUCTOR (LightComponent)
 
void Exterminate () override
 
void Init () override
 
void Tick (float elapsedTime) override
 
void SetLightType (LIGHT type)
 
void SetDirection (const vec4 &direction) const
 
void SetColor (const vec3 &color) const
 
LIGHT GetType () const
 
vec4 GetDirection (const vec4 &direction) const
 
vec3 GetColor () const
 
void SetLightRadius (float radius) const
 
void SetAttenuationFactor (const vec3 &att) const
 
void SetAttenuationFactor (float Kc, float Kl, float Kq) const
 
void SetSunrising (bool active)
 
SLightGetLight () const
 
void SetShadow (bool isActive)
 
SComponentClone (SGameObject *object) override
 
void SetValue (std::string name_str, Arguments value) override
 
std::string PrintValue () const override
 
const mat4GetLightProjectionMatrix () const
 
const mat4GetLightViewMatrix () const
 
CameraMatrixStruct GetCameraMatrixStruct () const override
 
SFrameBufferGetFrameBuffer () const override
 
bool IsShadow () const
 
void BindShadow (const GLProgramHandle &handle, int handleIndex, int index) const
 
void RenderBackground () const override
 
- Public Member Functions inherited from CSE::SComponent
 SComponent (std::string classType, SGameObject *gameObject)
 
 SComponent (const SComponent &src)
 
void Start () override
 
virtual void CopyReference (SComponent *src, std::map< SGameObject *, SGameObject * > lists_obj, std::map< SComponent *, SComponent * > lists_comp)
 
virtual auto GetComponent () -> SObject *
 
void SetValue (std::string name_str, Arguments value) override
 
std::string PrintValue () const override
 
void SetGameObject (SGameObject *object)
 
virtual SGameObjectGetGameObject () const
 
virtual bool GetIsEnable () const
 
virtual void SetIsEnable (bool is_enable)
 
std::string GetClassType () const
 
void SetClassType (std::string type)
 
- Public Member Functions inherited from CSE::SObject
 SObject (bool isRegister)
 
virtual void SetUndestroyable (bool enable)
 
virtual void Destroy ()
 
virtual void __FORCE_DESTROY__ ()
 
virtual std::string GenerateMeta ()
 
std::string GetHash () const
 
virtual void SetHash (std::string &hash)
 
- Public Member Functions inherited from CSE::SISComponent
 SISComponent (const SISComponent &src)=default
 
- Public Member Functions inherited from CSE::CameraBase
virtual BackgroundType GetBackgroundType ()
 

Public Attributes

LIGHT m_type = DIRECTIONAL
 

Additional Inherited Members

- Protected Types inherited from CSE::VariableBinder
typedef std::vector< std::string > Arguments
 
- Protected Attributes inherited from CSE::SComponent
SGameObjectgameObject = nullptr
 
bool isEnable = true
 
std::string m_classType
 
- Protected Attributes inherited from CSE::SObject
std::string m_hash
 

Detailed Description

Definition at line 13 of file LightComponent.h.

Member Enumeration Documentation

◆ LIGHT

enum CSE::LightComponent::LIGHT

Definition at line 16 of file LightComponent.h.

16 {
17 NONE = 0, DIRECTIONAL = 1, POINT = 2, SPOT = 3
18 };

Member Function Documentation

◆ BindShadow()

void LightComponent::BindShadow ( const GLProgramHandle handle,
int  handleIndex,
int  index 
) const

Definition at line 190 of file LightComponent.cpp.

190 {
191 if(m_frameBuffer == nullptr || m_disableShadow) return;
192
193 m_depthTexture->Bind(handle.Uniforms.LightShadowMap + index, index);
194 auto matrix = m_lightViewMatrix * m_lightProjectionMatrix;
195 glUniformMatrix4fv(handle.Uniforms.LightMatrix + handleIndex, 1, 0, matrix.Pointer());
196}

◆ Clone()

SComponent * LightComponent::Clone ( SGameObject object)
overridevirtual

Reimplemented from CSE::SComponent.

Definition at line 140 of file LightComponent.cpp.

140 {
141 INIT_COMPONENT_CLONE(LightComponent, clone);
142
143 clone->m_type = m_type;
144 clone->m_disableShadow = m_disableShadow;
145
146 clone->m_near = m_near;
147 clone->m_far = m_far;
148 clone->SetLightType(clone->m_type);
149
150 return clone;
151}

◆ Exterminate()

void LightComponent::Exterminate ( )
overridevirtual

Implements CSE::SObject.

Definition at line 22 of file LightComponent.cpp.

22 {
23 CORE->GetCore(LightMgr)->Remove(this);
24 SAFE_DELETE(m_light);
25 auto resMgr = CORE->GetCore(ResMgr);
26 if(m_frameBuffer != nullptr) resMgr->Remove(m_frameBuffer);
27}

◆ GetCameraMatrixStruct()

CameraMatrixStruct LightComponent::GetCameraMatrixStruct ( ) const
overridevirtual

Implements CSE::CameraBase.

Definition at line 198 of file LightComponent.cpp.

198 {
199 const auto& position = gameObject->GetTransform();
200 return { m_lightViewMatrix, m_lightProjectionMatrix, position->m_position };
201}

◆ GetColor()

vec3 LightComponent::GetColor ( ) const

Definition at line 132 of file LightComponent.cpp.

132 {
133 return m_light->color;
134}

◆ GetDirection()

vec4 LightComponent::GetDirection ( const vec4 direction) const

Definition at line 128 of file LightComponent.cpp.

128 {
129 return m_light->direction;
130}

◆ GetFrameBuffer()

SFrameBuffer * LightComponent::GetFrameBuffer ( ) const
overridevirtual

Implements CSE::CameraBase.

Definition at line 203 of file LightComponent.cpp.

203 {
204 return m_frameBuffer;
205}

◆ GetLight()

SLight * CSE::LightComponent::GetLight ( ) const
inline

Definition at line 52 of file LightComponent.h.

52 {
53 return m_light;
54 }

◆ GetLightProjectionMatrix()

const mat4 & LightComponent::GetLightProjectionMatrix ( ) const

Definition at line 182 of file LightComponent.cpp.

182 {
183 return m_lightProjectionMatrix;
184}

◆ GetLightViewMatrix()

const mat4 & LightComponent::GetLightViewMatrix ( ) const

Definition at line 186 of file LightComponent.cpp.

186 {
187 return m_lightViewMatrix;
188}

◆ GetType()

LightComponent::LIGHT LightComponent::GetType ( ) const

Definition at line 124 of file LightComponent.cpp.

124 {
125 return m_type;
126}

◆ Init()

void LightComponent::Init ( )
overridevirtual

Implements CSE::SISComponent.

Definition at line 29 of file LightComponent.cpp.

29 {
30 if(m_disableShadow) return;
31 SetDepthMap();
32}

◆ IsShadow()

bool LightComponent::IsShadow ( ) const

Definition at line 207 of file LightComponent.cpp.

207 {
208 return !m_disableShadow;
209}

◆ PrintValue()

std::string LightComponent::PrintValue ( ) const
overridevirtual

Implements CSE::VariableBinder.

Definition at line 169 of file LightComponent.cpp.

169 {
170 PRINT_START("component");
171
172 PRINT_VALUE(m_type, static_cast<int>(m_type));
173 PRINT_VALUE(m_disableShadow, m_disableShadow ? 1 : 0);
174 PRINT_VALUE(m_near, m_near);
175 PRINT_VALUE(m_far, m_far);
176 vec4 m_direction = m_light->direction;
177 PRINT_VALUE_VEC4(m_direction);
178
179 PRINT_END("component");
180}

◆ RenderBackground()

void CSE::LightComponent::RenderBackground ( ) const
inlineoverridevirtual

Implements CSE::CameraBase.

Definition at line 78 of file LightComponent.h.

78{};

◆ SetAttenuationFactor() [1/2]

void LightComponent::SetAttenuationFactor ( const vec3 att) const

Definition at line 86 of file LightComponent.cpp.

86 {
87 m_light->att = att;
88}

◆ SetAttenuationFactor() [2/2]

void LightComponent::SetAttenuationFactor ( float  Kc,
float  Kl,
float  Kq 
) const

Definition at line 90 of file LightComponent.cpp.

90 {
91 SetAttenuationFactor(vec3{ Kc, Kl, Kq });
92}

◆ SetColor()

void LightComponent::SetColor ( const vec3 color) const

Definition at line 78 of file LightComponent.cpp.

78 {
79 m_light->color = color;
80}

◆ SetDirection()

void LightComponent::SetDirection ( const vec4 direction) const

Definition at line 65 of file LightComponent.cpp.

65 {
66 switch (m_type) {
67 case DIRECTIONAL:
68 case SPOT:
69
70 m_light->direction = direction;
71 return;
72
73 default:
74 return;
75 }
76}

◆ SetLightRadius()

void LightComponent::SetLightRadius ( float  radius) const

Definition at line 82 of file LightComponent.cpp.

82 {
83 m_light->radius = radius;
84}

◆ SetLightType()

void LightComponent::SetLightType ( LIGHT  type)

Definition at line 54 of file LightComponent.cpp.

54 {
55 m_type = type;
56
57 if (m_type == POINT || m_type == SPOT) {
58 SetLightPosition();
59 }
60 else {
61 m_lightProjectionMatrix = mat4::Ortho(-3.f, 3.f, -3.f, 3.f, m_near, m_far);
62 }
63}

◆ SetShadow()

void CSE::LightComponent::SetShadow ( bool  isActive)
inline

Definition at line 56 of file LightComponent.h.

56 {
57 m_disableShadow = !isActive;
58 }

◆ SetSunrising()

void LightComponent::SetSunrising ( bool  active)

Definition at line 136 of file LightComponent.cpp.

136 {
137 m_isSunRising = active;
138}

◆ SetValue()

void LightComponent::SetValue ( std::string  name_str,
Arguments  value 
)
overridevirtual

Implements CSE::VariableBinder.

Definition at line 153 of file LightComponent.cpp.

153 {
154 if (name_str == "m_type") {
155 m_type = static_cast<LIGHT>(std::stoi(value[0]));
156 } else if (name_str == "m_disableShadow") {
157 m_disableShadow = std::stoi(value[0]) == 1;
158 } else if (name_str == "m_near") {
159 m_near = std::stof(value[0]);
160 } else if (name_str == "m_far") {
161 m_far = std::stof(value[0]);
162 } else if (name_str == "m_direction") {
163 SET_VEC4(m_light->direction);
164 }
165
166 SetLightType(m_type);
167}

◆ Tick()

void LightComponent::Tick ( float  elapsedTime)
overridevirtual

Implements CSE::SISComponent.

Definition at line 34 of file LightComponent.cpp.

34 {
35 auto eye = static_cast<TransformComponent*>(gameObject->GetTransform())->GetPosition();
36 auto target = *eye + vec3(-m_light->direction.x, -m_light->direction.y, -m_light->direction.z);
37 m_lightViewMatrix = mat4::LookAt(*eye, target, vec3{ 0, 1, 0 });
38
39 if (m_isSunRising && m_type == DIRECTIONAL) {
40 float value = m_light->direction.y;
41 float bright = (value < 0.2) ? (value - 0.2f) * 2 + 1 : 1;
42 if (bright < 0) bright = 0;
43 if (value < 0) value = 0;
44
45 float color0 = (0.4f * (1 - value) + 0.4f) * bright * 5;
46 float color1 = (0.3f * value + 0.3f) * bright * 5;
47
48// float color2 = (valueStr * 0.07f + 0.03f) * 10;
49
50 m_light->color = vec3{ color0, color1, color1 };
51 }
52}

Member Data Documentation

◆ m_type

LIGHT CSE::LightComponent::m_type = DIRECTIONAL

Definition at line 85 of file LightComponent.h.


The documentation for this class was generated from the following files: