summaryrefslogtreecommitdiff
path: root/gfx
diff options
context:
space:
mode:
Diffstat (limited to 'gfx')
-rw-r--r--gfx/gl/sceneRenderer.cpp13
-rw-r--r--gfx/gl/sceneRenderer.h7
-rw-r--r--gfx/gl/shaders/directionalLight.fs17
-rw-r--r--gfx/gl/shadowMapper.cpp69
-rw-r--r--gfx/gl/shadowMapper.h6
5 files changed, 19 insertions, 93 deletions
diff --git a/gfx/gl/sceneRenderer.cpp b/gfx/gl/sceneRenderer.cpp
index b60d9af..2dd1760 100644
--- a/gfx/gl/sceneRenderer.cpp
+++ b/gfx/gl/sceneRenderer.cpp
@@ -116,7 +116,7 @@ SceneRenderer::setDirectionalLight(const RGB & colour, const Direction3D & direc
glBindFramebuffer(GL_FRAMEBUFFER, gBufferIll);
glViewport(0, 0, size.x, size.y);
dirLight.use();
- dirLight.setDirectionalLight(colour, direction, camera.getPosition(), lvp.projections, lvp.regions, lvp.maps);
+ dirLight.setDirectionalLight(colour, direction, camera.getPosition(), lvp);
renderQuad();
}
}
@@ -133,21 +133,18 @@ SceneRenderer::DirectionalLightProgram::DirectionalLightProgram() :
Program {lighting_vs, directionalLight_fs}, directionLoc {*this, "lightDirection"},
colourLoc {*this, "lightColour"}, lightPointLoc {*this, "lightPoint"},
lightViewProjectionLoc {*this, "lightViewProjection"},
- lightViewProjectionCountLoc {*this, "lightViewProjectionCount"},
- lightViewShadowMapRegionLoc {*this, "shadowMapRegion"}
+ lightViewProjectionCountLoc {*this, "lightViewProjectionCount"}
{
}
void
-SceneRenderer::DirectionalLightProgram::setDirectionalLight(const RGB & c, const Direction3D & d,
- const GlobalPosition3D & p, const std::span<const glm::mat4x4> lvp,
- const std::span<const TextureRelRegion> shadowMapRegions, std::size_t maps) const
+SceneRenderer::DirectionalLightProgram::setDirectionalLight(
+ const RGB & c, const Direction3D & d, const GlobalPosition3D & p, const std::span<const glm::mat4x4> lvp) const
{
glUniform(colourLoc, c);
const auto nd = glm::normalize(d);
glUniform(directionLoc, nd);
glUniform(lightPointLoc, p);
- glUniform(lightViewProjectionCountLoc, static_cast<GLuint>(maps));
+ glUniform(lightViewProjectionCountLoc, static_cast<GLuint>(lvp.size()));
glUniform(lightViewProjectionLoc, lvp);
- glUniform(lightViewShadowMapRegionLoc, shadowMapRegions);
}
diff --git a/gfx/gl/sceneRenderer.h b/gfx/gl/sceneRenderer.h
index 797ecf1..021936f 100644
--- a/gfx/gl/sceneRenderer.h
+++ b/gfx/gl/sceneRenderer.h
@@ -6,7 +6,6 @@
#include "sceneProvider.h"
#include "sceneShader.h"
#include "shadowMapper.h"
-#include <functional>
#include <glm/fwd.hpp>
class SceneRenderer {
@@ -39,12 +38,12 @@ protected:
DirectionalLightProgram();
using Program::use;
- void setDirectionalLight(const RGB &, const Direction3D &, const GlobalPosition3D &,
- const std::span<const glm::mat4x4>, const std::span<const TextureRelRegion>, std::size_t maps) const;
+ void setDirectionalLight(
+ const RGB &, const Direction3D &, const GlobalPosition3D &, const std::span<const glm::mat4x4>) const;
private:
RequiredUniformLocation directionLoc, colourLoc, lightPointLoc, lightViewProjectionLoc,
- lightViewProjectionCountLoc, lightViewShadowMapRegionLoc;
+ lightViewProjectionCountLoc;
};
DeferredLightProgram lighting;
diff --git a/gfx/gl/shaders/directionalLight.fs b/gfx/gl/shaders/directionalLight.fs
index d0c5062..c49bb8d 100644
--- a/gfx/gl/shaders/directionalLight.fs
+++ b/gfx/gl/shaders/directionalLight.fs
@@ -15,35 +15,32 @@ uniform vec3 lightDirection;
uniform vec3 lightColour;
uniform ivec3 lightPoint;
uniform mat4 lightViewProjection[MAX_MAPS];
-uniform vec4 shadowMapRegion[MAX_MAPS];
uniform uint lightViewProjectionCount;
-const vec3 e1 = vec3(-1, -1, -1), e2 = vec3(1, 1, 1);
+const vec3 e1 = vec3(0, 0, 0), e2 = vec3(1, 1, 1);
-float
+ float
insideShadowCube(vec3 v)
{
const vec3 s = step(e1, v) - step(e2, v);
return s.x * s.y * s.z;
}
-float
+ float
isShaded(vec4 Position)
{
for (uint m = 0u; m < lightViewProjectionCount; m++) {
- const vec3 PositionInLightSpace = (lightViewProjection[m] * Position).xyz;
+ const vec3 PositionInLightSpace = (lightViewProjection[m] * Position).xyz * .5 + .5;
const float inside = insideShadowCube(PositionInLightSpace);
if (inside > 0) {
- const float lightSpaceDepth = texture(
- shadowMap, vec3(PositionInLightSpace.xy * shadowMapRegion[m].xy + shadowMapRegion[m].zw, m))
- .r;
- return step(lightSpaceDepth, PositionInLightSpace.z * .5 + .5);
+ const float lightSpaceDepth = texture(shadowMap, vec3(PositionInLightSpace.xy, m)).r;
+ return step(lightSpaceDepth, PositionInLightSpace.z);
}
}
return 0;
}
-void
+ void
main()
{
const vec4 Position = vec4(texture(gPosition, TexCoords).xyz - lightPoint, 1);
diff --git a/gfx/gl/shadowMapper.cpp b/gfx/gl/shadowMapper.cpp
index f3d5dea..4dbee8d 100644
--- a/gfx/gl/shadowMapper.cpp
+++ b/gfx/gl/shadowMapper.cpp
@@ -40,48 +40,6 @@ ShadowMapper::ShadowMapper(const TextureAbsCoord & s) :
glBindFramebuffer(GL_FRAMEBUFFER, 0);
}
-constexpr std::array<std::array<TextureAbsRegion, ShadowMapper::SHADOW_BANDS>, ShadowMapper::SHADOW_BANDS> viewports {{
- {{
- {31, 31, 0, 0}, // full
- }},
- {{
- {31, 31, 0, 1}, // lower half
- {31, 1, 0, 1}, // upper half
- }},
- {{
- {31, 31, 0, 1}, // lower half
- {31, 1, 1, 1}, // upper left
- {1, 1, 1, 1}, // upper right
- }},
- {{
- {31, 31, 1, 1}, // lower left
- {1, 31, 1, 1}, // lower right
- {31, 1, 1, 1}, // upper left
- {1, 1, 1, 1}, // upper right
- }},
-}};
-constexpr std::array<std::array<TextureRelRegion, ShadowMapper::SHADOW_BANDS>, ShadowMapper::SHADOW_BANDS>
- shadowMapRegions {{
- {{
- {0.5F, 0.5F, 0.5F, 0.5F}, // full
- }},
- {{
- {0.5F, 0.25F, 0.5F, 0.25F}, // lower half
- {0.5F, 0.25F, 0.5F, 0.75F}, // upper half
- }},
- {{
- {0.5F, 0.25F, 0.5F, 0.25F}, // lower half
- {0.25F, 0.25F, 0.25F, 0.75F}, // upper left
- {0.25F, 0.25F, 0.75F, 0.75F}, // upper right
- }},
-
- {{
- {0.25F, 0.25F, 0.25F, 0.25F}, // lower left
- {0.25F, 0.25F, 0.75F, 0.25F}, // lower right
- {0.25F, 0.25F, 0.25F, 0.75F}, // upper left
- {0.25F, 0.25F, 0.75F, 0.75F}, // upper right
- }},
- }};
constexpr std::array<GlobalDistance, ShadowMapper::SHADOW_BANDS + 1> shadowBands {
1000,
250000,
@@ -89,24 +47,6 @@ constexpr std::array<GlobalDistance, ShadowMapper::SHADOW_BANDS + 1> shadowBands
2500000,
10000000,
};
-static_assert(viewports.size() == shadowMapRegions.size());
-static_assert(shadowBands.size() == shadowMapRegions.size() + 1);
-
-struct DefinitionsInserter {
- auto
- operator++()
- {
- return out.maps++;
- };
-
- auto
- operator*()
- {
- return std::tie(out.projections[out.maps], out.regions[out.maps]);
- }
-
- ShadowMapper::Definitions & out;
-};
std::vector<std::array<RelativePosition3D, 4>>
ShadowMapper::getBandViewExtents(const Camera & camera, const glm::mat4 & lightViewDir)
@@ -139,7 +79,7 @@ ShadowMapper::update(const SceneProvider & scene, const Direction3D & dir, const
const auto bandViewExtents = getBandViewExtents(camera, lightViewDir);
Definitions out;
std::transform(bandViewExtents.begin(), std::prev(bandViewExtents.end()), std::next(bandViewExtents.begin()),
- DefinitionsInserter {out},
+ std::back_inserter(out),
[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);
@@ -150,13 +90,10 @@ ShadowMapper::update(const SceneProvider & scene, const Direction3D & dir, const
return glm::ortho(x.first, x.second, y.first, y.second, -z.second, -z.first);
}(extents_minmax(CompareBy {0}), extents_minmax(CompareBy {1}), extents_minmax(CompareBy {2}));
- const auto lightViewDirProjection = lightProjection * lightViewDir;
-
- return std::make_pair(lightViewDirProjection, shadowMapRegions[0][0]);
+ return lightProjection * lightViewDir;
});
- std::span vps {out.projections.data(), out.maps};
for (const auto p : std::initializer_list<const ShadowProgram *> {&fixedPoint, &dynamicPoint, &dynamicPointInst}) {
- p->setView(vps, lightViewPoint);
+ p->setView(out, lightViewPoint);
}
scene.shadows(*this);
diff --git a/gfx/gl/shadowMapper.h b/gfx/gl/shadowMapper.h
index b948f50..a95d4c1 100644
--- a/gfx/gl/shadowMapper.h
+++ b/gfx/gl/shadowMapper.h
@@ -17,11 +17,7 @@ public:
static constexpr std::size_t SHADOW_BANDS {4};
- struct Definitions {
- std::array<glm::mat4x4, SHADOW_BANDS> projections {};
- std::array<TextureRelRegion, SHADOW_BANDS> regions {};
- size_t maps {};
- };
+ using Definitions = std::vector<glm::mat4x4>;
[[nodiscard]] Definitions update(const SceneProvider &, const Direction3D & direction, const Camera &) const;