diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2024-01-27 22:49:54 +0000 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2024-01-27 22:49:54 +0000 |
commit | dad6fe3b6227b5d3e78913e164b1f688de1605a8 (patch) | |
tree | ddd3854afb250177ec5f12963d8c5315dc8825b3 /gfx/gl/shadowMapper.cpp | |
parent | 3D relative scaling in asset factory (diff) | |
download | ilt-dad6fe3b6227b5d3e78913e164b1f688de1605a8.tar.bz2 ilt-dad6fe3b6227b5d3e78913e164b1f688de1605a8.tar.xz ilt-dad6fe3b6227b5d3e78913e164b1f688de1605a8.zip |
Set light view point uniform once
Not once per shadow pass
Diffstat (limited to 'gfx/gl/shadowMapper.cpp')
-rw-r--r-- | gfx/gl/shadowMapper.cpp | 31 |
1 files changed, 23 insertions, 8 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); |