I use a variance shadow mapping with a "standard" light bleeding fix in my graphics engine which is based on deferred rendering.. I have a single shadow map for a directional light beacause a test scene is relatively small. Saving depth looks like this:
Then I perform a separable gaussian blur on that texture.
iffloat Chebyshev(shadowCoordvec2 moments, float mean, float minVariance)
{
float shadow = 1.z0f;
if(mean <= moments.x)
{
shadow = 1.0;0f;
return shadow;
}
else
{
float variance = moments.y - (moments.x * moments.x);
variance = max(variance, 0.000001minVariance);
float d = shadowCoord.zmean - moments.x;
shadow = variance / (variance + (d * d));
float amount = 0.3;3f;
shadow = clamp((shadow - amount) / (1.00f - amount), 0.00f, 1.00f); // standard light bleeding fix
return shadow;
}
}
vec4 shadowCoord = shadowMatrix * vec4(viewSpacePosition, 1.0f);
vec2 moments = texture(ShadowMap, shadowCoord.xy).xy;
float minVariance = 0.000001f;
float shadow = Chebyshev(moments, shadowCoord.z, minVariance);
How to implement a shadow test for that technique ? Can I additionaly use a "standard"Here is my attempt:
float positiveExponent = 40.0f;
float negativeExponent = 5.0f;
vec2 warpDepth(float depth)
{
vec2 exponents = vec2(positiveExponent, negativeExponent);
depth = 2.0f * depth - 1.0f;
float pos = exp(exponents.x * depth);
float neg = -exp(-exponents.y * depth);
vec2 wDepth = vec2(pos, neg);
return wDepth;
}
float Chebyshev(vec2 moments, float mean, float minVariance)
{
float shadow = 1.0f;
if(mean <= moments.x)
{
shadow = 1.0f;
return shadow;
}
else
{
float variance = moments.y - (moments.x * moments.x);
variance = max(variance, minVariance);
float d = mean - moments.x;
shadow = variance / (variance + (d * d));
return shadow;
}
}
vec4 shadowCoord = shadowMatrix * vec4(viewSpacePosition, 1.0f);
vec4 moments = texture(ShadowMap, shadowCoord.xy).xyzw;
vec2 posMoments = vec2(moments.x, moments.z);
vec2 negMoments = vec2(moments.y, moments.w);
vec2 wDepth = warpDepth(shadowCoord.z);
float minVariance = 0.000001f;
float posResult = Chebyshev(posMoments, wDepth.x, minVariance);
float negResult = Chebyshev(negMoments, wDepth.y, minVariance);
shadow = min(posResult, negResult);
Unfortunately it doesn't remove light bleeding fix with. Did I do something wrong ? Maybe I should calculate two different minVariance based on the new codepositive and negative exponents ?