Hello,
I've got this function in my shader that performs PCF-filtering on a cascaded shadow map, just like in the DirectX-SDK11-sample:
float CalculatePCFPercentLit(float4 vShadowTexCoord, float fBlurRowSize, int numCascade)
{
float fPercentLit = 0.0f;
// This loop could be unrolled, and texture immediate offsets could be used if the kernel size were fixed.
// This would be performance improvment.
float depthcompare = vShadowTexCoord.z;
// A very simple solution to the depth bias problems of PCF is to use an offset.
depthcompare -= vBlur.z; // z => bias
for( int x = int(vBlur.x); x < vBlur.y; ++x )
{
for( int y = int(vBlur.x); y < vBlur.y; ++y )
{
// Compare the transformed pixel depth to the depth read from the map.
float depth = Sample(Shadow,
float2(
vShadowTexCoord.x + (float(x) * vBorderPadding.w) , // w => native texel size
vShadowTexCoord.y + (float(y) * vBorderPadding.x) // x => texelsize
));
fPercentLit += (depthcompare <= depth ? 1.0f : 0.0f);
}
}
fPercentLit /= fBlurRowSize;
return fPercentLit;
}
Now in DirectX11 this works just fine, but in DirectX9, it fails with this warning/errors:
C:\Acclimate Engine\Techdemo\Game\Modules\Shadow\Effects\memory(59,19): warning X3553: can't use gradient instructions in loops with break, forcing loop to unroll
C:\Acclimate Engine\Techdemo\Game\Modules\Shadow\Effects\memory(53,5): error X3511: unable to unroll loop, loop does not appear to terminate in a timely manner (1024 iterations)
C:\Acclimate Engine\Techdemo\Game\Modules\Shadow\Effects\memory(51,5): error X3511: forced to unroll loop, but unrolling failed.
What does that mean? I'm not using any break in this loop as suggested by the warning, why does the loop try to unroll then? Is it even possible to have a loop like this based on c-register-input (thats where vBlur comes from) in HLSL for DirectX9? Target level is 3.0, and the "Sample"-function translates to tex2d when this effect is parsed to HLSL3. Any ideas?