[vulkan] Add tan and cos perspective projection

The tan and cos versions allow specifying the fov directly from the tan
or cos of the half angle, useful for dealing with lights.
This commit is contained in:
Bill Currie 2021-04-29 19:27:01 +09:00
parent cb7d2671d8
commit 562f3c2fe2
2 changed files with 18 additions and 2 deletions

View file

@ -5,6 +5,8 @@
void QFV_Orthographic (mat4f_t proj, float xmin, float xmax,
float ymin, float ymax, float znear, float zfar);
void QFV_PerspectiveTan (mat4f_t proj, float fov, float aspect);
void QFV_PerspectiveCos (mat4f_t proj, float fov, float aspect);
void QFV_Perspective (mat4f_t proj, float fov, float aspect);
#endif//__QF_Vulkan_projection_h

View file

@ -68,9 +68,9 @@ QFV_Orthographic (mat4f_t proj, float xmin, float xmax, float ymin, float ymax,
}
void
QFV_Perspective (mat4f_t proj, float fov, float aspect)
QFV_PerspectiveTan (mat4f_t proj, float fov, float aspect)
{
float f = 1 / tan (fov * M_PI / 360);
float f = 1 / fov;
float neard, fard;
neard = r_nearclip->value;
@ -81,3 +81,17 @@ QFV_Perspective (mat4f_t proj, float fov, float aspect)
proj[2] = (vec4f_t) { 0, 0, fard / (neard - fard), -1 };
proj[3] = (vec4f_t) { 0, 0, (neard * fard) / (neard - fard), 0 };
}
void
QFV_PerspectiveCos (mat4f_t proj, float fov, float aspect)
{
// square first for auto-abs (no support for > 180 degree fov)
fov = fov * fov;
QFV_PerspectiveTan (proj, sqrt ((1 - fov) / fov), aspect);
}
void
QFV_Perspective (mat4f_t proj, float fov, float aspect)
{
QFV_PerspectiveTan (proj, tan (fov * M_PI / 360), aspect);
}