I found a way to get the compiler to do the right thing while using functions. It's not ideal, but better than inlining everything manually.
What I did was use static global variables instead of inout parameters. You may want to do some more experimentation to find out exactly which things need to be global variables instead of parameters.
Here's a modified ...
Instead of increasing your sample depth by stepSize every time, why not divide depth by floor(depth/stepSize) and incrementing by that? That will give you n evenly-spaced sample points between camera and the surface.
Then the step length will vary slightly to give the same number of samples on proximate points.
It would still give you a transition as the ...
Okay after a lot of fiddling.
I needed to divide xyz with w:
Here is my Vertex Shader for a fullscreen quad;
VertexShaderOutput VS(VertexShaderInput input)
output.Position = float4(input.Position.xy,0.0, 1.0);
float4 worldPos = output.Position;
worldPos = mul(worldPos, InverseViewProjection);
worldPos.xyz /= ...