lmgl 1.0.0
A lightweight OpenGL graphics engine library written in C++
Loading...
Searching...
No Matches
shadow_map.hpp
Go to the documentation of this file.
1
14#pragma once
15
17#include "lmgl/scene/light.hpp"
18#include "lmgl/scene/scene.hpp"
19
20#include <glad/glad.h>
21#include <glm/glm.hpp>
22
23#include <memory>
24
25namespace lmgl {
26
27namespace renderer {
28
38class ShadowMap {
39 public:
48 ShadowMap(unsigned int width = 2048, unsigned int height = 2048);
49
51 ~ShadowMap();
52
61 void bind();
62
69 void unbind();
70
79 void bind_texture(unsigned int slot = 0) const;
80
86 inline unsigned int get_texture_id() const { return m_depth_map; }
87
93 inline unsigned int get_width() const { return m_width; }
94
100 inline unsigned int get_height() const { return m_height; }
101
110 void resize(unsigned int width, unsigned int height);
111
112 private:
114 unsigned int m_fbo = 0;
115
117 unsigned int m_depth_map = 0;
118
120 unsigned int m_width;
121
123 unsigned int m_height;
124};
125
137 public:
145 CubemapShadowMap(unsigned int resolution = 1024);
146
149
160 void bind(unsigned int face);
161
168 void unbind();
169
178 void bind_texture(unsigned int slot = 0) const;
179
185 inline unsigned int get_texture_id() const { return m_depth_cubemap; }
186
192 inline unsigned int get_resolution() const { return m_resolution; }
193
199 inline unsigned int get_fbo() const { return m_fbo; }
200
201 private:
203 unsigned int m_fbo = 0;
204
206 unsigned int m_depth_cubemap = 0;
207
209 unsigned int m_resolution;
210};
211
220 public:
229
231 ~ShadowRenderer() = default;
232
243 void render_directional_shadow(std::shared_ptr<scene::Scene> scene, std::shared_ptr<scene::Light> light,
244 std::shared_ptr<ShadowMap> shadow_map);
245
256 void render_point_shadow(std::shared_ptr<scene::Scene> scene, std::shared_ptr<scene::Light> light,
257 std::shared_ptr<CubemapShadowMap> shadow_map);
258
270 glm::mat4 get_light_space_matrix(std::shared_ptr<scene::Light> light, const glm::vec3 &scene_center,
271 float scene_radius);
272
273 private:
274
276 std::shared_ptr<Shader> m_depth_shader;
277
279 std::shared_ptr<Shader> m_depth_cubemap_shader;
280
290 void render_scene_depth(std::shared_ptr<scene::Scene> scene, const glm::mat4 &light_space_matrix);
291};
292
293} // namespace renderer
294
295} // namespace lmgl
void unbind()
Unbinds the framebuffer object, returning to the default framebuffer.
Definition shadow_map.cpp:98
void bind(unsigned int face)
Binds the framebuffer object for rendering to a specific face of the cubemap shadow map.
Definition shadow_map.cpp:91
unsigned int get_resolution() const
Returns the resolution of each face of the cubemap shadow map.
Definition shadow_map.hpp:192
unsigned int get_fbo() const
Returns the OpenGL framebuffer object ID.
Definition shadow_map.hpp:199
~CubemapShadowMap()
Destructor for CubemapShadowMap.
Definition shadow_map.cpp:84
CubemapShadowMap(unsigned int resolution=1024)
Constructs a CubemapShadowMap with the specified resolution.
Definition shadow_map.cpp:61
unsigned int get_texture_id() const
Returns the OpenGL texture ID of the cubemap depth texture.
Definition shadow_map.hpp:185
void bind_texture(unsigned int slot=0) const
Binds the cubemap depth texture to the specified texture slot for use in shaders.
Definition shadow_map.cpp:100
ShadowMap(unsigned int width=2048, unsigned int height=2048)
Constructs a ShadowMap with the specified width and height.
Definition shadow_map.cpp:13
unsigned int get_texture_id() const
Returns the OpenGL texture ID of the depth texture.
Definition shadow_map.hpp:86
unsigned int get_width() const
Returns the width of the shadow map texture.
Definition shadow_map.hpp:93
void resize(unsigned int width, unsigned int height)
Resizes the shadow map texture to the specified width and height.
Definition shadow_map.cpp:54
void bind_texture(unsigned int slot=0) const
Binds the depth texture to the specified texture slot for use in shaders.
Definition shadow_map.cpp:49
void bind()
Binds the framebuffer object for rendering to the shadow map.
Definition shadow_map.cpp:41
unsigned int get_height() const
Returns the height of the shadow map texture.
Definition shadow_map.hpp:100
void unbind()
Unbinds the framebuffer object, returning to the default framebuffer.
Definition shadow_map.cpp:47
~ShadowMap()
Destructor for ShadowMap.
Definition shadow_map.cpp:34
ShadowRenderer()
Constructs a ShadowRenderer and initializes depth shaders.
Definition shadow_map.cpp:105
void render_directional_shadow(std::shared_ptr< scene::Scene > scene, std::shared_ptr< scene::Light > light, std::shared_ptr< ShadowMap > shadow_map)
Renders the shadow map for a directional light.
Definition shadow_map.cpp:110
void render_point_shadow(std::shared_ptr< scene::Scene > scene, std::shared_ptr< scene::Light > light, std::shared_ptr< CubemapShadowMap > shadow_map)
Renders the shadow map for a point light.
Definition shadow_map.cpp:131
glm::mat4 get_light_space_matrix(std::shared_ptr< scene::Light > light, const glm::vec3 &scene_center, float scene_radius)
Computes the light space matrix for a directional light.
Definition shadow_map.cpp:224
~ShadowRenderer()=default
Destructor for ShadowRenderer.
Definition of the Light class and LightType enumeration.
Namespace for rendering-related classes and functions.
Definition buffer.cpp:9
Namespace for scene-related classes and functions.
Definition camera.cpp:7
Forward declarations for Assimp Material structure.
Definition model_loader.cpp:12
Defines the Scene class for managing a 3D scene graph.
Declaration of the Shader class for managing shader programs in OpenGL.