This operator transforms a position into normal device coordinates. This space is well defined only for the Displacement, Surface and Light contexts.
toNDC() assumes that the position is already in camera space and just needs to be converted to NDC coordinates. To get NDC coordinates for the viewing camera, the input position should be in current space.
For light shaders, toNDC() behaves a little differently as it will transform into the NDC space for the light (not the viewing camera). In this case, you need to first transform into the space of the light - for example, using wo_space(P) and then pass this to the toNDC function.
Position In Camera Space
This is the position of a point in camera/light space which is to be transformed into the NDC space.