diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2024-09-07 12:35:03 +0100 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2024-09-07 12:35:03 +0100 |
commit | 5ec74c35fb1f2524add7fd03ace78667f93edb2e (patch) | |
tree | e8c560b6713aac68cc97bd957b5ffa8015ab75a0 /gfx/gl/shadowStenciller.cpp | |
parent | Populate all layers of the stencil texture (diff) | |
download | ilt-5ec74c35fb1f2524add7fd03ace78667f93edb2e.tar.bz2 ilt-5ec74c35fb1f2524add7fd03ace78667f93edb2e.tar.xz ilt-5ec74c35fb1f2524add7fd03ace78667f93edb2e.zip |
Populate all layers of shadow stencil with view from all around
Diffstat (limited to 'gfx/gl/shadowStenciller.cpp')
-rw-r--r-- | gfx/gl/shadowStenciller.cpp | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/gfx/gl/shadowStenciller.cpp b/gfx/gl/shadowStenciller.cpp index 1063b71..da2b3a0 100644 --- a/gfx/gl/shadowStenciller.cpp +++ b/gfx/gl/shadowStenciller.cpp @@ -6,9 +6,18 @@ #include "gfx/models/mesh.h" #include "glArrays.h" #include "gl_traits.h" +#include "maths.h" #include <stdexcept> -ShadowStenciller::ShadowStenciller() : shadowCaster {shadowStencil_vs, shadowStencil_gs, shadowStencil_fs} +namespace { + static constexpr std::array<float, 8> anglesEigthPi {-3, -2, -1, 0, 1, 2, 3, 4}; + static const auto angles = anglesEigthPi * [](auto ep) { + return rotate_yaw(ep * quarter_pi); + }; +} + +ShadowStenciller::ShadowStenciller() : + shadowCaster {shadowStencil_vs, shadowStencil_gs, shadowStencil_fs}, viewProjections {} { glBindFramebuffer(GL_FRAMEBUFFER, fbo); glDrawBuffer(GL_NONE); @@ -20,6 +29,9 @@ void ShadowStenciller::setLightDirection(const Direction3D & lightDir, const Direction3D & lightDirUp) { lightDirMat = glm::lookAt(-lightDir, {}, lightDirUp); + viewProjections = angles * [this](const auto & a) { + return lightDirMat * a; + }; } glTexture @@ -58,6 +70,8 @@ ShadowStenciller::renderStencil(const glTexture & stencil, const MeshBase & mesh 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); + glUniform(viewProjectionLoc, std::span<const glm::mat4> {viewProjections * [&](const auto & vp) { + return extentsMat * vp; + }}); mesh.Draw(); } |