Accessing depth texture from fragment program

I’m trying to implement dual depth shadow mapping as described in .

I’m running into a problem on the second pass where you use a fragment program to compare the current pixel’s depth value to a previously rendered depth texture (so that you can KIL it if it is equal and get a second-depth map).

It seems that no matter what I do, I cannot get correct values out of my bound depth texture.

Here is some pseudo-code. I am using Mark Harris’ RenderTexture for the depth texture.

// Pass 1  --------------------------
applyLightMatrices( );
renderScene( );
depthBuff1->EndCapture( );

// At this point, so far so good. 
// I can render the scene using depthBuff1 as the
// shadowmap and get correct shadowing, albeit
// with the usual artifacts

// Pass 2 ----------------------------
applyLightMatrices( );
depthBuff1->BindDepth( );
enableDepthCompareFragmentProgram( );
renderScene( );
disableDepthCompareFragmentProgram( );
depthBuff2->EndCapture( );

And here is my (test version) fragment program. The real fragment program will do a comparison, but this one has been simplified to just copy the depth texture into the newly cleared depth buffer.

TEMP firstDepth;
TEMP tc;

// Get texcoords into [0,1] range
MUL tc, fragment.position, { 0.00125, 0.001721, 1.0, 1.0};
// Lookup shadow texture
TEX firstDepth, tc, texture[0], 2D;
// Copy result to new depth buffer (have also tried firstDepth.z, firstDepth.w, etc)
MOV result.depth.z, firstDepth.x;

Unfortunately this does not work. DepthBuff2 is always blank after running pass 2. Is this the correct way to look up a depth map from the fragment program? Is it possible to have a depth-based render-to-texture enabled and bind another one at the same time?

If it matters I’m on a 6800 ultra with 71.89 driver version.

Not sure what I’m doing wrong here so any help would be appreciated.