Thanks!
I already tried using G16R16 format to implement VSM.
my code:
PixelInput VS_VSM(VertexInput IN)
{
PixelInput OUT;
OUT.Position = mul(IN.Position , WorldViewProjection);
OUT.Depth = PixelInput.Position.zw;
return OUT;
}
float4 PS_VSM(PixelInput IN) : COLOR
{
float d = IN.Depth.x / IN.Depth.y;
return float4(d , d * d , 0 , 1);
}
calculate shadow:
float GetShadowVSM(float3 shadowCoord)
{
float2 vsm = tex2D(shadowMap, shadowCoord.xy).rg;
float t = shadowCoord.z;
float Z = vsm.x;
float Z2 = vsm.y;
float cmpEq = ((Z - Z2) <= 0.0);
float p = (t <= Z);
float variance = max(Z2 - (Z*Z), 0.0005f);
float d = (t - Z);
float pMax = variance / (variance + d*d);
return max(cmpEq, max(max(p, pMax)));
}
currently it still has some problem :
1. rendering high object , the shadow at the bottom is very weak.
2. numerical precision.
3. blurring.
so how to solve these?
could you show me some details? Thank you advance!