diff --git a/libs/gfx/include/psemek/gfx/renderer/deferred.hpp b/libs/gfx/include/psemek/gfx/renderer/deferred.hpp index 79e47b76..6df03e40 100644 --- a/libs/gfx/include/psemek/gfx/renderer/deferred.hpp +++ b/libs/gfx/include/psemek/gfx/renderer/deferred.hpp @@ -70,6 +70,7 @@ namespace psemek::gfx color_3f color; geom::vector direction; bool shadowed = true; + std::size_t shadow_map_size = 1024; }; struct point_light @@ -83,6 +84,7 @@ namespace psemek::gfx geom::point position; bool shadowed = true; float min_shadow_distance; + std::size_t shadow_map_size = 1024; }; struct options diff --git a/libs/gfx/source/renderer/deferred.cpp b/libs/gfx/source/renderer/deferred.cpp index 204409b7..02247c6e 100644 --- a/libs/gfx/source/renderer/deferred.cpp +++ b/libs/gfx/source/renderer/deferred.cpp @@ -820,8 +820,6 @@ void main() gfx::array box_array; }; - static int const shadow_map_size = 1024; - deferred_renderer::deferred_renderer() : pimpl_{std::make_unique()} { @@ -854,24 +852,15 @@ void main() impl().point_light_pass_program["u_g3"] = 3; impl().point_light_pass_program["u_shadow"] = 4; - impl().directional_shadow_texture.load({shadow_map_size, shadow_map_size}); impl().directional_shadow_texture.linear_filter(); impl().directional_shadow_texture.clamp(); gl::TexParameteri(gl::TEXTURE_2D, gl::TEXTURE_COMPARE_MODE, gl::COMPARE_REF_TO_TEXTURE); gl::TexParameteri(gl::TEXTURE_2D, gl::TEXTURE_COMPARE_FUNC, gl::LEQUAL); - impl().directional_shadow_framebuffer.depth(impl().directional_shadow_texture); - impl().directional_shadow_framebuffer.assert_complete(); impl().point_shadow_texture.linear_filter(); impl().point_shadow_texture.clamp(); gl::TexParameteri(gl::TEXTURE_CUBE_MAP, gl::TEXTURE_COMPARE_MODE, gl::COMPARE_REF_TO_TEXTURE); gl::TexParameteri(gl::TEXTURE_CUBE_MAP, gl::TEXTURE_COMPARE_FUNC, gl::LEQUAL); - for (int f = 0; f < 6; ++f) - { - impl().point_shadow_texture.load(f, {shadow_map_size, shadow_map_size}); - } - impl().point_shadow_framebuffer.depth(impl().point_shadow_texture); - impl().point_shadow_framebuffer.assert_complete(); for (std::size_t i = 0; i < 3; ++i) { @@ -1528,6 +1517,14 @@ void main() impl().directional_shadow_framebuffer.bind(); gl::DrawBuffer(gl::NONE); + + if (impl().directional_shadow_texture.width() != l.shadow_map_size) + { + impl().directional_shadow_texture.load({l.shadow_map_size, l.shadow_map_size}); + impl().directional_shadow_framebuffer.depth(impl().directional_shadow_texture); + impl().directional_shadow_framebuffer.assert_complete(); + } + gl::Viewport(0, 0, impl().directional_shadow_texture.width(), impl().directional_shadow_texture.height()); gl::Clear(gl::DEPTH_BUFFER_BIT); @@ -1681,6 +1678,14 @@ void main() geom::matrix const translate_by_light = geom::translation(geom::point::zero() - l.position).homogeneous_matrix(); impl().point_shadow_framebuffer.bind(); + + if (impl().point_shadow_texture.width() != l.shadow_map_size) + { + for (int f = 0; f < 6; ++f) + impl().point_shadow_texture.load(f, {l.shadow_map_size, l.shadow_map_size}); + impl().point_shadow_framebuffer.depth(impl().point_shadow_texture); + impl().point_shadow_framebuffer.assert_complete(); + } gl::DrawBuffer(gl::NONE); gl::Viewport(0, 0, impl().point_shadow_texture.width(), impl().point_shadow_texture.height());