I've been adding shadows to a shader for a Windows Store app, and I've been using this very good tutorial to get me started:

http://takinginitiative.net/2011/05/25/directx10-tutorial-10-shadow-mapping-part-2/

In the final code for the shader, he adds PCF sampling, but when I add the code to my shader, I get:

FXC : error X4539: sampler mismatch: sampler used inconsistently

If I try to manually unroll the y loop into four blocks, I get the same error. If I completely get rid of the y loop, it compiles. Has anyone gotten this kind of thing to work before? Here's the code to my pixel shader which won't compile:

float2 texOffset(int u, int v)

{

return float2(u * 1.0f/shadowMapSize.x, v * 1.0f/shadowMapSize.y);

}

float4 main(PixelShaderFlatInput input) : SV_Target

{

// Compute amount of shadow

const float shadowMapBias = 0.0f;

input.lightPosition.xyz /= input.lightPosition.w;

input.lightPosition.x = input.lightPosition.x/2 + 0.5;

input.lightPosition.y = input.lightPosition.y/-2 + 0.5;

// PCF sampling for shadow map

float sum = 0;

int x, y;

// perform PCF filtering on a 4 x 4 texel neighborhood

for (y = -1.5; y <= 1.5; y += 1.0)

{

for (x = -1.5; x <= 1.5; x += 1.0)

{

sum += shadowTexture.SampleCmpLevelZero(shadowSampler, input.lightPosition.xy + texOffset(x,y), input.lightPosition.z);

}

}

float shadowFactor = sum / 16;

float4 factor = input.diffuseColor * shadowFactor;

return diffuseTexture.Sample(linearSampler, input.textureUV) * factor;

}