summaryrefslogtreecommitdiff
path: root/gfx
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2024-01-30 22:13:56 +0000
committerDan Goodliffe <dan@randomdan.homeip.net>2024-01-30 22:13:56 +0000
commit72ec5dd096a3110e8085919f4c0e3320ef176657 (patch)
tree7eb3c254b681d2cafbc9ce8f13b285a9313474c4 /gfx
parentRemove the complications from previously storing several shadow maps in the t... (diff)
downloadilt-72ec5dd096a3110e8085919f4c0e3320ef176657.tar.bz2
ilt-72ec5dd096a3110e8085919f4c0e3320ef176657.tar.xz
ilt-72ec5dd096a3110e8085919f4c0e3320ef176657.zip
Adjust light view projection matrix upfront
Saves doing it per pixel, per region later
Diffstat (limited to 'gfx')
-rw-r--r--gfx/gl/sceneRenderer.cpp8
-rw-r--r--gfx/gl/shaders/directionalLight.fs8
2 files changed, 11 insertions, 5 deletions
diff --git a/gfx/gl/sceneRenderer.cpp b/gfx/gl/sceneRenderer.cpp
index 2dd1760..517d51e 100644
--- a/gfx/gl/sceneRenderer.cpp
+++ b/gfx/gl/sceneRenderer.cpp
@@ -137,14 +137,20 @@ SceneRenderer::DirectionalLightProgram::DirectionalLightProgram() :
{
}
+const auto toTextureSpaceMat = glm::translate(glm::identity<glm::mat4>(), glm::vec3 {0.5F})
+ * glm::scale(glm::identity<glm::mat4>(), glm::vec3 {0.5F});
+
void
SceneRenderer::DirectionalLightProgram::setDirectionalLight(
const RGB & c, const Direction3D & d, const GlobalPosition3D & p, const std::span<const glm::mat4x4> lvp) const
{
+ const auto toTextureSpace = [](const glm::mat4 & m) {
+ return toTextureSpaceMat * m;
+ };
glUniform(colourLoc, c);
const auto nd = glm::normalize(d);
glUniform(directionLoc, nd);
glUniform(lightPointLoc, p);
glUniform(lightViewProjectionCountLoc, static_cast<GLuint>(lvp.size()));
- glUniform(lightViewProjectionLoc, lvp);
+ glUniform(lightViewProjectionLoc, std::span<const glm::mat4> {lvp * toTextureSpace});
}
diff --git a/gfx/gl/shaders/directionalLight.fs b/gfx/gl/shaders/directionalLight.fs
index c49bb8d..24457b8 100644
--- a/gfx/gl/shaders/directionalLight.fs
+++ b/gfx/gl/shaders/directionalLight.fs
@@ -19,18 +19,18 @@ uniform uint lightViewProjectionCount;
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 * .5 + .5;
+ const vec3 PositionInLightSpace = (lightViewProjection[m] * Position).xyz;
const float inside = insideShadowCube(PositionInLightSpace);
if (inside > 0) {
const float lightSpaceDepth = texture(shadowMap, vec3(PositionInLightSpace.xy, m)).r;
@@ -40,7 +40,7 @@ isShaded(vec4 Position)
return 0;
}
- void
+void
main()
{
const vec4 Position = vec4(texture(gPosition, TexCoords).xyz - lightPoint, 1);