forked from LukasBanana/LLGL
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Scene.450core.frag
39 lines (30 loc) · 1011 Bytes
/
Scene.450core.frag
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
28
29
30
31
32
33
34
35
36
37
38
39
// GLSL scene fragment shader
#version 450 core
layout(std140, binding = 1) uniform Settings
{
mat4 wMatrix;
mat4 vpMatrix;
mat4 vpShadowMatrix;
vec4 lightDir;
vec4 diffuse;
};
layout(binding = 2) uniform texture2D shadowMap;
layout(binding = 3) uniform samplerShadow shadowMapSampler;
layout(location = 0) in vec4 vWorldPos;
layout(location = 1) in vec4 vNormal;
layout(location = 0) out vec4 fragColor;
void main()
{
// Project world position into shadow-map space
vec4 shadowPos = vpShadowMatrix * vWorldPos;
shadowPos /= shadowPos.w;
shadowPos.xy = shadowPos.xy * vec2(0.5, -0.5) + 0.5;
// Sample shadow map
float shadow = texture(sampler2DShadow(shadowMap, shadowMapSampler), shadowPos.xyz);
// Compute lighting
vec3 normal = normalize(vNormal.xyz);
float NdotL = max(0.2, dot(normal, -lightDir.xyz));
// Set final output color
shadow = mix(0.2, 1.0, shadow);
fragColor = vec4(diffuse.rgb * (NdotL * shadow), 1.0);
}