summaryrefslogtreecommitdiff
path: root/gfx
diff options
context:
space:
mode:
Diffstat (limited to 'gfx')
-rw-r--r--gfx/gl/shadowMapper.cpp33
-rw-r--r--gfx/gl/shadowMapper.h6
2 files changed, 13 insertions, 26 deletions
diff --git a/gfx/gl/shadowMapper.cpp b/gfx/gl/shadowMapper.cpp
index 4141278..f3d5dea 100644
--- a/gfx/gl/shadowMapper.cpp
+++ b/gfx/gl/shadowMapper.cpp
@@ -140,8 +140,7 @@ ShadowMapper::update(const SceneProvider & scene, const Direction3D & dir, const
Definitions out;
std::transform(bandViewExtents.begin(), std::prev(bandViewExtents.end()), std::next(bandViewExtents.begin()),
DefinitionsInserter {out},
- [this, bands = bandViewExtents.size() - 2, &out, &lightViewDir](
- const auto & near, const auto & far) mutable {
+ [bands = bandViewExtents.size() - 2, &lightViewDir](const auto & near, const auto & far) mutable {
const auto extents_minmax = [extents = std::span {near.begin(), far.end()}](auto && comp) {
const auto mm = std::minmax_element(extents.begin(), extents.end(), comp);
return std::make_pair(comp.get(*mm.first), comp.get(*mm.second));
@@ -152,15 +151,13 @@ ShadowMapper::update(const SceneProvider & scene, const Direction3D & dir, const
}(extents_minmax(CompareBy {0}), extents_minmax(CompareBy {1}), extents_minmax(CompareBy {2}));
const auto lightViewDirProjection = lightProjection * lightViewDir;
- fixedPoint.setViewProjection(lightViewDirProjection, out.maps);
- dynamicPoint.setViewProjection(lightViewDirProjection, out.maps);
- dynamicPointInst.setViewProjection(lightViewDirProjection, out.maps);
return std::make_pair(lightViewDirProjection, shadowMapRegions[0][0]);
});
- fixedPoint.setViewPoint(lightViewPoint, out.maps);
- dynamicPoint.setViewPoint(lightViewPoint, out.maps);
- dynamicPointInst.setViewPoint(lightViewPoint, out.maps);
+ std::span vps {out.projections.data(), out.maps};
+ for (const auto p : std::initializer_list<const ShadowProgram *> {&fixedPoint, &dynamicPoint, &dynamicPointInst}) {
+ p->setView(vps, lightViewPoint);
+ }
scene.shadows(*this);
glCullFace(GL_BACK);
@@ -169,29 +166,19 @@ ShadowMapper::update(const SceneProvider & scene, const Direction3D & dir, const
}
ShadowMapper::ShadowProgram::ShadowProgram(const Shader & vs) :
- Program {vs, commonShadowPoint_gs}, viewProjectionLoc {{
- {*this, "viewProjection[0]"},
- {*this, "viewProjection[1]"},
- {*this, "viewProjection[2]"},
- {*this, "viewProjection[3]"},
- }},
+ Program {vs, commonShadowPoint_gs}, viewProjectionLoc {*this, "viewProjection"},
viewProjectionsLoc {*this, "viewProjections"}, viewPointLoc {*this, "viewPoint"}
{
}
void
-ShadowMapper::ShadowProgram::setViewPoint(const GlobalPosition3D viewPoint, size_t n) const
+ShadowMapper::ShadowProgram::setView(
+ const std::span<const glm::mat4> viewProjection, const GlobalPosition3D viewPoint) const
{
use();
glUniform(viewPointLoc, viewPoint);
- glUniform(viewProjectionsLoc, static_cast<GLint>(n));
-}
-
-void
-ShadowMapper::ShadowProgram::setViewProjection(const glm::mat4 & viewProjection, size_t n) const
-{
- use();
- glUniform(viewProjectionLoc[n], viewProjection);
+ glUniform(viewProjectionLoc, viewProjection);
+ glUniform(viewProjectionsLoc, static_cast<GLint>(viewProjection.size()));
}
void
diff --git a/gfx/gl/shadowMapper.h b/gfx/gl/shadowMapper.h
index 4f81e58..b948f50 100644
--- a/gfx/gl/shadowMapper.h
+++ b/gfx/gl/shadowMapper.h
@@ -5,6 +5,7 @@
#include "program.h"
#include <gfx/models/texture.h>
#include <glm/vec2.hpp>
+#include <span>
#include <vector>
class SceneProvider;
@@ -28,12 +29,11 @@ public:
public:
explicit ShadowProgram(const Shader & vs);
- void setViewPoint(const GlobalPosition3D, size_t n) const;
- void setViewProjection(const glm::mat4 &, size_t n) const;
+ void setView(const std::span<const glm::mat4>, const GlobalPosition3D) const;
void use() const;
private:
- std::array<RequiredUniformLocation, 4> viewProjectionLoc;
+ RequiredUniformLocation viewProjectionLoc;
RequiredUniformLocation viewProjectionsLoc;
RequiredUniformLocation viewPointLoc;
};