float EPLISON = 0.00001;
float chebychevUpperBound(vec4 fragPosLightSpace)
{
vec3 projCoords = fragPosLightSpace.xyz / fragPosLightSpace.w; // 透视除法
projCoords = projCoords * 0.5 + 0.5;
float mean = texture(shadowMap, projCoords.xy).r;
//mean = (mean - 0.5) * 2;
if ((projCoords.z - mean <= EPLISON) || projCoords.z > 1.0)
{
return 1.0f;
}
float var = texture(shadowMap, projCoords.xy).g - mean * mean;
var = max(var, EPLISON);
float pmax = var / (var + (projCoords.z - mean) * (projCoords.z - mean));
return pmax;
}