summaryrefslogtreecommitdiff
path: root/gfx/gl/shaders/directionalLight.fs
blob: d1e60eeaf54cdc0ca9b2716cd3176ef2dd5943c0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#version 330 core
#extension GL_ARB_shading_language_420pack : enable

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 vec3 PositionInLightSpace = ((lightViewProjection * vec4(Position, 1.0f)) * 0.5 + 0.5).xyz;
	const float lightSpaceDepth = texture(shadowMap, PositionInLightSpace.xy).r;
	if (lightSpaceDepth < PositionInLightSpace.z) {
		discard;
	}
	const vec3 Normal = texture(gNormal, TexCoords).rgb;
	FragColor = max(dot(-lightDirection, Normal) * lightColour, 0);
}