get the line of sight vector with nodes
Use a camera data/view vector node.  Because this provides a camera space vector, you can use a vector transform node to transform it into a world space vector like you want.

The &quot;camera&quot; being referred to here is not the camera I have in the scene-- notice the axes and camera position, notice that the same sphere is different colors in different viewports.  The camera being referred to is whatever eye is looking at the scene.  In the case of a render, that's the camera, but in the case of a viewport, it's whatever your viewport is using as a &quot;virtual&quot; camera.
Another way to do this, in Eevee, is to use geometry/incoming, then reverse the vector.  In Eevee, the incoming is vector is always the view vector (but reversed, to point at the camera.)  In Cycles, this vector doesn't always refer to the view vector, but instead refers to the most recent direction any particular ray that hit the object took.