float DoPCF(sampler2D sMap,float4 vShadowTexCoord,int iSqrtSamples,float fBias)
{
float fShadowTerm = 0.0f;
float fRadius = (iSqrtSamples - 1.0f) / 2;
for (float y = -fRadius; y <= fRadius; y++)
{
for (float x = -fRadius; x <= fRadius; x++)
{
float2 vOffset = float2(x,y)/pssm_res_var;
float fDepth = tex2Dlod(sMap, float4(vShadowTexCoord.xy + vOffset, 0.0f, 0.0f)).x;
float fSample = (vShadowTexCoord.z < fDepth + fBias);
float xWeight = 1, yWeight = 1;
if (x == -fRadius)
xWeight = 1 - frac(vShadowTexCoord.x * pssm_res_var);
else if (x == fRadius)
xWeight = frac(vShadowTexCoord.x * pssm_res_var);
if (y == -fRadius)
yWeight = 1 - frac(vShadowTexCoord.y * pssm_res_var);
else if (y == fRadius)
yWeight = frac(vShadowTexCoord.y * pssm_res_var);
fShadowTerm += fSample * xWeight * yWeight;
}
}
return fShadowTerm / (iSqrtSamples * iSqrtSamples);
}