Loading [MathJax]/extensions/TeX/AMSmath.js
Radium Engine  1.5.28
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Light.hpp
1#pragma once
2
3#include <Core/CoreMacros.hpp>
4#include <Core/Utils/Color.hpp>
5#include <Eigen/Core>
6#include <Engine/Data/RenderParameters.hpp>
7#include <Engine/RaEngine.hpp>
8#include <Engine/Scene/Component.hpp>
9#include <map>
10#include <string>
11
12namespace Ra {
13namespace Engine {
14namespace Scene {
15
16class Entity;
17
18// Radium-V2 : this class could totally be renamed LightComponent and get a Light struct embedded.
19// Thoughts are welcome !
23class RA_ENGINE_API Light : public Component
24{
25 public:
30 enum LightType : int { DIRECTIONAL = 0, POINT, SPOT, POLYGONAL };
31
37 struct Attenuation {
38 Scalar constant { 1 };
39 Scalar linear { 0 };
40 Scalar quadratic { 0 };
41 Attenuation() = default;
42 };
43
44 public:
51 Light( Entity* entity, const LightType& type, const std::string& name = "light" );
52 ~Light() override = default;
53
58 inline const Core::Utils::Color& getColor() const { return m_color; }
63 inline void setColor( const Core::Utils::Color& color );
64
70 virtual void setDirection( const Eigen::Matrix<Scalar, 3, 1>& /*dir*/ ) {}
76 virtual void setPosition( const Eigen::Matrix<Scalar, 3, 1>& /*pos*/ ) {}
77 // ...
78
83 inline const LightType& getType() const { return m_type; }
84
90 void getRenderParameters( Data::RenderParameters& params ) const;
91
96 const Data::RenderParameters& getRenderParameters() const { return m_params; }
97
109 virtual std::string getShaderInclude() const;
110
114 void initialize() override;
115
116 private:
117 Data::RenderParameters m_params;
118 Core::Utils::Color m_color = Core::Utils::Color::White();
119 LightType m_type { LightType::DIRECTIONAL };
120};
121
122// ---------------------------------------------------------------------------------------------
123// ---- inline methods implementation
124
125inline void Light::setColor( const Core::Utils::Color& color ) {
126 m_color = color;
127 m_params.setVariable( "light.color", m_color );
128}
129
130} // namespace Scene
131} // namespace Engine
132} // namespace Ra
Management of shader parameters with automatic binding of a named parameter to the corresponding glsl...
void setVariable(const std::string &name, RenderParameters &rp)
overload create ref wrapper for RenderParameters variable
A component is an element that can be updated by a system. It is also linked to some other components...
Definition Component.hpp:31
An entity is an scene element. It ties together components with a transform.
Definition Entity.hpp:23
const Core::Utils::Color & getColor() const
Definition Light.hpp:58
const LightType & getType() const
Definition Light.hpp:83
Data::RenderParameters & getRenderParameters()
Gives read-write access to the renderParameters of the light.
Definition Light.hpp:102
const Data::RenderParameters & getRenderParameters() const
Gives read-only access to the renderParameters of the light.
Definition Light.hpp:96
void setColor(const Core::Utils::Color &color)
Definition Light.hpp:125
virtual void setDirection(const Eigen::Matrix< Scalar, 3, 1 > &)
Definition Light.hpp:70
virtual void setPosition(const Eigen::Matrix< Scalar, 3, 1 > &)
Definition Light.hpp:76
hepler function to manage enum as underlying types in VariableSet
Definition Cage.cpp:4