summaryrefslogtreecommitdiff
path: root/gfx/gl
diff options
context:
space:
mode:
Diffstat (limited to 'gfx/gl')
-rw-r--r--gfx/gl/shaders/shadowStencil.gs6
-rw-r--r--gfx/gl/shadowStenciller.cpp18
-rw-r--r--gfx/gl/shadowStenciller.h1
3 files changed, 20 insertions, 5 deletions
diff --git a/gfx/gl/shaders/shadowStencil.gs b/gfx/gl/shaders/shadowStencil.gs
index eea4643..2c3f9bd 100644
--- a/gfx/gl/shaders/shadowStencil.gs
+++ b/gfx/gl/shaders/shadowStencil.gs
@@ -6,7 +6,7 @@ include(`materialDetail.glsl')
layout(triangles) in;
layout(triangle_strip, max_vertices = 24) out;
-uniform mat4 viewProjection;
+uniform mat4 viewProjection[8];
in vec3 FragPos[];
in vec2 TexCoords[];
flat in MaterialDetail Material[];
@@ -16,9 +16,9 @@ flat out MaterialDetail gMaterial;
void
main()
{
- for (gl_Layer = 0; gl_Layer < 8; ++gl_Layer) {
+ for (gl_Layer = 0; gl_Layer < viewProjection.length(); ++gl_Layer) {
for (int v = 0; v < FragPos.length(); ++v) {
- gl_Position = viewProjection * vec4(FragPos[v], 1);
+ gl_Position = viewProjection[gl_Layer] * vec4(FragPos[v], 1);
gTexCoords = TexCoords[v];
gMaterial = Material[v];
EmitVertex();
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();
}
diff --git a/gfx/gl/shadowStenciller.h b/gfx/gl/shadowStenciller.h
index 925f82a..2edb955 100644
--- a/gfx/gl/shadowStenciller.h
+++ b/gfx/gl/shadowStenciller.h
@@ -20,4 +20,5 @@ private:
Program::RequiredUniformLocation viewProjectionLoc {shadowCaster, "viewProjection"};
glm::mat4 lightDirMat {};
+ std::array<glm::mat4, 8> viewProjections;
};