Perspective Raytracing 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?
Let the horizontal FOV be given as theta (in radians), and the vertical FOV be given as phi (in radians). The we know that:

$$\tan\frac{\theta}{2}=\frac{w}{f}, \tan\frac{\phi}{2}=\frac{h}{f}$$

Let us pick $f = 1$, then $w = \tan\frac{\theta}{2}, h = \tan\frac{\phi}{2}$. Now your ray generation direction generation formula looks like:

$$\pmb{d} = x w\pmb{u} + yh\pmb{v} + \pmb{w}$$

Where $\pmb{u},\pmb{v}, \pmb{w}$ are your sx,sy, forward vectors. Essentially, I found the extent of the smallest/largest x and y respectively ($1w = w, -1w=-w$, etc.). You can premultiply $\pmb{u}, \pmb{v}$ with $w, h$ respectively, if you don't want to perform the multiplication per ray.