HDRP outline shader

I have a need to create an outline in HDRP, just for a sphere, where only the outline is able to display above all other objects. Ideally, I’d want this outline to be a material that I apply to the sphere, with a pass for regular hdrp lit shader, and then a pass for the outline (or two materials I suppose). That way I don’t have to add any extra render layers, or extra game objects, and it feels like the cleanest solution to me.

I had concluded that because I’m just working with a sphere, this should be easy enough to resolve, by looking at the world space position of the sphere, projecting that into screen space, and then comparing the distance of the pixels in the shader from the sphere position, to a threshold.

I have managed to do just that, with the following code:

float _BallRadius;        
float4 worldToClip(float4 worldVec){
    return mul(UNITY_MATRIX_VP, worldVec);
}

float2 clipToScreen(float4 clipPos){
    float4 ndcPos = float4(clipPos.x/clipPos.w, -clipPos.y/clipPos.w, clipPos.z, clipPos.w);
    return (ndcPos.xy * 0.5 + 0.5) * _ScreenParams.xy;    
}

float2 worldToScreen(float4 worldVec){
    float4 clipPos = worldToClip(worldVec);
    return clipToScreen(clipPos);
}

fixed4 frag(float4 sp: VPOS) : SV_Target
{
    float4 ballWorldPos = mul(unity_ObjectToWorld, float4(0, 0, 0, 1));

    float4 ballClipPos = worldToClip(ballWorldPos);

    float2 ballScreenPos = clipToScreen(ballClipPos);

    float4 worldRadius = mul(unity_CameraToWorld, float4(_BallRadius,0,0,1)) + ballWorldPos;

    float2 screenRadius = worldToScreen(worldRadius);

    float radiusLength = distance(ballScreenPos, screenRadius);

    float centreDist = distance(sp.xy, ballScreenPos.xy);

    if(centreDist < (radiusLength)){
        return fixed4(0,0,0,0);
    }
    return fixed4(1,0,0,1);
}

However the results are not quite as desired:

At the edges of the screen, the sphere distorts due to perspective, and so, it figures that because I’m only calculating the screen position of the sphere, and comparing it to a pixel position, the shader is just giving me a perfect circle, at the screen space location of the sphere’s centre.
So, is there a way that I can distort the pixel position to account for the perspective distortion of the sphere, and give me the outline that I’m looking for? (like in the first image?)

If not, what other ways could I go about achieveing this effect?