VenomEngine
Cross-Platform Modern Graphics Engine
Loading...
Searching...
No Matches
Light.h
Go to the documentation of this file.
1
8#pragma once
11
12namespace venom
13{
14namespace common
15{
16class Camera;
17class Light;
18
19enum class LightType
20{
21 Directional = 0,
22 Point = 1,
23 Spot = 2,
24 Count
25};
26
28{
29 vcm::Vec3 position;
30 LightType type;
31 vcm::Vec3 color;
32 float intensity;
33 vcm::Vec3 direction;
34 float angle;
35};
36
38{
39 vcm::Mat4 lightSpaceMatrix;
40 int lightType;
41 int cascadeIndex;
42};
43
44#define POINTLIGHT_THRESHHOLD 0.2
45#define SPOTLIGHT_THRESHHOLD 0.2
46
47class VENOM_COMMON_API LightImpl : public PluginObjectImpl, public GraphicsPluginObject
48{
49public:
50 LightImpl();
51 ~LightImpl();
52
53 vc::Error SetType(const LightType type);
54 inline const LightType & GetLightType() const { return __lightType; }
55 inline void SetColor(const vcm::Vec3 & color) { __color = color; }
56 inline const vcm::Vec3 & GetColor() const { return __color; }
57 inline void SetIntensity(const float intensity) { __intensity = intensity; }
58 inline const float & GetIntensity() const { return __intensity; }
59 inline float * GetIntensityPtr() { return &__intensity; }
60 inline void SetAngle(const float angle) { __angle = angle; }
61 inline const float & GetAngle() const { return __angle; }
62 inline LightShaderStruct GetShaderStruct() const { return {__transform->GetPosition(), __lightType, __color, __intensity, GetDirection(), __angle}; }
63 inline vc::Error Reinit() { return _SetType(__lightType); }
64 LightCascadedShadowMapConstantsStruct GetShadowMapConstantsStruct(const int cascadeIndex, const int faceIndex, Camera * const camera, vcm::Vec3 * lightPos) const;
65 int GetCascadeIndex(Camera * const camera);
66 inline int GetLightIndexPerType() const { return _lightIndexPerType; }
67
68 vcm::Vec3 GetDirection() const;
69
70protected:
71 virtual vc::Error _SetType(const LightType type) = 0;
72 virtual void _SetDescriptorsFromCascade(const int cascadeIndex) = 0;
73
74private:
75 void __AllocateLightType();
76 void __DeallocateLightType();
77
78protected:
79 int _lightIndexPerType;
80
81private:
82 Transform3D * __transform;
83 vcm::Vec3 __color;
84 LightType __lightType;
85 float __intensity;
86 float __angle;
87
88 friend class Light;
89};
90
91class VENOM_COMMON_API Light : public Component, public PluginObjectImplWrapper
92{
93public:
94 Light();
95 ~Light() override;
96 Light(const Light & other);
97 Light & operator=(const Light & other);
98 Light(Light && other) noexcept;
99 Light & operator=(Light && other) noexcept;
100
101 void Init(Entity entity) override;
102 void Update(Entity entity) override;
103 void _GUI(const Entity entity) override;
104 vc::String _GetComponentTitle() override;
105 bool CanRemove(Entity entity) override;
106 inline void SetType(const LightType type) { _impl->As<LightImpl>()->SetType(type); }
107 inline const LightType & GetLightType() const { return _impl->As<LightImpl>()->GetLightType(); }
108 inline void SetColor(const vcm::Vec3 & color) { _impl->As<LightImpl>()->SetColor(color); }
109 inline const vcm::Vec3 & GetColor() const { return _impl->As<LightImpl>()->GetColor(); }
110 inline void SetIntensity(const float intensity) { _impl->As<LightImpl>()->SetIntensity(intensity); }
111 inline const float & GetIntensity() const { return _impl->As<LightImpl>()->GetIntensity(); }
112 inline float * GetIntensityPtr() { return _impl->As<LightImpl>()->GetIntensityPtr(); }
113 inline void SetAngle(const float angle) { _impl->As<LightImpl>()->SetAngle(angle); }
114 inline const float & GetAngle() const { return _impl->As<LightImpl>()->GetAngle(); }
115 inline LightShaderStruct GetShaderStruct() const { return _impl->As<LightImpl>()->GetShaderStruct(); }
116 inline LightCascadedShadowMapConstantsStruct GetShadowMapConstantsStruct(const int shadowMapIndex, const int faceIndex, Camera * const camera, vcm::Vec3 * lightPos) const { return _impl->As<LightImpl>()->GetShadowMapConstantsStruct(shadowMapIndex, faceIndex, camera, lightPos); }
117
118 static const size_t GetCountOfLights() { return __lights.size(); }
119 static const vc::Vector<Light *> & GetLights() { return __lights; }
120 static vc::Vector<Light *> & GetLightsMut() { return __lights; }
121
122 static const size_t GetCountOfLightsOfType(const LightType type);
123
124private:
125 static vc::Vector<Light *> __lights;
126};
127}
128}
Camera class Classic layout with position, rotation and projection matrices.
Definition Camera.h:132
Definition Light.h:92
Definition Light.h:48
Definition Transform3D.h:18
High-Level Frontend of the VenomEngine project. It also contains all the code shared between every AP...
Definition Callback.h:15
Contains the entirety of the code of the VenomEngine project.
Definition Callback.h:13