Radium Engine  1.5.20
Loading...
Searching...
No Matches
Light.hpp
1#pragma once
2
3#include <Core/Utils/Color.hpp>
4#include <Engine/RaEngine.hpp>
5#include <Engine/Scene/Component.hpp>
6
7#include <Engine/Data/RenderParameters.hpp>
8
9namespace Ra {
10namespace Engine {
11namespace Scene {
12
13class Entity;
14
15// Radium-V2 : this class could totally be renamed LightComponent and get a Light struct embedded.
16// Thoughts are welcome !
20class RA_ENGINE_API Light : public Component
21{
22 public:
27 enum LightType : int { DIRECTIONAL = 0, POINT, SPOT, POLYGONAL };
28
34 struct Attenuation {
35 Scalar constant { 1 };
36 Scalar linear { 0 };
37 Scalar quadratic { 0 };
38 Attenuation() = default;
39 };
40
41 public:
48 Light( Entity* entity, const LightType& type, const std::string& name = "light" );
49 ~Light() override = default;
50
55 inline const Core::Utils::Color& getColor() const { return m_color; }
60 inline void setColor( const Core::Utils::Color& color );
61
67 virtual void setDirection( const Eigen::Matrix<Scalar, 3, 1>& /*dir*/ ) {}
73 virtual void setPosition( const Eigen::Matrix<Scalar, 3, 1>& /*pos*/ ) {}
74 // ...
75
80 inline const LightType& getType() const { return m_type; }
81
87 void getRenderParameters( Data::RenderParameters& params ) const;
88
93 const Data::RenderParameters& getRenderParameters() const { return m_params; }
94
106 virtual std::string getShaderInclude() const;
107
111 void initialize() override;
112
113 private:
114 Data::RenderParameters m_params;
115 Core::Utils::Color m_color = Core::Utils::Color::White();
116 LightType m_type { LightType::DIRECTIONAL };
117};
118
119// ---------------------------------------------------------------------------------------------
120// ---- inline methods implementation
121
122inline void Light::setColor( const Core::Utils::Color& color ) {
123 m_color = color;
124 m_params.setVariable( "light.color", m_color );
125}
126
127} // namespace Scene
128} // namespace Engine
129} // 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:55
const LightType & getType() const
Definition Light.hpp:80
Data::RenderParameters & getRenderParameters()
Gives read-write access to the renderParameters of the light.
Definition Light.hpp:99
const Data::RenderParameters & getRenderParameters() const
Gives read-only access to the renderParameters of the light.
Definition Light.hpp:93
void setColor(const Core::Utils::Color &color)
Definition Light.hpp:122
virtual void setDirection(const Eigen::Matrix< Scalar, 3, 1 > &)
Definition Light.hpp:67
virtual void setPosition(const Eigen::Matrix< Scalar, 3, 1 > &)
Definition Light.hpp:73
hepler function to manage enum as underlying types in VariableSet
Definition Cage.cpp:3