samplecmp usage?

What exactly do the samplecmp HLSL instruction?

From what I understand from the documentation:
v = MyTexture.samplecmp( MySampler, Position, CmpRef );
seems to perform something like this:
CmpVal = MyTexture.load(Position);
if (CmpVal CmpOp CmpRef)
then v = MyTexture.sample( MySampler, Position );
else v = ?
where CmpVal is the operator specified in the ComparisonFunc
field when creating the MySampler state.

My questions are:

  1. Is it right?
  2. What this functions does in the else case ?
  3. What is this function intended for? (A practical exemple?)

Thanks for your help.

[673 byte] By [PascalMignot] at [2008-2-18]
# 1

SampleCmp operates similarly to Sample, except that the red channel values of each texel it samples is compared with the CmpRef value and results in either black or white. The operation performed at each texel is:

srcReferenceValue {ComparisonFunction} texel.R

When a comparison passes the result is 1.0f, and when it fails the result is 0.0f. These texel values are blended together just as the original texel colors would be for Sample, so you'll end up with a grayscale value influenced by the sample location and the results of the comparison function for each texel. The most obvious use for this function is in shadow-mapping, letting the hardware do a PCF for you instead of using Load repeatedly and using up valuable shader instructions.

AndyCampbell at 2007-9-4 > top of Msdn Tech,Game Technologies: DirectX, XNA, XACT, etc.,Direct3D 10...
# 2

The z-comparison usage is confirmed by the fact that the only DXGI_FORMAT_* supporting the SampleCmp* functions in the reference device are R32_FLOAT, R32_FLOAT_X8X24_TYPELESS, R24_UNORM_X8_TYPELESS, R16_UNORM. These formats clearly indicate that the data come from a DepthStencil buffer.

PascalMignot at 2007-9-4 > top of Msdn Tech,Game Technologies: DirectX, XNA, XACT, etc.,Direct3D 10...