Radium Engine  1.5.20
Loading...
Searching...
No Matches
LightData.hpp
1#pragma once
2
3#include <Core/Asset/AssetData.hpp>
4#include <Core/RaCore.hpp>
5#include <Core/Utils/Color.hpp>
6#include <Core/Utils/Log.hpp>
7
8#include <memory>
9#include <string>
10#include <vector>
11
12namespace Ra {
13namespace Core {
14namespace Asset {
15
25class RA_CORE_API LightData : public AssetData
26{
27
28 public:
32 enum LightType {
33 UNKNOWN = 1 << 0,
34 POINT_LIGHT = 1 << 1,
35 SPOT_LIGHT = 1 << 2,
36 DIRECTIONAL_LIGHT = 1 << 3,
37 AREA_LIGHT = 1 << 4
38 };
39
45 Scalar constant;
46 Scalar linear;
47 Scalar quadratic;
48 explicit LightAttenuation( Scalar c = 1, Scalar l = 0, Scalar q = 0 ) :
49 constant( c ), linear( l ), quadratic( q ) {}
50 };
51 // TODO : allow to define other attenuation function such
52 // \max\left(0,1-\frac{\left|x\right|^2}{r^2}\right)^2
53
58 explicit LightData( const std::string& name = "", const LightType& type = UNKNOWN );
59
66 LightData( const LightData& data );
67
69 ~LightData();
70
76 inline void setName( const std::string& name );
77
82 inline const Eigen::Matrix<Scalar, 4, 4>& getFrame() const;
83
88 inline void setFrame( const Eigen::Matrix<Scalar, 4, 4>& frame );
89
98 inline void setLight( const Core::Utils::Color& color,
99 const Eigen::Matrix<Scalar, 3, 1>& direction );
100
108 inline void setLight( const Core::Utils::Color& color,
109 const Eigen::Matrix<Scalar, 3, 1>& position,
110 LightAttenuation attenuation );
111
120 inline void setLight( const Core::Utils::Color& color,
121 const Eigen::Matrix<Scalar, 3, 1>& position,
122 const Eigen::Matrix<Scalar, 3, 1>& direction,
123 Scalar inAngle,
124 Scalar outAngle,
125 LightAttenuation attenuation );
126
135 inline void setLight( const Core::Utils::Color& color,
136 const Eigen::Matrix<Scalar, 3, 1>& cog,
137 const Eigen::Matrix<Scalar, 3, 3>& spatialCov,
138 const Eigen::Matrix<Scalar, 3, 3>& normalCov,
139 LightAttenuation attenuation );
140
144 inline LightType getType() const;
145
149 inline bool isPointLight() const;
150
154 inline bool isSpotLight() const;
155
159 inline bool isDirectionalLight() const;
160
164 inline bool isAreaLight() const;
165
169 inline void displayInfo() const;
170
171 protected:
173
174 Eigen::Matrix<Scalar, 4, 4> m_frame;
175 LightType m_type;
176
177 // This part is public so that systems handling lights could access to the data.
178 // TODO : make these protected with getters ? Define independant types ?
179 public:
180 Core::Utils::Color m_color;
181
182 struct DirLight {
183 Eigen::Matrix<Scalar, 3, 1> direction;
184 };
185 struct PointLight {
186 Eigen::Matrix<Scalar, 3, 1> position;
187 LightAttenuation attenuation;
188 };
189 struct SpotLight {
190 Eigen::Matrix<Scalar, 3, 1> position;
191 Eigen::Matrix<Scalar, 3, 1> direction;
192 Scalar innerAngle;
193 Scalar outerAngle;
194 LightAttenuation attenuation;
195 };
196 struct AreaLight {
197 // TODO : this representation is usefull but might be improved
198 Eigen::Matrix<Scalar, 3, 1> position;
199 Eigen::Matrix<Scalar, 3, 3> spatialCovariance;
200 Eigen::Matrix<Scalar, 3, 3> normalCovariance;
201 LightAttenuation attenuation;
202 };
203
204 union {
205 DirLight m_dirlight;
206 PointLight m_pointlight;
207 SpotLight m_spotlight;
208 AreaLight m_arealight;
209 };
210};
211
215
217inline void LightData::setName( const std::string& name ) {
218 m_name = name;
219}
220
223 return m_type;
224}
225
227inline const Eigen::Matrix<Scalar, 4, 4>& LightData::getFrame() const {
228 return m_frame;
229}
230
231inline void LightData::setFrame( const Eigen::Matrix<Scalar, 4, 4>& frame ) {
232 m_frame = frame;
233}
234
236inline void LightData::setLight( const Core::Utils::Color& color,
237 const Eigen::Matrix<Scalar, 3, 1>& direction ) {
238 m_type = DIRECTIONAL_LIGHT;
239 m_color = color;
240 m_dirlight.direction = direction;
241}
242
244inline void LightData::setLight( const Core::Utils::Color& color,
245 const Eigen::Matrix<Scalar, 3, 1>& position,
246 LightAttenuation attenuation ) {
247 m_type = POINT_LIGHT;
248 m_color = color;
249 m_pointlight.position = position;
250 m_pointlight.attenuation = attenuation;
251}
252
254inline void LightData::setLight( const Core::Utils::Color& color,
255 const Eigen::Matrix<Scalar, 3, 1>& position,
256 const Eigen::Matrix<Scalar, 3, 1>& direction,
257 Scalar inAngle,
258 Scalar outAngle,
259 LightAttenuation attenuation ) {
260 m_type = SPOT_LIGHT;
261 m_color = color;
262 m_spotlight.position = position;
263 m_spotlight.direction = direction;
264 m_spotlight.innerAngle = inAngle;
265 m_spotlight.outerAngle = outAngle;
266 m_spotlight.attenuation = attenuation;
267}
268
270inline void LightData::setLight( const Core::Utils::Color& color,
271 const Eigen::Matrix<Scalar, 3, 1>& cog,
272 const Eigen::Matrix<Scalar, 3, 3>& spatialCov,
273 const Eigen::Matrix<Scalar, 3, 3>& normalCov,
274 LightAttenuation attenuation ) {
275 m_type = AREA_LIGHT;
276 m_color = color;
277 m_arealight.position = cog;
278 m_arealight.spatialCovariance = spatialCov;
279 m_arealight.normalCovariance = normalCov;
280 m_arealight.attenuation = attenuation;
281}
282
284inline bool LightData::isPointLight() const {
285 return ( m_type == POINT_LIGHT );
286}
287
288inline bool LightData::isSpotLight() const {
289 return ( m_type == SPOT_LIGHT );
290}
291
292inline bool LightData::isDirectionalLight() const {
293 return ( m_type == DIRECTIONAL_LIGHT );
294}
295
296inline bool LightData::isAreaLight() const {
297 return ( m_type == AREA_LIGHT );
298}
299
301inline void LightData::displayInfo() const {
302 using namespace Core::Utils; // log
303 std::string type;
304 switch ( m_type ) {
305 case POINT_LIGHT:
306 type = "POINT LIGHT";
307 break;
308 case SPOT_LIGHT:
309 type = "SPOT LIGHT";
310 break;
311 case DIRECTIONAL_LIGHT:
312 type = "DIRECTIONAL LIGHT";
313 break;
314 case AREA_LIGHT:
315 type = "AREA LIGHT";
316 break;
317 case UNKNOWN:
318 default:
319 type = "UNKNOWN";
320 break;
321 }
322 LOG( logINFO ) << "======== LIGHT INFO ========";
323 LOG( logINFO ) << " Name : " << m_name;
324 LOG( logINFO ) << " Type : " << type;
325}
326
327} // namespace Asset
328} // namespace Core
329} // namespace Ra
void setLight(const Core::Utils::Color &color, const Eigen::Matrix< Scalar, 3, 1 > &direction)
construct a directional light
void displayInfo() const
DEBUG.
bool isPointLight() const
QUERY.
void setName(const std::string &name)
LIGHT DATA ///.
Eigen::Matrix< Scalar, 4, 4 > m_frame
VARIABLE.
const Eigen::Matrix< Scalar, 4, 4 > & getFrame() const
FRAME.
bool isDirectionalLight() const
LightType getType() const
TYPE.
void setFrame(const Eigen::Matrix< Scalar, 4, 4 > &frame)
hepler function to manage enum as underlying types in VariableSet
Definition Cage.cpp:3