CeresEngine 0.2.0
A game development framework
Loading...
Searching...
No Matches
Light.hpp
Go to the documentation of this file.
1//
2// CeresEngine - A game development framework
3//
4// Created by Rogiel Sulzbach.
5// Copyright (c) 2018-2022 Rogiel Sulzbach. All rights reserved.
6//
7
8#pragma once
9
10#include "SceneObject.hpp"
11
13
16
20
21#include <glm/vec3.hpp>
22
23namespace CeresEngine {
24
36 Point,
37
42
45 Spot,
46
54 Area,
55 };
56
58 struct CE_SCRIPT_EXPORT() LightComponent final : public Component<LightComponent> {
60 struct Accessor;
61
64 LightType type = LightType::Point;
65
68 Vector3 color = Vector3(1.0);
69
73 double power = 1.0;
74
79 double radius = 1.0;
80
83 double strength = 1.0;
84
87 bool shouldCastShadows = false;
88
91 double shadowOcclusionStrength = 1.0;
92
95 double constant = 0.0;
96
99 double linear = 0.0;
100
103 double quadratic = 1.0;
104
107 double cutOff = 10.0;
108
111 double outerCutOff = 15.0;
112
115 RendererLightSettings rendererSettings;
116
119 LightComponent() = default;
120
121 public: // Reflection
124 template<typename Processor> static constexpr void reflect(Processor&& RTTI) {
125 CE_REFL_DATA(type);
126 CE_REFL_DATA(color);
127 CE_REFL_DATA(strength);
128 CE_REFL_DATA(shouldCastShadows);
129 CE_REFL_DATA(shadowOcclusionStrength);
130 CE_REFL_DATA(constant);
131 CE_REFL_DATA(linear);
132 CE_REFL_DATA(quadratic);
133 CE_REFL_DATA(cutOff);
134 CE_REFL_DATA(outerCutOff);
135 CE_REFL_DATA(rendererSettings);
136 }
137 };
138
140 struct CE_SCRIPT_EXPORT() LightComponent::Accessor : public Component<LightComponent>::Accessor {
141 using Component<LightComponent>::Accessor::Accessor;
142
143 public:
145 [[nodiscard]] CE_SCRIPT_EXPORT()
146 LightType getType() const noexcept;
147
150 void setType(LightType type) noexcept;
151
153 [[nodiscard]] CE_SCRIPT_EXPORT()
154 Vector3 getColor() const noexcept;
155
158 void setColor(Vector3 color) noexcept;
159
161 [[nodiscard]] CE_SCRIPT_EXPORT()
162 double getStrength() const noexcept;
163
166 void setStrength(double strength) noexcept;
167
169 [[nodiscard]] CE_SCRIPT_EXPORT()
170 bool getShouldCastShadows() const noexcept;
171
175 void setShouldCastShadows(bool shouldCastShadows) noexcept;
176
178 [[nodiscard]] CE_SCRIPT_EXPORT()
179 double getShadowOcclusionStrength() const noexcept;
180
184 void setShadowOcclusionStrength(double shadowOcclusionStrength) noexcept;
185
187 [[nodiscard]] CE_SCRIPT_EXPORT()
188 double getConstant() const noexcept;
189
192 void setConstant(double constant) noexcept;
193
195 [[nodiscard]] CE_SCRIPT_EXPORT()
196 double getLinear() const noexcept;
197
200 void setLinear(double linear) noexcept;
201
203 [[nodiscard]] CE_SCRIPT_EXPORT()
204 double getQuadratic() const noexcept;
205
208 void setQuadratic(double quadratic) noexcept;
209
211 [[nodiscard]] CE_SCRIPT_EXPORT()
212 double getCutOff() const noexcept;
213
216 void setCutOff(double cutOff) noexcept;
217
219 [[nodiscard]] CE_SCRIPT_EXPORT()
220 double getOuterCutOff() const noexcept;
221
224 void setOuterCutOff(double outerCutOff) noexcept;
225
227 [[nodiscard]] const RendererLightSettings& getRendererSettings() const;
228
230 void setRendererSettings(const RendererLightSettings& rendererSettings);
231
233 template<CInvocable<RendererLightSettings&> Func> decltype(auto) updateRendererSettings(Func&& func) noexcept {
234 RendererLightSettings settings = getRendererSettings();
235 const ScopeExit commitSettings([&]() { setRendererSettings(settings); });
236 return func(settings);
237 }
238
239 public: // Reflection
242 template<typename Processor> static constexpr void reflect(Processor&& RTTI) {
243 CE_REFL_DATA_GETSET(type, getType, setType);
244 CE_REFL_DATA_GETSET(color, getColor, setColor);
245 CE_REFL_DATA_GETSET(strength, getStrength, setStrength);
246 CE_REFL_DATA_GETSET(shouldCastShadows, getShouldCastShadows, setShouldCastShadows);
247 CE_REFL_DATA_GETSET(shadowOcclusionStrength, getShadowOcclusionStrength, setShadowOcclusionStrength);
248 CE_REFL_DATA_GETSET(constant, getConstant, setConstant);
249 CE_REFL_DATA_GETSET(linear, getLinear, setLinear);
250 CE_REFL_DATA_GETSET(quadratic, getQuadratic, setQuadratic);
251 CE_REFL_DATA_GETSET(cutOff, getCutOff, setCutOff);
252 CE_REFL_DATA_GETSET(outerCutOff, getOuterCutOff, setOuterCutOff);
253 CE_REFL_DATA_GETSET(rendererSettings, getRendererSettings, setRendererSettings);
254 }
255 };
256
275 class CE_SCRIPT_EXPORT() Light final : public TSceneObject<LightComponent> {
276 public:
282 Light(EntityManager& entityManager, const Entity& parent, LightType type);
283 using TSceneObject::TSceneObject;
284 };
285 extern template class TSceneObject<LightComponent>;
286
287} // namespace CeresEngine
288
291
294
297
298
#define CE_EXTERN_COMPONENT(T)
Definition Component.hpp:600
#define CE_ENTITY_OBJECT_HASH(T)
Definition Entity.hpp:784
#define CE_REFLECT_HASH(T)
Definition Hash.hpp:89
#define CE_REFLECTABLE_STRUCT
Definition IReflectable.hpp:47
#define CE_REFL_DATA_GETSET(N, G, S)
Definition Macros.hpp:549
#define CE_REFL_DATA(N)
Definition Macros.hpp:541
#define CE_SCRIPT_EXPORT(...)
The CE_SCRIPT_EXPORT macro marks a class or method as exportable and available in scripting environme...
Definition Macros.hpp:247
The base entity class.
Definition Entity.hpp:41
Definition EntityManager.hpp:49
A scene light.
Definition Light.hpp:275
Light(EntityManager &entityManager, const Entity &parent, LightType type)
Create a new Light with the given type and parent.
The SceneObject template class is a helper class that EntityObjects might choose to use to provide so...
Definition SceneObject.hpp:323
Definition Concepts.hpp:43
Definition Application.hpp:19
CE_FLATTEN_INLINE Type getType()
Definition Type.hpp:248
LightType
Definition Light.hpp:25
@ Point
The point light is an omni-directional point of light, that is, a point radiating the same amount of ...
@ Spot
A spot light emits a cone-shaped beam of light from the tip of the cone, in a given direction.
@ Directional
A sun light provides light of constant intensity emitted in a single direction from infinitely far aw...
@ Area
The area light simulates light originating from a surface (or surface-like) emitter.
constexpr size_t hash(const T &v)
Generates a hash for the provided type.
Definition Hash.hpp:25
Components serve as the base for data storage for an entity.
Definition Component.hpp:68
A scene light.
Definition Light.hpp:140
static constexpr void reflect(Processor &&RTTI)
Executes the given processor for every field of the struct.
Definition Light.hpp:242
A scene light.
Definition Light.hpp:58
A structure that holds renderer-specific settings for a Light.
Definition RendererLightSettings.hpp:150
Definition ScopeExit.hpp:15