summaryrefslogtreecommitdiff
path: root/gfx
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2023-01-07 19:11:25 +0000
committerDan Goodliffe <dan@randomdan.homeip.net>2023-01-07 19:11:25 +0000
commite2fcb6ac75fe46c932d29ed056242158c99c1c11 (patch)
tree92307fa29392525aacb4d7835027c9e370ebb4f6 /gfx
parentUse the whole texture when only some shadow map bands (diff)
downloadilt-e2fcb6ac75fe46c932d29ed056242158c99c1c11.tar.bz2
ilt-e2fcb6ac75fe46c932d29ed056242158c99c1c11.tar.xz
ilt-e2fcb6ac75fe46c932d29ed056242158c99c1c11.zip
Tidy shadow map creation
Diffstat (limited to 'gfx')
-rw-r--r--gfx/gl/shadowMapper.cpp28
-rw-r--r--gfx/gl/shadowMapper.h2
2 files changed, 16 insertions, 14 deletions
diff --git a/gfx/gl/shadowMapper.cpp b/gfx/gl/shadowMapper.cpp
index 74b7dc0..01043e6 100644
--- a/gfx/gl/shadowMapper.cpp
+++ b/gfx/gl/shadowMapper.cpp
@@ -100,19 +100,14 @@ struct DefinitionsInserter {
ShadowMapper::Definitions & out;
};
-ShadowMapper::Definitions
-ShadowMapper::update(const SceneProvider & scene, const glm::vec3 & dir, const Camera & camera) const
+std::vector<std::array<glm::vec3, 4>>
+ShadowMapper::getBandViewExtents(const Camera & camera, const glm::mat4 & lightView)
{
- glBindFramebuffer(GL_FRAMEBUFFER, depthMapFBO);
- glViewport(0, 0, size.x, size.y);
- glClear(GL_DEPTH_BUFFER_BIT);
- glCullFace(GL_FRONT);
-
std::vector<std::array<glm::vec3, 4>> bandViewExtents;
for (const auto dist : shadowBands) {
const auto extents = camera.extentsAtDist(dist);
- bandViewExtents.emplace_back(extents * [](const auto & e) -> glm::vec3 {
- return e;
+ bandViewExtents.emplace_back(extents * [&lightView](const auto & e) -> glm::vec3 {
+ return lightView * glm::vec4(glm::vec3 {e}, 1);
});
if (std::none_of(extents.begin(), extents.end(), [targetDist = dist * 0.99F](const glm::vec4 & e) {
return e.w > targetDist;
@@ -120,13 +115,18 @@ ShadowMapper::update(const SceneProvider & scene, const glm::vec3 & dir, const C
break;
}
}
+ return bandViewExtents;
+}
+
+ShadowMapper::Definitions
+ShadowMapper::update(const SceneProvider & scene, const glm::vec3 & dir, const Camera & camera) const
+{
+ glBindFramebuffer(GL_FRAMEBUFFER, depthMapFBO);
+ glClear(GL_DEPTH_BUFFER_BIT);
+ glCullFace(GL_FRONT);
const auto lightView = glm::lookAt(camera.getPosition(), camera.getPosition() + dir, up);
- for (auto & band : bandViewExtents) {
- for (auto & e : band) {
- e = lightView * glm::vec4(e, 1);
- }
- }
+ const auto bandViewExtents = getBandViewExtents(camera, lightView);
Definitions out;
std::transform(bandViewExtents.begin(), std::prev(bandViewExtents.end()), std::next(bandViewExtents.begin()),
diff --git a/gfx/gl/shadowMapper.h b/gfx/gl/shadowMapper.h
index bdbd39f..2805d64 100644
--- a/gfx/gl/shadowMapper.h
+++ b/gfx/gl/shadowMapper.h
@@ -48,6 +48,8 @@ public:
}
private:
+ [[nodiscard]] static std::vector<std::array<glm::vec3, 4>> getBandViewExtents(
+ const Camera &, const glm::mat4 & lightView);
glFrameBuffer depthMapFBO;
glTexture depthMap;
glm::ivec2 size;