How to reverse this projection?

610 Views Asked by At

I have a simple pinhole-style perspective projection:

$v = \begin{bmatrix} w_x - W(u_x / 2) \\ w_y - W(u_y / 2) \\ W(u_y / tan(\theta / 2)) \\ \end{bmatrix}$

$output \ ray = \hat{v}$

where $u$ is a two-dimensional vector of screen sizes, $\theta$ is the vertical field-of-view, $w$ is an input pixel coordinate, and $W$ represents pixel width (needed for anti-aliasing).

I'm interested in reversing this projection, so finding $w$ given an output ray. At the moment I use this method:

$w = (\hat{v} \ / \ (\hat{v}_z \ / \ (u_y \ / \ tan(\theta \ / \ 2))))_{xy} + u \ / \ 2$

But (as far as I can see) it only maps to points outside the range described by $u$ (so ((0, screen-width), (0, screen-height))). What am I missing?