How to correctly sample a shadow map from a render texture? (515907)

I’m trying to implement a custom shader to determine shadows on a terrain based on the sun position.

I have the pov of the sun light rendering depth to a render texture, and this, along with the matrix is an input to my custom terrain shader.

Here’s a screenshot showing the render texture and the depth of the pixels in view from the light:

So it looks like so far, so good. The part I am struggling with is projecting my rendertexture (which is a shadow depth map) onto the terrain surface from the camera pov.

It seems no matter what I try, the depth values for the projection always come out as 0 (i.e. they look fully black when I visualise them on the surface).

I am currently trying:

   float4 shadow_depth4 = tex2Dproj(_RenderPaintTexture, i.sh);
   float shadow_depth = DecodeFloatRG(shadow_depth4.zw);

Where i.sh is output from the vertex shader as:

 o.sh = mul(_Object2World, v.vertex);
 o.sh = mul(_ShadowDepthMatrix, o.sh);

…but that doesn’t appear to work. If I output shadow_depth from the frag shader, I get this:

Obviously any shadow depth test is going to return all pixels as in shadow using this.

Any ideas where I am going wrong? Thanks in advance.

Figured it out, I needed to access the render texture as follows:

    float4 shadow_depth4 = tex2Dproj(_RenderPaintTexture, i.sh.xyw);
    float shadow_depth = DecodeFloatRG(shadow_depth4.zw);