So originally, I recommended doing this with geometry nodes, and you've had some trouble with that. In preparing you a better answer, I've had nothing but trouble with trying to get geometry nodes to give me the proper materials, and GN instanced materials is one of those things that is still changing with every release (and is currently pretty wicked bugged.) At the same time, I realized that I was overthinking the alternatives, and they're not really hard to implement. So instead of doing it with GN, let's do it with regular old modifiers.
You've indicated in comments that your end goal for this is outlining, so let's work with an outlining example.
Select your object and make sure that scale is applied. What I am demonstrating will not work with unapplied scale, even with inherited scale. You can do some tricks to make it work with uniform unapplied scale, but it will never ever work with non-uniform scale.
Make a new VG for it, call that new VG "prox". Assign all vertices to "prox" at weight 1.0.
Give your object a vertex weight proximity modifier. Set the target object to your camera. Set the vertex group to "prox". Set the proximity mode to geometry/vertex. Set the lowest weight to 0m and the highest weight equal to the far clip of your camera (default, 100m.)
Give your object a solidify modifier. Set the offset to 1.0, disable rim fill, enabled flipped normals, and give it an appropriate material offset so that the solidified mesh acquires your outline material (talked about in a little more depth below.) Set the vertex group to "prox" and then, from your camera's perspective, set the thickness to eye.
Now you need an outline material. For mine, rendering in Eevee, I just made a black emission material with backface culling enabled. Because my object had only a single material before creating the outline material, I set the solidify Material Offset to 1. If you're ever having trouble with an outline material, remember that the direction of your normals is the most important thing, and that different directions of normals can be made to work, just in different ways.
Pic demonstrating all that:
Now let's zoom out the camera:
Outlines are the same width.
Here's a file so you can play with the camera and see it working:
Notes:
When doing it this way, geometry that spans the far clip distance won't really work properly. This will probably be unnoticeable in practice, but it's possible to create theoretical situations that aren't right. (Really, any geometry that spans the far clip won't look right, so the fact that the outline also won't be right doesn't much matter.)
SS thickness is not just a function of distance to camera, but of FoV as well. You can create a driver to change the thickness linearly as FoV increases, but it's kind of a pain because you have to figure FoV from sensor size and focal length. I'm assuming you won't be changing FoV in any animations.
The way that these kinds of outlines work, the thickness of the line is not a single value-- the thickness, in pixels, depends not just on your solidify modifier's thickness, but on the angle of the face relative to your camera as well. What we're doing is establishing a constant maximum outline thickness. In practice, your outlines will vary from this zero to this maximum. Again, this does not depend on distance, but on relative angle.
I mentioned that this will potentially work with unapplied uniform scale. Solidify thickness is in object space not world space, so if you want it to work with unapplied scale, create a driver for your solidify thickness that divides the thickness by your object's scale (x,y, or z, because if it's uniform scale, they're all the same.)