summaryrefslogtreecommitdiff
path: root/gfx/gl/shadowMapper.cpp
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2023-12-17 18:58:53 +0000
committerDan Goodliffe <dan@randomdan.homeip.net>2023-12-17 18:58:53 +0000
commitedb63bcb5fd140d0d4db71e170a43f767a4b70be (patch)
tree2703b2e4517ead609738e2597e0ab20670643573 /gfx/gl/shadowMapper.cpp
parentUse new calc types in camera extents to address overflow (diff)
downloadilt-edb63bcb5fd140d0d4db71e170a43f767a4b70be.tar.bz2
ilt-edb63bcb5fd140d0d4db71e170a43f767a4b70be.tar.xz
ilt-edb63bcb5fd140d0d4db71e170a43f767a4b70be.zip
Run shadow mapper in camera relative space
Diffstat (limited to 'gfx/gl/shadowMapper.cpp')
-rw-r--r--gfx/gl/shadowMapper.cpp16
1 files changed, 8 insertions, 8 deletions
diff --git a/gfx/gl/shadowMapper.cpp b/gfx/gl/shadowMapper.cpp
index deb0630..74d93bd 100644
--- a/gfx/gl/shadowMapper.cpp
+++ b/gfx/gl/shadowMapper.cpp
@@ -106,14 +106,15 @@ struct DefinitionsInserter {
};
std::vector<std::array<Position3D, 4>>
-ShadowMapper::getBandViewExtents(const Camera & camera, const glm::mat4 & lightView)
+ShadowMapper::getBandViewExtents(const Camera & camera, const glm::mat4 & lightViewDir)
{
std::vector<std::array<Position3D, 4>> bandViewExtents;
for (const auto dist : shadowBands) {
const auto extents = camera.extentsAtDist(dist);
- bandViewExtents.emplace_back(extents * [&lightView](const auto & e) -> Position3D {
- return lightView * glm::vec4(Position3D {e}, 1);
- });
+ bandViewExtents.emplace_back(
+ extents * [&lightViewDir, cameraPos = camera.getPosition()](const auto & e) -> Position3D {
+ return lightViewDir * RelativePosition4D(e.xyz() - cameraPos, 1);
+ });
if (std::none_of(extents.begin(), extents.end(), [targetDist = dist - 1](const auto & e) {
return e.w > targetDist;
})) {
@@ -131,14 +132,13 @@ ShadowMapper::update(const SceneProvider & scene, const Direction3D & dir, const
glCullFace(GL_FRONT);
const auto lightViewDir = glm::lookAt(origin, dir, up);
- const auto lightView = lightViewDir * glm::translate(RelativePosition3D {-camera.getPosition()});
const auto lightViewPoint = camera.getPosition();
- const auto bandViewExtents = getBandViewExtents(camera, lightView);
+ const auto bandViewExtents = getBandViewExtents(camera, lightViewDir);
Definitions out;
std::transform(bandViewExtents.begin(), std::prev(bandViewExtents.end()), std::next(bandViewExtents.begin()),
DefinitionsInserter {out},
- [&scene, this, &lightView, bands = bandViewExtents.size() - 2, &out, &lightViewPoint, &lightViewDir](
+ [&scene, this, bands = bandViewExtents.size() - 2, &out, &lightViewPoint, &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);
@@ -158,7 +158,7 @@ ShadowMapper::update(const SceneProvider & scene, const Direction3D & dir, const
glViewport(size.x >> viewport.x, size.y >> viewport.y, size.x >> viewport.z, size.y >> viewport.w);
scene.shadows(*this);
- return std::make_pair(lightProjection * lightView, shadowMapRegions[bands][out.maps]);
+ return std::make_pair(lightViewDirProjection, shadowMapRegions[bands][out.maps]);
});
glCullFace(GL_BACK);