Camera position in Viewport coordinates

According to the documentation the range of viewport coordinates are:

“Viewport space is normalized and relative to the camera. The bottom-left of the camera is (0,0); the top-right is (1,1). The z position is in world units from the camera.”

However, when I perform the following operation, the result is always Vector3.zero (0,0,0).

Camera.current.WorldToViewportPoint(Camera.current.transform.position);

While this would make sense to me if the viewport range were [-1,+1], I don’t see how this works with a range of [0,+1].
The (0,0,0) vector indicates that the camera is at the bottom left of the viewport. Why isn’t the camera’s viewspace coordinate (0.5f,0.5f,0.0f), right in the MIDDLE of it’s viewport?

I suspect I’m missing some critical piece of information about viewport space, but my online research has not helped me find it.

Additional info: I discovered this because I was trying to determine which of two viewspace coordinates (with the same z coord) are closer to the CENTER of the viewspace output. Should I compare their distances to (0,0,z) or (0.5,0.5,z)?

Looks like a very small glitch in Unity’s worldToViewPoint. It doesn’t work when you give it the exact world position of the camera. Moving it a tiny amount fixes it:

Transform T=Camera.current.transform;
Vector3 pp=T.position; // exact camera pos. gives incorrect 00
// pp += T.forward*0.01f; // <- fixes it
// pp -= T.forward*0.01; // <- also fixes it
Debug.Log( Camera.current.WorldToViewportPoint(pp) );

With pp as the exact camera coords, you get 000. But moving it a tiny bit forward or backward is fine.

I’m wondering if technically the exact camera pos doesn’t have a viewport point – but I think you’re right. It’s (0.5, 0.5, 0) by definition.

Sir Owen, you got my thinking back on the right track, here is what’s going on.

Consider the usual viewing frustum. As show in this world-space image, we have a NEAR PLANE. This near plane distance is in-fact the Z coordinate of the “Screen” in veiwport space. The plane, at this z coordinate, has a rectangular shape, with some non-zero distance between the clipping planes.
74149-cam-w-near.png

In this world-space image, we can see what it looks like if we ignore the near-plane: All our clipping planes(top,bottom,left,right) meet at a single point, the camera’s position, a.k.a our viewport space z=0. The effectively renders any x,y coordinate at z=0, in view-space, meaningless: Since there is zero “distance” between the left and right clipping planes at z=0, an x value that represents a fraction of how far between them, is also, always zero.

74150-cam-nonear.png