diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2024-08-18 16:14:29 +0100 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2024-08-18 18:00:06 +0100 |
commit | 172beac34e82c86f8c16b8a1be5fca9d7ccfc0d1 (patch) | |
tree | 22607b9012b8140e6f80fad39f49d899ef12908c /gfx/gl/shadowStenciller.cpp | |
parent | Add updateStencil to Renderable interface (diff) | |
download | ilt-172beac34e82c86f8c16b8a1be5fca9d7ccfc0d1.tar.bz2 ilt-172beac34e82c86f8c16b8a1be5fca9d7ccfc0d1.tar.xz ilt-172beac34e82c86f8c16b8a1be5fca9d7ccfc0d1.zip |
Update asset stencils from shadow mapper
Diffstat (limited to 'gfx/gl/shadowStenciller.cpp')
-rw-r--r-- | gfx/gl/shadowStenciller.cpp | 15 |
1 files changed, 7 insertions, 8 deletions
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(); } |