From 66047d123769245e3b5cb8bbe748aefb13db16d4 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Wed, 28 Dec 2022 19:36:00 +0000 Subject: Generate 4 bands of shadow maps --- gfx/gl/shaders/directionalLight.fs | 2 +- gfx/gl/shadowMapper.cpp | 28 ++++++++++++++++++++-------- gfx/gl/shadowMapper.h | 3 ++- 3 files changed, 23 insertions(+), 10 deletions(-) (limited to 'gfx') diff --git a/gfx/gl/shaders/directionalLight.fs b/gfx/gl/shaders/directionalLight.fs index fa1e38d..ca10ef5 100644 --- a/gfx/gl/shaders/directionalLight.fs +++ b/gfx/gl/shaders/directionalLight.fs @@ -1,7 +1,7 @@ #version 330 core #extension GL_ARB_shading_language_420pack : enable -const int MAX_MAPS = 3; +const int MAX_MAPS = 4; out vec3 FragColor; diff --git a/gfx/gl/shadowMapper.cpp b/gfx/gl/shadowMapper.cpp index b41a53b..f1beb82 100644 --- a/gfx/gl/shadowMapper.cpp +++ b/gfx/gl/shadowMapper.cpp @@ -33,17 +33,29 @@ ShadowMapper::ShadowMapper(const glm::ivec2 & s) : size {s} glBindFramebuffer(GL_FRAMEBUFFER, 0); } -constexpr std::array viewports {{ - {31, 31, 0, 0}, +constexpr std::array viewports {{ + {31, 31, 1, 1}, + {1, 31, 1, 1}, + {31, 1, 1, 1}, + {1, 1, 1, 1}, }}; -constexpr std::array shadowMapRegions { - {{0.5F, 0.5F, 0.5F, 0.5F}}, +constexpr std::array shadowMapRegions {{ + {0.25F, 0.25F, 0.25F, 0.25F}, + {0.25F, 0.25F, 0.75F, 0.25F}, + {0.25F, 0.25F, 0.25F, 0.75F}, + {0.25F, 0.25F, 0.75F, 0.75F}, +}}; +constexpr std::array shadowBands { + 1.F, + 250.F, + 750.F, + 2500.F, + 10000.F, }; -constexpr std::array shadowBands {1.F, 1000.F}; static_assert(viewports.size() == shadowMapRegions.size()); static_assert(shadowBands.size() == shadowMapRegions.size() + 1); -ShadowMapper::Definitions<1> +ShadowMapper::Definitions ShadowMapper::update(const SceneProvider & scene, const glm::vec3 & dir, const Camera & camera) const { glBindFramebuffer(GL_FRAMEBUFFER, depthMapFBO); @@ -61,8 +73,8 @@ ShadowMapper::update(const SceneProvider & scene, const glm::vec3 & dir, const C for (auto & e : viewExtents) { e = lightView * glm::vec4(e, 1); } - Definitions<1> out; - for (std::size_t band = 0; band < viewports.size(); ++band) { + Definitions out; + for (std::size_t band = 0; band < SHADOW_BANDS; ++band) { const auto extents_minmax = [extents = viewExtents.subspan(band * 4, 8)](auto && comp) { const auto mm = std::minmax_element(extents.begin(), extents.end(), comp); return std::make_pair(comp.get(*mm.first), comp.get(*mm.second)); diff --git a/gfx/gl/shadowMapper.h b/gfx/gl/shadowMapper.h index d5f091e..7065ffe 100644 --- a/gfx/gl/shadowMapper.h +++ b/gfx/gl/shadowMapper.h @@ -11,11 +11,12 @@ class ShadowMapper { public: ShadowMapper(const glm::ivec2 & size); + static constexpr std::size_t SHADOW_BANDS {4}; template struct Definitions { std::array projections; std::array regions; }; - Definitions<1> update(const SceneProvider &, const glm::vec3 & direction, const Camera &) const; + Definitions update(const SceneProvider &, const glm::vec3 & direction, const Camera &) const; class FixedPoint : public Program { public: -- cgit v1.2.3