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
194 private:
196 unsigned int m_fbo = 0;
197
199 unsigned int m_depth_cubemap = 0;
200
202 unsigned int m_resolution;
203};
204
213 public:
222
224 ~ShadowRenderer() = default;
225
236 void render_directional_shadow(std::shared_ptr<scene::Scene> scene, std::shared_ptr<scene::Light> light,
237 std::shared_ptr<ShadowMap> shadow_map);
238
249 void render_point_shadow(std::shared_ptr<scene::Scene> scene, std::shared_ptr<scene::Light> light,
250 std::shared_ptr<CubemapShadowMap> shadow_map);
251
263 glm::mat4 get_light_space_matrix(std::shared_ptr<scene::Light> light, const glm::vec3 &scene_center,
264 float scene_radius);
265
266 private:
267
269 std::shared_ptr<Shader> m_depth_shader;
270
272 std::shared_ptr<Shader> m_depth_cubemap_shader;
273
283 void render_scene_depth(std::shared_ptr<scene::Scene> scene, const glm::mat4 &light_space_matrix);
284};
285
286} // namespace renderer
287
288} // namespace lmgl
void unbind()
Unbinds the framebuffer object, returning to the default framebuffer.
Definition shadow_map.cpp:103
void bind(unsigned int face)
Binds the framebuffer object for rendering to a specific face of the cubemap shadow map.
Definition shadow_map.cpp:95
unsigned int get_resolution() const
Returns the resolution of each face of the cubemap shadow map.
Definition shadow_map.hpp:192
~CubemapShadowMap()
Destructor for CubemapShadowMap.
Definition shadow_map.cpp:88
CubemapShadowMap(unsigned int resolution=1024)
Constructs a CubemapShadowMap with the specified resolution.
Definition shadow_map.cpp:65
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:105
ShadowMap(unsigned int width=2048, unsigned int height=2048)
Constructs a ShadowMap with the specified width and height.
Definition shadow_map.cpp:15
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:56
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:51
void bind()
Binds the framebuffer object for rendering to the shadow map.
Definition shadow_map.cpp:43
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:49
~ShadowMap()
Destructor for ShadowMap.
Definition shadow_map.cpp:36
ShadowRenderer()
Constructs a ShadowRenderer and initializes depth shaders.
Definition shadow_map.cpp:112
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:117
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:140
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:218
~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.