Given the up and focal vector of the perspective camera, the position of the camera and the vertical and horizontal opening angle of the FOV. How can I calculate a ray for given screen space coordinates (x, y) where x, y are between -1 and 1 (inclusive). I tried this:
1) Calculate the vectors sx, sy that span the image plane
sy = -norm(up)
sx = norm(cross(focal, sy))
2) Calculate the focal length f
f = 1 * sin(90 - vertical) / sin(vertical)
3) Create the ray
dir = (center + x * sx + y * sy + f * forward) - center
r(t) = center + t * norm(dir)
But the resulting image does not turn out like the reference image. Someone know what I am doing wrong?
sin
most likely accepts radians. Also you can cancel out the+center-center
:dir = x * sx + y * sy + f * forward
. I am unsure why you calculate the focal length like this either. $\endgroup$