Nazara Engine  0.4
A fast, complete, cross-platform API designed for game development
Light.hpp
1 // Copyright (C) 2017 Jérôme Leclercq
2 // This file is part of the "Nazara Engine - Graphics module"
3 // For conditions of distribution and use, see copyright notice in Config.hpp
4 
5 #pragma once
6 
7 #ifndef NAZARA_LIGHT_HPP
8 #define NAZARA_LIGHT_HPP
9 
10 #include <Nazara/Prerequesites.hpp>
11 #include <Nazara/Core/Color.hpp>
12 #include <Nazara/Graphics/Enums.hpp>
13 #include <Nazara/Graphics/Renderable.hpp>
14 #include <Nazara/Renderer/Texture.hpp>
15 
16 namespace Nz
17 {
18  class NAZARA_GRAPHICS_API Light : public Renderable
19  {
20  public:
21  Light(LightType type = LightType_Point);
22  inline Light(const Light& light);
23  Light(Light&& light) = default;
24  ~Light() = default;
25 
26  void AddToRenderQueue(AbstractRenderQueue* renderQueue, const Matrix4f& transformMatrix) const override;
27 
28  Light* Clone() const;
29  Light* Create() const;
30 
31  bool Cull(const Frustumf& frustum, const Matrix4f& transformMatrix) const override;
32 
33  inline void EnableShadowCasting(bool castShadows);
34 
35  inline void EnsureShadowMapUpdate() const;
36 
37  inline float GetAmbientFactor() const;
38  inline float GetAttenuation() const;
39  inline Color GetColor() const;
40  inline float GetDiffuseFactor() const;
41  inline float GetInnerAngle() const;
42  inline float GetInnerAngleCosine() const;
43  inline float GetInvRadius() const;
44  inline LightType GetLightType() const;
45  inline float GetOuterAngle() const;
46  inline float GetOuterAngleCosine() const;
47  inline float GetOuterAngleTangent() const;
48  inline float GetRadius() const;
49  inline TextureRef GetShadowMap() const;
50  inline PixelFormatType GetShadowMapFormat() const;
51  inline const Vector2ui& GetShadowMapSize() const;
52 
53  inline bool IsShadowCastingEnabled() const;
54 
55  inline void SetAmbientFactor(float factor);
56  inline void SetAttenuation(float attenuation);
57  inline void SetColor(const Color& color);
58  inline void SetDiffuseFactor(float factor);
59  inline void SetInnerAngle(float innerAngle);
60  inline void SetLightType(LightType type);
61  inline void SetOuterAngle(float outerAngle);
62  inline void SetRadius(float radius);
63  inline void SetShadowMapFormat(PixelFormatType shadowFormat);
64  inline void SetShadowMapSize(const Vector2ui& size);
65 
66  void UpdateBoundingVolume(const Matrix4f& transformMatrix) override;
67 
68  Light& operator=(const Light& light);
69  Light& operator=(Light&& light) = default;
70 
71  private:
72  void MakeBoundingVolume() const override;
73  inline void InvalidateShadowMap();
74  void UpdateShadowMap() const;
75 
76  Color m_color;
77  LightType m_type;
78  PixelFormatType m_shadowMapFormat;
79  Vector2ui m_shadowMapSize;
80  mutable TextureRef m_shadowMap;
81  bool m_shadowCastingEnabled;
82  mutable bool m_shadowMapUpdated;
83  float m_ambientFactor;
84  float m_attenuation;
85  float m_diffuseFactor;
86  float m_innerAngle;
87  float m_innerAngleCosine;
88  float m_invRadius;
89  float m_outerAngle;
90  float m_outerAngleCosine;
91  float m_outerAngleTangent;
92  float m_radius;
93  };
94 
95  struct LightUniforms
96  {
97  struct UniformLocations
98  {
99  int type;
100  int color;
101  int factors;
102  int lightViewProjMatrix;
103  int parameters1;
104  int parameters2;
105  int parameters3;
106  int shadowMapping;
107  };
108 
109  bool ubo;
110 
111  union
112  {
113  UniformLocations locations;
114  int blockLocation;
115  };
116  };
117 }
118 
119 #include <Nazara/Graphics/Light.inl>
120 
121 #endif // NAZARA_LIGHT_HPP
Math class that represents a frustum in the three dimensional vector space.
Definition: Frustum.hpp:24
Core class that represents a color.
Definition: Color.hpp:18
TODO: Inherit SoundEmitter from Node.
Definition: Algorithm.hpp:12
Graphics class that represents a light.
Definition: Light.hpp:18
Graphics class that represents the rendering queue for our scene.
Definition: AbstractRenderQueue.hpp:26
Graphics class that represents a renderable element for our scene.
Definition: Renderable.hpp:19