summaryrefslogtreecommitdiff
path: root/gfx/gl/shadowStenciller.cpp
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2024-09-07 12:35:03 +0100
committerDan Goodliffe <dan@randomdan.homeip.net>2024-09-07 12:35:03 +0100
commit5ec74c35fb1f2524add7fd03ace78667f93edb2e (patch)
treee8c560b6713aac68cc97bd957b5ffa8015ab75a0 /gfx/gl/shadowStenciller.cpp
parentPopulate all layers of the stencil texture (diff)
downloadilt-billboard-shadows.tar.bz2
ilt-billboard-shadows.tar.xz
ilt-billboard-shadows.zip
Populate all layers of shadow stencil with view from all aroundbillboard-shadows
Diffstat (limited to 'gfx/gl/shadowStenciller.cpp')
-rw-r--r--gfx/gl/shadowStenciller.cpp18
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();
}