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 int padding[3];
36 int shadowMapIndex;
37};
38
40{
41 vcm::Mat4 lightSpaceMatrix;
42 int lightType;
43 int cascadeIndex;
44};
45
46#define POINTLIGHT_THRESHHOLD 0.2
47#define SPOTLIGHT_THRESHHOLD 0.2
48
49class VENOM_COMMON_API LightImpl : public GraphicsPluginObject
50{
51public:
52 LightImpl();
53 ~LightImpl();
54
55 vc::Error SetType(const LightType type);
56 inline const LightType & GetLightType() const { return __lightType; }
57 inline void SetColor(const vcm::Vec3 & color) { __color = color; }
58 inline const vcm::Vec3 & GetColor() const { return __color; }
59 inline void SetIntensity(const float intensity) { __intensity = intensity; }
60 inline const float & GetIntensity() const { return __intensity; }
61 inline float * GetIntensityPtr() { return &__intensity; }
62 inline void SetAngle(const float angle) { __angle = angle; }
63 inline const float & GetAngle() const { return __angle; }
64 inline LightShaderStruct GetShaderStruct() const { return {__transform->GetPosition(), __lightType, __color, __intensity, GetDirection(), __angle, {}, _shadowLightIndexPerType}; }
65 inline vc::Error Reinit() { return _SetType(__lightType); }
66 LightCascadedShadowMapConstantsStruct GetShadowMapConstantsStruct(const int cascadeIndex, const int faceIndex, Camera * const camera, vcm::Vec3 * lightPos) const;
67 int GetCascadeIndex(Camera * const camera);
68 inline int GetLightIndexPerType() const { return _lightIndexPerType; }
69 inline int GetShadowLightIndexPerType() const { return _shadowLightIndexPerType; }
70
71 vcm::Vec3 GetDirection() const;
72
73protected:
74 virtual vc::Error _SetType(const LightType type) = 0;
75 virtual void _SetDescriptorsFromCascade(const int cascadeIndex) = 0;
76
77private:
78 void __AllocateLightType();
79 void __DeallocateLightType();
80
81protected:
82 int _lightIndexPerType;
83 int _shadowLightIndexPerType;
84
85private:
86 Transform3D * __transform;
87 vcm::Vec3 __color;
88 LightType __lightType;
89 float __intensity;
90 float __angle;
91
92 friend class Light;
93};
94
95class VENOM_COMMON_API Light : public Component, public PluginObjectWrapper
96{
97public:
98 Light();
99 ~Light() override;
100 Light(const Light & other);
101 Light & operator=(const Light & other);
102 Light(Light && other) noexcept;
103 Light & operator=(Light && other) noexcept;
104
105 void Init(Entity entity) override;
106 void Update(Entity entity) override;
107 void _GUI(const Entity entity) override;
108 vc::String _GetComponentTitle() override;
109 bool CanRemove(Entity entity) override;
110 inline void SetType(const LightType type) { _impl->As<LightImpl>()->SetType(type); }
111 inline const LightType & GetLightType() const { return _impl->As<LightImpl>()->GetLightType(); }
112 inline void SetColor(const vcm::Vec3 & color) { _impl->As<LightImpl>()->SetColor(color); }
113 inline const vcm::Vec3 & GetColor() const { return _impl->As<LightImpl>()->GetColor(); }
114 inline void SetIntensity(const float intensity) { _impl->As<LightImpl>()->SetIntensity(intensity); }
115 inline const float & GetIntensity() const { return _impl->As<LightImpl>()->GetIntensity(); }
116 inline float * GetIntensityPtr() { return _impl->As<LightImpl>()->GetIntensityPtr(); }
117 inline void SetAngle(const float angle) { _impl->As<LightImpl>()->SetAngle(angle); }
118 inline const float & GetAngle() const { return _impl->As<LightImpl>()->GetAngle(); }
119 inline LightShaderStruct GetShaderStruct() const { return _impl->As<LightImpl>()->GetShaderStruct(); }
120 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); }
121
122 static const size_t GetCountOfLights() { return __lights.size(); }
123 static const vc::Vector<Light *> & GetLights() { return __lights; }
124 static vc::Vector<Light *> & GetLightsMut() { return __lights; }
125
126 static const size_t GetCountOfLightsOfType(const LightType type);
127 static const size_t GetCountOfShadowedLightsOfType(const LightType type);
128
129private:
130 static vc::Vector<Light *> __lights;
131};
132}
133}
Camera class Classic layout with position, rotation and projection matrices.
Definition Camera.h:132
Definition Light.h:96
Definition Light.h:50
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