2
uniform sampler2D shadowMap;
4
varying vec4 shadowCoord;
8
float chebyshevUpperBound( float distance) {
9
// We retrive the two moments previously stored (depth and depth*depth)
10
vec2 moments = texture2D(shadowMap,shadowCoordPostW.xy).rb;
11
// Surface is fully lit. as the current fragment is before the light occluder
12
if (distance <= moments.x)
15
float variance = moments.y - (moments.x*moments.x);
16
//variance = max(variance,0.00002);
17
variance = max(variance,0.000195);
18
float d = distance - moments.x;
19
float p_max = variance / (variance + d*d);
24
shadowCoordPostW = shadowCoord / shadowCoord.w;
25
shadowCoordPostW = shadowCoordPostW * 0.5 + 0.5;
26
float shadow = chebyshevUpperBound(shadowCoordPostW.z);
28
vec4 kd = gl_LightSource[0].diffuse;
32
gl_FragColor = vec4(vec3(0.0), 0.5 - shadow);
b'\\ No newline at end of file'