summaryrefslogtreecommitdiff
path: root/gfx
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2024-08-18 16:14:29 +0100
committerDan Goodliffe <dan@randomdan.homeip.net>2024-08-18 18:00:06 +0100
commit172beac34e82c86f8c16b8a1be5fca9d7ccfc0d1 (patch)
tree22607b9012b8140e6f80fad39f49d899ef12908c /gfx
parentAdd updateStencil to Renderable interface (diff)
downloadilt-172beac34e82c86f8c16b8a1be5fca9d7ccfc0d1.tar.bz2
ilt-172beac34e82c86f8c16b8a1be5fca9d7ccfc0d1.tar.xz
ilt-172beac34e82c86f8c16b8a1be5fca9d7ccfc0d1.zip
Update asset stencils from shadow mapper
Diffstat (limited to 'gfx')
-rw-r--r--gfx/gl/shadowMapper.cpp9
-rw-r--r--gfx/gl/shadowStenciller.cpp15
-rw-r--r--gfx/gl/shadowStenciller.h3
3 files changed, 18 insertions, 9 deletions
diff --git a/gfx/gl/shadowMapper.cpp b/gfx/gl/shadowMapper.cpp
index a846a3d..9b9e404 100644
--- a/gfx/gl/shadowMapper.cpp
+++ b/gfx/gl/shadowMapper.cpp
@@ -1,6 +1,7 @@
#include "shadowMapper.h"
#include "camera.h"
#include "collections.h"
+#include "game/gamestate.h"
#include "gfx/gl/shaders/fs-shadowDynamicPointInstWithTextures.h"
#include "gfx/gl/shaders/gs-commonShadowPoint.h"
#include "gfx/gl/shaders/gs-shadowDynamicPointInstWithTextures.h"
@@ -8,6 +9,8 @@
#include "gfx/gl/shaders/vs-shadowDynamicPointInst.h"
#include "gfx/gl/shaders/vs-shadowDynamicPointInstWithTextures.h"
#include "gfx/gl/shaders/vs-shadowLandmass.h"
+#include "gfx/gl/shadowStenciller.h"
+#include "gfx/renderable.h"
#include "gl_traits.h"
#include "location.h"
#include "maths.h"
@@ -74,6 +77,12 @@ ShadowMapper::getBandViewExtents(const Camera & camera, const glm::mat4 & lightV
ShadowMapper::Definitions
ShadowMapper::update(const SceneProvider & scene, const Direction3D & dir, const Camera & camera) const
{
+ ShadowStenciller shadowStenciller {dir, up};
+ for (const auto & [id, asset] : gameState->assets) {
+ if (const auto r = std::dynamic_pointer_cast<const Renderable>(asset)) {
+ r->updateStencil(shadowStenciller);
+ }
+ }
glBindFramebuffer(GL_FRAMEBUFFER, depthMapFBO);
glClear(GL_DEPTH_BUFFER_BIT);
glCullFace(GL_FRONT);
diff --git a/gfx/gl/shadowStenciller.cpp b/gfx/gl/shadowStenciller.cpp
index dc87d76..9f13808 100644
--- a/gfx/gl/shadowStenciller.cpp
+++ b/gfx/gl/shadowStenciller.cpp
@@ -1,15 +1,14 @@
#include "shadowStenciller.h"
-#include "config/types.h"
#include "gfx/gl/program.h"
#include "gfx/gl/shaders/fs-shadowStencil.h"
#include "gfx/gl/shaders/vs-shadowStencil.h"
#include "gfx/models/mesh.h"
#include "glArrays.h"
#include "gl_traits.h"
-#include "maths.h"
#include <stdexcept>
-ShadowStenciller::ShadowStenciller() : shadowCaster {shadowStencil_vs, shadowStencil_fs}
+ShadowStenciller::ShadowStenciller(const Direction3D & lightDir, const Direction3D & lightDirUp) :
+ shadowCaster {shadowStencil_vs, shadowStencil_fs}, lightDirMat {glm::lookAt(-lightDir, {}, lightDirUp)}
{
glBindFramebuffer(GL_FRAMEBUFFER, fbo);
glDrawBuffer(GL_NONE);
@@ -47,10 +46,10 @@ ShadowStenciller::renderStencil(const glTexture & stencil, const MeshBase & mesh
glClear(GL_DEPTH_BUFFER_BIT);
glViewport(0, 0, 256, 256);
glEnable(GL_DEPTH_TEST);
- const auto & mins = mesh.getDimensions().minExtent;
- const auto & maxs = mesh.getDimensions().maxExtent;
- const auto extents = glm::ortho(mins.x, maxs.x, mins.z, maxs.z, mins.y, maxs.y);
- const auto lightDir = glm::lookAt({}, north, up);
- glUniform(viewProjectionLoc, extents * lightDir);
+ const auto & centre = mesh.getDimensions().centre;
+ const auto & size = mesh.getDimensions().size;
+ const auto extentsMat
+ = glm::translate(glm::ortho(-size, size, -size, size, -size, size), {-centre.x, -centre.z, -centre.y});
+ glUniform(viewProjectionLoc, extentsMat * lightDirMat);
mesh.Draw();
}
diff --git a/gfx/gl/shadowStenciller.h b/gfx/gl/shadowStenciller.h
index bf6d204..87dc044 100644
--- a/gfx/gl/shadowStenciller.h
+++ b/gfx/gl/shadowStenciller.h
@@ -7,7 +7,7 @@
class ShadowStenciller {
public:
- ShadowStenciller();
+ ShadowStenciller(const Direction3D & lightDir, const Direction3D & lightDirUp);
[[nodiscard]]
static glTexture createStencilTexture(GLsizei width, GLsizei height);
@@ -16,5 +16,6 @@ public:
private:
glFrameBuffer fbo;
Program shadowCaster;
+ glm::mat4 lightDirMat;
Program::UniformLocation viewProjectionLoc {shadowCaster, "viewProjection"};
};