summaryrefslogtreecommitdiff
path: root/gfx/gl/shaders
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2022-12-04 17:16:31 +0000
committerDan Goodliffe <dan@randomdan.homeip.net>2022-12-04 17:16:31 +0000
commit6433b56c3af8721f8301255818a8dd692e75492e (patch)
tree46471356f76e4dc66746fa4133c928609b5c0620 /gfx/gl/shaders
parentFixed point shadow shader doesn't need normal/texture data (diff)
downloadilt-6433b56c3af8721f8301255818a8dd692e75492e.tar.bz2
ilt-6433b56c3af8721f8301255818a8dd692e75492e.tar.xz
ilt-6433b56c3af8721f8301255818a8dd692e75492e.zip
Generate and use a shadow map
Generated when the directional light is specified in the environment call, passed to the directional light shader pass to conditionally illuminate each pixel.
Diffstat (limited to 'gfx/gl/shaders')
-rw-r--r--gfx/gl/shaders/directionalLight.fs9
1 files changed, 9 insertions, 0 deletions
diff --git a/gfx/gl/shaders/directionalLight.fs b/gfx/gl/shaders/directionalLight.fs
index 7562f96..5350bf3 100644
--- a/gfx/gl/shaders/directionalLight.fs
+++ b/gfx/gl/shaders/directionalLight.fs
@@ -5,14 +5,23 @@ out vec3 FragColor;
in vec2 TexCoords;
+layout(binding = 0) uniform sampler2D gPosition;
layout(binding = 1) uniform sampler2D gNormal;
+layout(binding = 2) uniform sampler2D shadowMap;
uniform vec3 lightDirection;
uniform vec3 lightColour;
+uniform mat4 lightViewProjection;
void
main()
{
+ const vec3 Position = texture(gPosition, TexCoords).xyz;
+ const vec4 PositionInLightSpace = (lightViewProjection * vec4(Position, 1)) * 0.5 + 0.5;
+ const float lightSpaceDepth = texture(shadowMap, PositionInLightSpace.xy).r;
+ if (lightSpaceDepth < PositionInLightSpace.z) {
+ discard;
+ }
const vec3 Normal = texture(gNormal, TexCoords).rgb;
FragColor = dot(-lightDirection, Normal) * lightColour;
}