Debian Codegraph @

tests/manual/rhi/shadowmap/main.frag

raw
1 #version 440
2
3 layout(location = 0) in vec4 vLCVertPos;
4
5 layout(location = 0) out vec4 fragColor;
6
7 layout(binding = 1) uniform sampler2DShadow shadowMap;
8
9 layout(std140, binding = 0) uniform buf {
10 mat4 mvp;
11 mat4 lightMvp;
12 mat4 shadowBias;
13 int useShadow;
14 } ubuf;
15
16 void main()
17 {
18 vec4 adjustedLcVertPos = vLCVertPos;
19 adjustedLcVertPos.z -= 0.0001; // bias to avoid acne
20
21 // no textureProj, that seems to end up not doing the perspective divide for z (?)
22 vec3 v = adjustedLcVertPos.xyz / adjustedLcVertPos.w;
23 float sc = texture(shadowMap, v); // sampler is comparison enabled so compares to z
24
25 float shadowFactor = 0.2;
26 if (sc > 0 || ubuf.useShadow == 0)
27 shadowFactor = 1.0;
28
29 fragColor = vec4(0.5, 0.3 + ubuf.useShadow * 0.2, 0.7, 1.0) * shadowFactor;
30 }