summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2024-01-27 22:49:54 +0000
committerDan Goodliffe <dan@randomdan.homeip.net>2024-01-27 22:49:54 +0000
commitdad6fe3b6227b5d3e78913e164b1f688de1605a8 (patch)
treeddd3854afb250177ec5f12963d8c5315dc8825b3
parent3D relative scaling in asset factory (diff)
downloadilt-dad6fe3b6227b5d3e78913e164b1f688de1605a8.tar.bz2
ilt-dad6fe3b6227b5d3e78913e164b1f688de1605a8.tar.xz
ilt-dad6fe3b6227b5d3e78913e164b1f688de1605a8.zip
Set light view point uniform once
Not once per shadow pass
-rw-r--r--gfx/gl/shadowMapper.cpp31
-rw-r--r--gfx/gl/shadowMapper.h6
2 files changed, 27 insertions, 10 deletions
diff --git a/gfx/gl/shadowMapper.cpp b/gfx/gl/shadowMapper.cpp
index ab4ac50..040010f 100644
--- a/gfx/gl/shadowMapper.cpp
+++ b/gfx/gl/shadowMapper.cpp
@@ -134,11 +134,14 @@ ShadowMapper::update(const SceneProvider & scene, const Direction3D & dir, const
const auto lightViewDir = glm::lookAt({}, dir, up);
const auto lightViewPoint = camera.getPosition();
const auto bandViewExtents = getBandViewExtents(camera, lightViewDir);
+ fixedPoint.setViewPoint(lightViewPoint);
+ dynamicPoint.setViewPoint(lightViewPoint);
+ dynamicPointInst.setViewPoint(lightViewPoint);
Definitions out;
std::transform(bandViewExtents.begin(), std::prev(bandViewExtents.end()), std::next(bandViewExtents.begin()),
DefinitionsInserter {out},
- [&scene, this, bands = bandViewExtents.size() - 2, &out, &lightViewPoint, &lightViewDir](
+ [&scene, this, bands = bandViewExtents.size() - 2, &out, &lightViewDir](
const auto & near, const auto & far) {
const auto extents_minmax = [extents = std::span {near.begin(), far.end()}](auto && comp) {
const auto mm = std::minmax_element(extents.begin(), extents.end(), comp);
@@ -150,9 +153,9 @@ 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(lightViewPoint, lightViewDirProjection);
- dynamicPoint.setViewProjection(lightViewPoint, lightViewDirProjection);
- dynamicPointInst.setViewProjection(lightViewPoint, lightViewDirProjection);
+ fixedPoint.setViewProjection(lightViewDirProjection);
+ dynamicPoint.setViewProjection(lightViewDirProjection);
+ dynamicPointInst.setViewProjection(lightViewDirProjection);
const auto & viewport = viewports[bands][out.maps];
glViewport(size.x >> viewport.x, size.y >> viewport.y, size.x >> viewport.z, size.y >> viewport.w);
@@ -172,14 +175,20 @@ ShadowMapper::FixedPoint::FixedPoint(const Shader & vs) :
}
void
-ShadowMapper::FixedPoint::setViewProjection(const GlobalPosition3D viewPoint, const glm::mat4 & viewProjection) const
+ShadowMapper::FixedPoint::setViewPoint(const GlobalPosition3D viewPoint) const
{
use();
- glUniform(viewProjectionLoc, viewProjection);
glUniform(viewPointLoc, viewPoint);
}
void
+ShadowMapper::FixedPoint::setViewProjection(const glm::mat4 & viewProjection) const
+{
+ use();
+ glUniform(viewProjectionLoc, viewProjection);
+}
+
+void
ShadowMapper::FixedPoint::use() const
{
glUseProgram(*this);
@@ -192,14 +201,20 @@ ShadowMapper::DynamicPoint::DynamicPoint() :
}
void
-ShadowMapper::DynamicPoint::setViewProjection(const GlobalPosition3D viewPoint, const glm::mat4 & viewProjection) const
+ShadowMapper::DynamicPoint::setViewPoint(const GlobalPosition3D viewPoint) const
{
glUseProgram(*this);
- glUniform(viewProjectionLoc, viewProjection);
glUniform(viewPointLoc, viewPoint);
}
void
+ShadowMapper::DynamicPoint::setViewProjection(const glm::mat4 & viewProjection) const
+{
+ glUseProgram(*this);
+ glUniform(viewProjectionLoc, viewProjection);
+}
+
+void
ShadowMapper::DynamicPoint::use(const Location & location) const
{
glUseProgram(*this);
diff --git a/gfx/gl/shadowMapper.h b/gfx/gl/shadowMapper.h
index d1e4e10..065db4f 100644
--- a/gfx/gl/shadowMapper.h
+++ b/gfx/gl/shadowMapper.h
@@ -27,7 +27,8 @@ public:
class FixedPoint : public Program {
public:
FixedPoint(const Shader & vs);
- void setViewProjection(const GlobalPosition3D, const glm::mat4 &) const;
+ void setViewPoint(const GlobalPosition3D) const;
+ void setViewProjection(const glm::mat4 &) const;
void use() const;
private:
@@ -37,7 +38,8 @@ public:
class DynamicPoint : public Program {
public:
DynamicPoint();
- void setViewProjection(const GlobalPosition3D, const glm::mat4 &) const;
+ void setViewPoint(const GlobalPosition3D) const;
+ void setViewProjection(const glm::mat4 &) const;
void use(const Location &) const;
void setModel(const Location &) const;