Hi, I have understood how shadow mapping works so I have decided to go further and try with “soft-shadows” in this case implementing Variance Shadow Mapping ( VSM ).
Basically, I have added a color attachement to the light frame buffer which I use to store the depth information, and applied a blur filter before send it to the lighting shader.
I have to say, that due to now I use a color attachement to store the depth information, before writing any depth information I clear it using a white color ( since the white color represent the farthest depth ).
My light frame buffer have a texture whose size is 1024 x 1024, its color attachement uses a GL_LINEAR filter and a GL_RGB16F for internal format.
Finally I have to say that I am using a cascaded shadow mapping to test it, the problem is that how I show in the next pictures, the shadow mapping technique works well with PFC ( not VSM ), but when I applied the VSM technique the shadow shrink and the result is very ugly. ( I think that is not a problem of the size of the cascade since the PFC works well. )
Shadow with PFC:
Shadow with VSM:
This is my fragment shader for the light rendering:
void main( )
{
float depth = gl_FragCoord.z;
float moment1 = depth;
float moment2 = depth * depth;
out_color = vec4( moment1, moment2, 0.0, 1.0 );
}
And this is my VSM code to calculate the shadow in the lighting shader:
float DirChebyshevVSM( int i, vec4 shadowCoords )
{
float dist = shadowCoords.z;
vec2 moments = texture2D( directional.cascades[i], shadowCoords.xy ).rg;
// Surface is fully lit. as the current fragment is before the light occluder
if ( dist <= moments.x )
{
return 1.0;
}
// The fragment is either in shadow or penumbra. We now use chebyshev's upperBound to check
// How likely this pixel is to be lit (p_max)
float variance = moments.y - ( moments.x * moments.x );
variance = max( variance, 0.00001 );
float d = dist - moments.x;
float p_max = variance / ( variance + d * d );
return p_max;
}
I have played with the variance max with no results …
Does anybody know how can I improve my VSM shadows?
Thanks in adavance,