I have a camera projected vertex of four components:
screen_space_vertex4 = local_vertex4 * world_view_projection_matrix
// Homogeneous coordinates to Cartesian coordinates.
screen_space_vertex4.x /= screen_space_vertex4.w
screen_space_vertex4.y /= screen_space_vertex4.w
screen_space_vertex4.z /= screen_space_vertex4.w
This puts screen_space_vertex4.z in the -1;1 range.
I try to get the world space distance between my camera and my vertex, but a simple mapping of near and far to -1;1 doesn't work.
What are the math for this?
I know there are near, far, fov and ratio involved, but I can't find the proper equation.