summaryrefslogtreecommitdiff
path: root/gfx/gl/shaders/directionalLight.fs
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/shaders/directionalLight.fs
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/shaders/directionalLight.fs')
-rw-r--r--gfx/gl/shaders/directionalLight.fs7
1 files changed, 4 insertions, 3 deletions
diff --git a/gfx/gl/shaders/directionalLight.fs b/gfx/gl/shaders/directionalLight.fs
index 3756db7..f36d83f 100644
--- a/gfx/gl/shaders/directionalLight.fs
+++ b/gfx/gl/shaders/directionalLight.fs
@@ -13,6 +13,7 @@ layout(binding = 2) uniform sampler2D shadowMap;
uniform vec3 lightDirection;
uniform vec3 lightColour;
+uniform ivec3 lightPoint;
uniform mat4 lightViewProjection[MAX_MAPS];
uniform vec4 shadowMapRegion[MAX_MAPS];
uniform uint lightViewProjectionCount;
@@ -27,10 +28,10 @@ insideShadowCube(vec3 v)
}
float
-isShaded(ivec3 Position)
+isShaded(vec4 Position)
{
for (uint m = 0u; m < lightViewProjectionCount; m++) {
- vec3 PositionInLightSpace = (lightViewProjection[m] * vec4(Position, 1.0f)).xyz;
+ const vec3 PositionInLightSpace = (lightViewProjection[m] * Position).xyz;
const float inside = insideShadowCube(PositionInLightSpace);
if (inside > 0) {
const float lightSpaceDepth
@@ -44,7 +45,7 @@ isShaded(ivec3 Position)
void
main()
{
- const ivec3 Position = texture(gPosition, TexCoords).xyz;
+ const vec4 Position = vec4(texture(gPosition, TexCoords).xyz - lightPoint, 1);
const vec3 Normal = texture(gNormal, TexCoords).rgb;
const float shaded = isShaded(Position);
FragColor = (1 - shaded) * max(dot(-lightDirection, Normal) * lightColour, 0);