summaryrefslogtreecommitdiff
path: root/gfx/gl/shaders
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2024-01-29 01:56:42 +0000
committerDan Goodliffe <dan.goodliffe@octal.co.uk>2024-01-30 17:28:03 +0000
commita01f1d9e834719046fbdec02a5147d2e55722bac (patch)
tree58475e7704f486890246e4f3ae3b4e5031e668eb /gfx/gl/shaders
parentSet shadow program uniforms all in one function, merge setting of view projec... (diff)
downloadilt-a01f1d9e834719046fbdec02a5147d2e55722bac.tar.bz2
ilt-a01f1d9e834719046fbdec02a5147d2e55722bac.tar.xz
ilt-a01f1d9e834719046fbdec02a5147d2e55722bac.zip
Remove the complications from previously storing several shadow maps in the texture
Diffstat (limited to 'gfx/gl/shaders')
-rw-r--r--gfx/gl/shaders/directionalLight.fs17
1 files changed, 7 insertions, 10 deletions
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);