CSEngine
Loading...
Searching...
No Matches
LightComponent.h
1#pragma once
2
3#include "SComponent.h"
4#include "../Util/Render/LightHelper.h"
5#include "../Util/Render/STexture.h"
6#include "../Util/Render/CameraBase.h"
7
8namespace CSE {
9
10 class GLProgramHandle;
11 struct CameraMatrixStruct;
12
13 class LightComponent : public SComponent, public CameraBase {
14
15 public:
16 enum LIGHT {
17 NONE = 0, DIRECTIONAL = 1, POINT = 2, SPOT = 3
18 };
19 public:
20 COMPONENT_DEFINE_CONSTRUCTOR(LightComponent);
21
22 ~LightComponent() override;
23
24
25 void Exterminate() override;
26
27 void Init() override;
28
29 void Tick(float elapsedTime) override;
30
31 void SetLightType(LIGHT type);
32
33 void SetDirection(const vec4& direction) const;
34
35 void SetColor(const vec3& color) const;
36
37 LIGHT GetType() const;
38
39 vec4 GetDirection(const vec4& direction) const;
40
41 vec3 GetColor() const;
42
43 //for Positional Light and SpotLight
44 void SetLightRadius(float radius) const;
45
46 void SetAttenuationFactor(const vec3& att) const;
47
48 void SetAttenuationFactor(float Kc, float Kl, float Kq) const;
49
50 void SetSunrising(bool active);
51
52 SLight* GetLight() const {
53 return m_light;
54 }
55
56 void SetShadow(bool isActive) {
57 m_disableShadow = !isActive;
58 }
59
60 SComponent* Clone(SGameObject* object) override;
61
62 void SetValue(std::string name_str, Arguments value) override;
63
64 std::string PrintValue() const override;
65
66 const mat4& GetLightProjectionMatrix() const;
67
68 const mat4& GetLightViewMatrix() const;
69
70 CameraMatrixStruct GetCameraMatrixStruct() const override;
71
72 SFrameBuffer* GetFrameBuffer() const override;
73
74 bool IsShadow() const;
75
76 void BindShadow(const GLProgramHandle& handle, int handleIndex, int index) const;
77
78 void RenderBackground() const override {};
79
80 private:
81 void SetLightPosition() const;
82 void SetDepthMap();
83
84 public:
85 LIGHT m_type = DIRECTIONAL;
86
87 private:
88 SLight* m_light = nullptr;
89 bool m_isSunRising = false;
90 bool m_disableShadow = false;
91 SFrameBuffer* m_frameBuffer = nullptr;
92 STexture* m_depthTexture = nullptr;
93 mat4 m_lightProjectionMatrix;
94 mat4 m_lightViewMatrix;
95 float m_near = -10.f;
96 float m_far = 10.f;
97 };
98
99}