Lugdunum  0.1.0
Light.hpp
Go to the documentation of this file.
1 #pragma once
2 
6 #include <lug/Math/Constant.hpp>
7 #include <lug/Math/Vector.hpp>
8 
9 namespace lug {
10 namespace Graphics {
11 
12 // For friend
13 namespace Builder {
14 class Light;
15 } // Builder
16 
17 namespace Scene {
18 class Node;
19 } // Scene
20 
21 namespace Render {
22 
26 class LUG_GRAPHICS_API Light : public Resource, public DirtyObject {
27  friend class ::lug::Graphics::Builder::Light;
28 
29 public:
30  enum class Type: uint8_t {
31  Ambient = 0,
32  Directional = 1,
33  Point = 2,
34  Spot = 3
35  };
36 
37  // No default values other than 0.0f, required fields will be filled by the function getData
38  struct Data {
39  Math::Vec3f position{0.0f, 0.0f, 0.0f};
40  float distance{0.0f};
41  Math::Vec4f color{0.0f, 0.0f, 0.0f, 0.0f};
42  Math::Vec3f direction{0.0f, 0.0f, 0.0f};
43  float constantAttenuation{0.0f};
44  float linearAttenuation{0.0f};
45  float quadraticAttenuation{0.0f};
46  float falloffAngle{0.0f};
47  float falloffExponent{0.0f};
48  uint32_t type;
49  };
50 
51  static constexpr uint32_t strideShader{ 80 };
52 
53 public:
54  Light(const Light&) = delete;
55  Light(Light&&) = delete;
56 
57  Light& operator=(const Light&) = delete;
58  Light& operator=(Light&&) = delete;
59 
60  ~Light() = default;
61 
62  void setType(Type type);
63  void setColor(const Math::Vec4f& color);
64  void setDirection(const Math::Vec3f& direction);
65  void setConstantAttenuation(float constantAttenuation);
66  void setDistance(float distance);
67  void setLinearAttenuation(float linearAttenuation);
68  void setQuadraticAttenuation(float quadraticAttenuation);
69  void setFalloffAngle(float falloffAngle);
70  void setFalloffExponent(float falloffExponent);
71 
77  Type getType() const;
78 
79  const Math::Vec4f& getColor() const;
80  const Math::Vec3f& getDirection() const;
81  float getConstantAttenuation() const;
82  float getDistance() const;
83  float getLinearAttenuation() const;
84  float getQuadraticAttenuation() const;
85  float getFalloffAngle() const;
86  float getFalloffExponent() const;
87 
88  void getData(Light::Data& lightData, Scene::Node& node);
89 
90 private:
97  Light(const std::string& name, Type type);
98 
99 protected:
100  Type _type{Type::Ambient};
101 
102  Math::Vec4f _color{0.0f, 0.0f, 0.0f, 1.0f};
103  Math::Vec3f _direction{0.0f, 0.0f, 0.0f};
104  float _constantAttenuation{0.0f};
105  float _distance{0.0f};
106  float _linearAttenuation{1.0f};
107  float _quadraticAttenuation{1.0f};
108  float _falloffAngle{Math::halfPi<float>()};
109  float _falloffExponent{0.0f};
110 };
111 
113 
114 } // Render
115 } // Graphics
116 } // lug
#define LUG_GRAPHICS_API
Definition: Export.hpp:11
Class for resource.
Definition: Resource.hpp:17
Scene & operator=(const Scene &)=delete
Class for Light.
Definition: Light.hpp:26