Rendu
A lightweight rendering engine for experimentations
Loading...
Searching...
No Matches
SpotLight.hpp
1#pragma once
2
3#include "scene/lights/Light.hpp"
4#include "scene/Animated.hpp"
5#include "scene/Object.hpp"
6
13class SpotLight final : public Light {
14
15public:
17 SpotLight() = default;
18
27 SpotLight(const glm::vec3 & worldPosition, const glm::vec3 & worldDirection, const glm::vec3 & color, float innerAngle, float outerAngle, float radius);
28
32 void draw(LightRenderer & renderer) override;
33
37 void update(double fullTime, double frameTime) override;
38
42 void setScene(const BoundingBox & sceneBox) override;
43
47 glm::vec3 sample(const glm::vec3 & position, float & dist, float & attenuation) const override;
48
64 bool decode(const KeyValues & params);
65
69 KeyValues encode() const override;
70
74 const glm::vec3 & position() const { return _lightPosition; }
75
79 const glm::vec3 & direction() const { return _lightDirection; }
80
84 const glm::vec2 & angles() const { return _angles; }
85
89 float radius() const { return _radius; }
90
91private:
92
93 glm::mat4 _projectionMatrix = glm::mat4(1.0f);
94 glm::mat4 _viewMatrix = glm::mat4(1.0f);
95 Animated<glm::vec3> _lightDirection { glm::vec3(1.0f, 0.0f, 0.0f) };
96 Animated<glm::vec3> _lightPosition { glm::vec3(0.0f) };
97 glm::vec2 _angles = glm::vec2(glm::quarter_pi<float>(), glm::half_pi<float>());
98 float _radius = 1.0f;
99};
Wraps an animated property so that the initial value is preserved.
Definition: Animated.hpp:11
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
Base structure of a per-light specialized renderer.
Definition: LightRenderer.hpp:13
A spotlight, where light rays in a given cone are radiating from a single point in space....
Definition: SpotLight.hpp:13
const glm::vec3 & direction() const
Definition: SpotLight.hpp:79
glm::mat4 _viewMatrix
Light view matrix.
Definition: SpotLight.hpp:94
SpotLight()=default
KeyValues encode() const override
Definition: SpotLight.cpp:109
glm::vec3 sample(const glm::vec3 &position, float &dist, float &attenuation) const override
Definition: SpotLight.cpp:52
void draw(LightRenderer &renderer) override
Definition: SpotLight.cpp:11
const glm::vec3 & position() const
Definition: SpotLight.hpp:74
void update(double fullTime, double frameTime) override
Definition: SpotLight.cpp:15
glm::mat4 _projectionMatrix
Light projection matrix.
Definition: SpotLight.hpp:93
float _radius
The attenuation radius.
Definition: SpotLight.hpp:98
const glm::vec2 & angles() const
Definition: SpotLight.hpp:84
Animated< glm::vec3 > _lightDirection
Light direction.
Definition: SpotLight.hpp:95
glm::vec2 _angles
The inner and outer cone attenuation angles.
Definition: SpotLight.hpp:97
Animated< glm::vec3 > _lightPosition
Light position.
Definition: SpotLight.hpp:96
bool decode(const KeyValues &params)
Definition: SpotLight.cpp:83
void setScene(const BoundingBox &sceneBox) override
Definition: SpotLight.cpp:27
float radius() const
Definition: SpotLight.hpp:89
Represent a key-values tuple.
Definition: Config.hpp:9