summaryrefslogtreecommitdiff
path: root/gfx
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2024-08-19 23:26:32 +0100
committerDan Goodliffe <dan@randomdan.homeip.net>2024-08-19 23:26:32 +0100
commitdd452f3e9238be954c3ecd325ed11e97a50ec1c3 (patch)
treeffe8390a875dbd252085ec0ee3ec1cd8cd68a0c7 /gfx
parentShuffle some GL state setting (diff)
downloadilt-dd452f3e9238be954c3ecd325ed11e97a50ec1c3.tar.bz2
ilt-dd452f3e9238be954c3ecd325ed11e97a50ec1c3.tar.xz
ilt-dd452f3e9238be954c3ecd325ed11e97a50ec1c3.zip
Persist a single ShadowStenciller within ShadowMapper
Diffstat (limited to 'gfx')
-rw-r--r--gfx/gl/shadowMapper.cpp2
-rw-r--r--gfx/gl/shadowMapper.h2
-rw-r--r--gfx/gl/shadowStenciller.cpp9
-rw-r--r--gfx/gl/shadowStenciller.h6
4 files changed, 14 insertions, 5 deletions
diff --git a/gfx/gl/shadowMapper.cpp b/gfx/gl/shadowMapper.cpp
index ff0634e..d9dd24f 100644
--- a/gfx/gl/shadowMapper.cpp
+++ b/gfx/gl/shadowMapper.cpp
@@ -80,7 +80,7 @@ ShadowMapper::update(const SceneProvider & scene, const Direction3D & dir, const
glCullFace(GL_FRONT);
glEnable(GL_DEPTH_TEST);
- ShadowStenciller shadowStenciller {dir, up};
+ shadowStenciller.setLightDirection(dir, up);
for (const auto & [id, asset] : gameState->assets) {
if (const auto r = std::dynamic_pointer_cast<const Renderable>(asset)) {
r->updateStencil(shadowStenciller);
diff --git a/gfx/gl/shadowMapper.h b/gfx/gl/shadowMapper.h
index 73dadd0..280a0cd 100644
--- a/gfx/gl/shadowMapper.h
+++ b/gfx/gl/shadowMapper.h
@@ -1,6 +1,7 @@
#pragma once
#include "config/types.h"
+#include "gfx/gl/shadowStenciller.h"
#include "lib/glArrays.h"
#include "program.h"
#include <gfx/models/texture.h>
@@ -61,4 +62,5 @@ private:
glFrameBuffer depthMapFBO;
glTexture depthMap;
TextureAbsCoord size;
+ mutable ShadowStenciller shadowStenciller;
};
diff --git a/gfx/gl/shadowStenciller.cpp b/gfx/gl/shadowStenciller.cpp
index fc3d77c..ac63b4e 100644
--- a/gfx/gl/shadowStenciller.cpp
+++ b/gfx/gl/shadowStenciller.cpp
@@ -7,8 +7,7 @@
#include "gl_traits.h"
#include <stdexcept>
-ShadowStenciller::ShadowStenciller(const Direction3D & lightDir, const Direction3D & lightDirUp) :
- shadowCaster {shadowStencil_vs, shadowStencil_fs}, lightDirMat {glm::lookAt(-lightDir, {}, lightDirUp)}
+ShadowStenciller::ShadowStenciller() : shadowCaster {shadowStencil_vs, shadowStencil_fs}
{
glBindFramebuffer(GL_FRAMEBUFFER, fbo);
glDrawBuffer(GL_NONE);
@@ -16,6 +15,12 @@ ShadowStenciller::ShadowStenciller(const Direction3D & lightDir, const Direction
glBindFramebuffer(GL_FRAMEBUFFER, 0);
}
+void
+ShadowStenciller::setLightDirection(const Direction3D & lightDir, const Direction3D & lightDirUp)
+{
+ lightDirMat = glm::lookAt(-lightDir, {}, lightDirUp);
+}
+
glTexture
ShadowStenciller::createStencilTexture(GLsizei width, GLsizei height)
{
diff --git a/gfx/gl/shadowStenciller.h b/gfx/gl/shadowStenciller.h
index 87dc044..009285c 100644
--- a/gfx/gl/shadowStenciller.h
+++ b/gfx/gl/shadowStenciller.h
@@ -7,15 +7,17 @@
class ShadowStenciller {
public:
- ShadowStenciller(const Direction3D & lightDir, const Direction3D & lightDirUp);
+ ShadowStenciller();
[[nodiscard]]
static glTexture createStencilTexture(GLsizei width, GLsizei height);
+ void setLightDirection(const Direction3D & lightDir, const Direction3D & lightDirUp);
void renderStencil(const glTexture &, const MeshBase &, const Texture::AnyPtr texture) const;
private:
glFrameBuffer fbo;
Program shadowCaster;
- glm::mat4 lightDirMat;
Program::UniformLocation viewProjectionLoc {shadowCaster, "viewProjection"};
+
+ glm::mat4 lightDirMat {};
};