# Fire range arc behind buildings

need some help with HLSL. Each charater in my game shows a fire range arc (which is a textured model) which show how far the guy can shoot, see

It looks ok, but I hate the fact that it shows even behing buildings. Now I already have a shader for rendering the Arc (where I only manipulate the u coordinate to achive oscilating effect) and I'm pretty sure that I can use the Shadow map approach for that - generate Shadow map as seen by the camera (my deferred renderer takes care of that), then when rendering the arc, compare current Depth to the one stored in shadow map and voila..

But I just can't get it to work. I know the theory, but I'm no expert in HLSL and shadow mapping...

Here is the code I have

...
float4x4 World;
float4x4 View;
float4x4 Projection;

float4x4 ObserverWVP; // of the character casting the arc

texture DepthMap; // as seen by the camera
...
{
float4 Position : POSITION0;
float2 TextureCoordinates : TEXCOORD0;
};

{
float4 Position : POSITION0;
float2 TextureCoordinates : TEXCOORD0;
float4 Observer : TEXCOORD1;
};

{

float4 worldPosition = mul(input.Position, World);
float4 viewPosition = mul(worldPosition, View);
output.Position = mul(viewPosition, Projection);

output.Observer = mul(input.Position, ObserverWVP);

output.TextureCoordinates = input.TextureCoordinates;

return output;
}

{
...

float2 temp = (input.Observer.xy / input.Observer.w) * 0.5 + 1; // half pixel
float depth2 = tex2D(DepthSampler, temp);
float depth = input.Observer.z / input.Observer.w;

if (depth < depth2)
{
}

return c;
}


And the ObserverWVP calculated in XNA

Matrix ObserverWVP = boneTransforms[mesh.ParentBone.Index] * worldMatrix // world
* Matrix.CreateLookAt(pos, pos + direction, Vector3.Up) // view
* Camera.Instance.ProjectionMatrix; // projection


Note that the direction vector is not normalized - it signifies the entire vector from the source (the character) to the outter edge of the arc.

I'm guessing the pixel shader is wrong. But I have no idea how to modify it. Any suggestions?