Rendu
A lightweight rendering engine for experimentations
Loading...
Searching...
No Matches
Light.hpp
1#pragma once
2
3#include "scene/Animation.hpp"
4#include "scene/Object.hpp"
5#include "raycaster/Raycaster.hpp"
6#include "renderers/LightRenderer.hpp"
7#include "renderers/shadowmaps/ShadowMap.hpp"
8#include "Common.hpp"
9
10enum class LightType : int {
11 POINT = 0,
12 DIRECTIONAL = 1,
13 SPOT = 2
14};
15
20class Light {
21
22public:
24 Light();
25
29 explicit Light(const glm::vec3 & color);
30
34 void addAnimation(const std::shared_ptr<Animation> & anim);
35
39 virtual void draw(LightRenderer & renderer) = 0;
40
45 virtual void update(double fullTime, double frameTime) = 0;
46
50 virtual void setScene(const BoundingBox & sceneBox) = 0;
51
58 virtual glm::vec3 sample(const glm::vec3 & position, float & dist, float & attenuation) const = 0;
59
63 virtual KeyValues encode() const;
64
68 bool castsShadow() const { return _castShadows; }
69
73 void setCastShadow(bool shouldCast) { _castShadows = shouldCast; }
74
78 const glm::vec3 & intensity() const { return _color; }
79
83 void setIntensity(const glm::vec3 & color) { _color = color; }
84
88 const glm::mat4 & vp() const { return _vp; }
89
93 const glm::mat4 & model() const { return _model; }
94
98 const ShadowMap::Region & shadowMap() const { return _shadowMapInfos; }
99
108 void registerShadowMap(const Texture * map, ShadowMode mode, size_t layer = 0, const glm::vec2 & minUV = glm::vec2(0.0f), const glm::vec2 & maxUV = glm::vec2(1.0f)) {
109 _shadowMapInfos.map = map;
110 _shadowMapInfos.mode = mode;
111 _shadowMapInfos.minUV = minUV;
112 _shadowMapInfos.maxUV = maxUV;
113 _shadowMapInfos.layer = layer;
114 }
115
119 bool animated() const { return !_animations.empty(); }
120
125 static std::shared_ptr<Light> decode(const KeyValues & params);
126
128 virtual ~Light() = default;
129
131 Light(const Light &) = delete;
132
136 Light & operator=(const Light &) = delete;
137
139 Light(Light &&) = default;
140
144 Light & operator=(Light &&) = delete;
145
146protected:
147
160 bool decodeBase(const KeyValues & params);
161
162
163 std::vector<std::shared_ptr<Animation>> _animations;
166 glm::mat4 _vp;
167 glm::mat4 _model;
168 glm::vec3 _color;
170};
Represent the smallest axis-aligne box containing a given object or region of space.
Definition: Bounds.hpp:28
A general light with adjustable color intensity, that can cast shadows.
Definition: Light.hpp:20
const glm::mat4 & vp() const
Definition: Light.hpp:88
ShadowMap::Region _shadowMapInfos
Region of the (optional) shadow map containing this light information.
Definition: Light.hpp:164
static std::shared_ptr< Light > decode(const KeyValues &params)
Definition: Light.cpp:45
Light & operator=(Light &&)=delete
const ShadowMap::Region & shadowMap() const
Definition: Light.hpp:98
bool castsShadow() const
Definition: Light.hpp:68
bool _castShadows
Is the light casting shadows (and thus use a shadow map)..
Definition: Light.hpp:169
virtual void setScene(const BoundingBox &sceneBox)=0
virtual void update(double fullTime, double frameTime)=0
bool animated() const
Definition: Light.hpp:119
BoundingBox _sceneBox
The scene bounding box, to fit the shadow map.
Definition: Light.hpp:165
Light & operator=(const Light &)=delete
void setIntensity(const glm::vec3 &color)
Definition: Light.hpp:83
glm::mat4 _vp
VP matrix for shadow casting.
Definition: Light.hpp:166
bool decodeBase(const KeyValues &params)
Definition: Light.cpp:19
virtual glm::vec3 sample(const glm::vec3 &position, float &dist, float &attenuation) const =0
const glm::vec3 & intensity() const
Definition: Light.hpp:78
std::vector< std::shared_ptr< Animation > > _animations
Animations list (will be applied in order).
Definition: Light.hpp:163
Light(Light &&)=default
void addAnimation(const std::shared_ptr< Animation > &anim)
Definition: Light.cpp:15
const glm::mat4 & model() const
Definition: Light.hpp:93
glm::mat4 _model
Model matrix of the mesh containing the light-covered region.
Definition: Light.hpp:167
virtual ~Light()=default
void registerShadowMap(const Texture *map, ShadowMode mode, size_t layer=0, const glm::vec2 &minUV=glm::vec2(0.0f), const glm::vec2 &maxUV=glm::vec2(1.0f))
Definition: Light.hpp:108
virtual KeyValues encode() const
Definition: Light.cpp:34
Light()
Definition: Light.cpp:7
Light(const Light &)=delete
glm::vec3 _color
Colored intensity.
Definition: Light.hpp:168
void setCastShadow(bool shouldCast)
Definition: Light.hpp:73
virtual void draw(LightRenderer &renderer)=0
Base structure of a per-light specialized renderer.
Definition: LightRenderer.hpp:13
Represents a texture containing one or more images, stored on the CPU and/or GPU.
Definition: Texture.hpp:12
ShadowMode
Available shadow mapping techniques.
Definition: ShadowMap.hpp:14
Represent a key-values tuple.
Definition: Config.hpp:9
Definition: ShadowMap.hpp:55
size_t layer
The layer containing the shadow map.
Definition: ShadowMap.hpp:60
const Texture * map
The texture reference.
Definition: ShadowMap.hpp:56
glm::vec2 minUV
The bottom-left corner of the texture region.
Definition: ShadowMap.hpp:58
glm::vec2 maxUV
The upper-right corner of the texture region.
Definition: ShadowMap.hpp:59
ShadowMode mode
The shadow mode to use.
Definition: ShadowMap.hpp:57