displayShadow.glsl
1.4 KB
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
// Only display shadow
@export ecgl.displayShadow.vertex
@import ecgl.common.transformUniforms
@import ecgl.common.uv.header
@import ecgl.common.attributes
varying vec3 v_WorldPosition;
varying vec3 v_Normal;
void main()
{
@import ecgl.common.uv.main
v_Normal = normalize((worldInverseTranspose * vec4(normal, 0.0)).xyz);
v_WorldPosition = (world * vec4(position, 1.0)).xyz;
gl_Position = worldViewProjection * vec4(position, 1.0);
}
@end
@export ecgl.displayShadow.fragment
@import ecgl.common.uv.fragmentHeader
varying vec3 v_Normal;
varying vec3 v_WorldPosition;
// For reflection.
uniform float roughness: 0.2;
#ifdef DIRECTIONAL_LIGHT_COUNT
@import clay.header.directional_light
#endif
@import ecgl.common.ssaoMap.header
@import clay.plugin.compute_shadow_map
void main()
{
float shadow = 1.0;
@import ecgl.common.ssaoMap.main
#if defined(DIRECTIONAL_LIGHT_COUNT) && defined(DIRECTIONAL_LIGHT_SHADOWMAP_COUNT)
float shadowContribsDir[DIRECTIONAL_LIGHT_COUNT];
if(shadowEnabled)
{
computeShadowOfDirectionalLights(v_WorldPosition, shadowContribsDir);
}
for (int i = 0; i < DIRECTIONAL_LIGHT_COUNT; i++) {
shadow = min(shadow, shadowContribsDir[i] * 0.5 + 0.5);
}
#endif
shadow *= 0.5 + ao * 0.5;
shadow = clamp(shadow, 0.0, 1.0);
gl_FragColor = vec4(vec3(0.0), 1.0 - shadow);
}
@end