diff options
Diffstat (limited to 'gfx/gl')
-rw-r--r-- | gfx/gl/shaders/directionalLight.fs | 2 | ||||
-rw-r--r-- | gfx/gl/shadowMapper.cpp | 28 | ||||
-rw-r--r-- | gfx/gl/shadowMapper.h | 3 |
3 files changed, 23 insertions, 10 deletions
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<glm::ivec4, 1> viewports {{ - {31, 31, 0, 0}, +constexpr std::array<glm::ivec4, ShadowMapper::SHADOW_BANDS> viewports {{ + {31, 31, 1, 1}, + {1, 31, 1, 1}, + {31, 1, 1, 1}, + {1, 1, 1, 1}, }}; -constexpr std::array<glm::vec4, 1> shadowMapRegions { - {{0.5F, 0.5F, 0.5F, 0.5F}}, +constexpr std::array<glm::vec4, ShadowMapper::SHADOW_BANDS> 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<float, ShadowMapper::SHADOW_BANDS + 1> 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::SHADOW_BANDS> 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<SHADOW_BANDS> 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<std::size_t S> struct Definitions { std::array<glm::mat4x4, S> projections; std::array<glm::vec4, S> regions; }; - Definitions<1> update(const SceneProvider &, const glm::vec3 & direction, const Camera &) const; + Definitions<SHADOW_BANDS> update(const SceneProvider &, const glm::vec3 & direction, const Camera &) const; class FixedPoint : public Program { public: |