Hi!
I'm pretty new to this forum. I'm recently working on my editor with a directional light, the shadow tech I applied was vsm but it didn't work well under large filter radius, thus I started over and now I got no shadow upon my new vsm method.
Here is the code:
float ActualDistance = Input.depth;
float2 Moment=GetDataFromZmap2(projUV); //projUV is the texcoord transformed from the light's view matrix.
float M1sq=Moment.x*Moment.x; //spuared moment.x
float dis=(ActualDistance-Moment.x);
if(ActualDistance <= Moment.x)//-------------unshadowed
{
return 1;
}
float variance = Moment.y-M1sq;
variance=variance/(variance+dis*dis);
return variance; //this should be the shadow factor that values from 0 to 1.
Moment.x is the value of depth and Moment.y is the one of squared depth, they are all from a blurred/filtered 2-channel depthmap, rendered at the light's view/camera.
I tested the following code to testify the value of Moment.x(blurred depthmap) and ActualDistance(from the player camera's view but the value itself is the z-value from the light's camera/view), they are generated from the same method(vertex shader, current value transformed by matWorldViewProjection, then z divided by w).
Output.depth= Output.Position.z / Output.Position.w;
The only difference is: depthmap value is from the light's viewMat and ActualDistance is from the light's viewMat but via the player's view.
The following code gives a correct result(see the pic), which can prove that both Moment.x(as well as the unfiltered depthmap) and actualldistance are correct so far.
float ActualDistance = Input.depth;
float2 Moment=GetDataFromZmap2(projUV); //projUV is the texcoord transformed from the light's view matrix.
float M1sq=Moment.x*Moment.x; //spuared moment.x
float dis=(ActualDistance-Moment.x);
if(ActualDistance <= Moment.x)//-------------unshadowed
{
return 1;
}
return 0;
My question is, what is the problem with my vsm code? Please let me know when more detail is needed, thanks for the help.