Deferred renderer: make shadow map size an explicit rendering parameter
This commit is contained in:
parent
68cdd22083
commit
59888bd5eb
2 changed files with 18 additions and 11 deletions
|
|
@ -70,6 +70,7 @@ namespace psemek::gfx
|
|||
color_3f color;
|
||||
geom::vector<float, 3> direction;
|
||||
bool shadowed = true;
|
||||
std::size_t shadow_map_size = 1024;
|
||||
};
|
||||
|
||||
struct point_light
|
||||
|
|
@ -83,6 +84,7 @@ namespace psemek::gfx
|
|||
geom::point<float, 3> position;
|
||||
bool shadowed = true;
|
||||
float min_shadow_distance;
|
||||
std::size_t shadow_map_size = 1024;
|
||||
};
|
||||
|
||||
struct options
|
||||
|
|
|
|||
|
|
@ -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<struct impl>()}
|
||||
{
|
||||
|
|
@ -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<gfx::depth24_pixel>({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<gfx::depth24_pixel>(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<depth24_pixel>({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<float, 4, 4> const translate_by_light = geom::translation<float, 3>(geom::point<float, 3>::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<depth24_pixel>(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());
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue