View-based thickness of Bounds

I want to get the thickness of a cube using it’s bounds, but the thickness of it from the POV of a camera (so if the cube is looked at on an angle, the thickness would be greater from corner to corner opposed to from side to side).

The first picture illustrates what I mean, and the second illustrates what result I want in the end.


This picture is one of my attempts, starting out with just getting the distance to the Minimum, but it’s flawed because it’s “fixed” on this corner in particular, so when I rotate, the corner fades away as it orbits closer to the camera. Which makes sense, the distance gets shorter, but I am stuck at figuring out how to get what’s always the furthest away from the cam

Here is a portion of a code I found (ro= ray origin, rd = ray direction, sz =size) which I got to work in ShaderToy, but I can’t seem to translate it correctly into nodes. Any tips?

void cube(vec3 ro, vec3 rd, vec3 sz, out float tN, out float tF) {
    vec3 m = 1./rd,
         k = abs(m)*sz,
         a = -m*ro-k*.5,
         b = a+k;
    tN = max(max(a.x,a.y),a.z);
    tF = min(min(b.x,b.y),b.z);

cube (ro, rd, sz, tN, tF);
return  vec4 (tF - tN);