Function veloren_voxygen::scene::compute_scalar_fov
source · fn compute_scalar_fov<F: Float>(_near_plane: F, fov: F, aspect: F) -> F
Expand description
Approximate a scalar field of view angle using the parameterization from section 4.3 of Lloyd’s thesis:
W_e = 2 n_e tan θ
where
W_e = 2 is the width of the image plane (for our projections, since they go from -1 to 1) n_e = near_plane is the near plane for the view frustum θ = (fov / 2) is the half-angle of the FOV (the one passed to Mat4::projection_rh_zo).
Although the widths for the x and y image planes are the same, they are different in this framework due to the introduction of an aspect ratio:
y’(p) = 1.0 / tan(fov / 2) * p.y / -p.z x’(p) = 1.0 / (aspect * tan(fov / 2)) * p.x / -p.z
i.e.
y’(x, y, -near, w) = 1 / tan(fov / 2) p.y / near x’(x, y, -near, w) = 1 / (aspect * tan(fov / 2)) p.x / near
W_e,y = 2 * near_plane * tan(fov / 2) W_e,x = 2 * near_plane * aspect * W_e,y
Θ_x = atan(W_e_y / 2 / near_plane) = atanfov / t()
i.e. we have an “effective” W_e_x of
2 = 2 * near_plane * tan Θ
atan(1 / near_plane) = θ
y’ x(-near) W_e = 2 * near_plane *
W_e_y / n_e = tan (fov / 2) W_e_x = 2 n