From e67ec84db9fe117ee00541cba8b740b88ff986cf Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Fri, 18 Feb 2022 13:40:24 +0900 Subject: [PATCH] [vulkan] Use simpler projection and z_up matrices While both matrices had positive determinants in the first place, I find the projection matrix easier to understand without all the negatives, and having quake-x/vulkan-z positively parallel in the z-up matrix makes that a lot easier to think about. --- libs/video/renderer/vulkan/projection.c | 4 ++-- libs/video/renderer/vulkan/vulkan_matrices.c | 10 ++++++---- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/libs/video/renderer/vulkan/projection.c b/libs/video/renderer/vulkan/projection.c index a4f597268..1dda6a7b6 100644 --- a/libs/video/renderer/vulkan/projection.c +++ b/libs/video/renderer/vulkan/projection.c @@ -77,8 +77,8 @@ QFV_PerspectiveTan (mat4f_t proj, float fov, float aspect) fard = r_farclip->value; proj[0] = (vec4f_t) { f / aspect, 0, 0, 0 }; - proj[1] = (vec4f_t) { 0, -f, 0, 0 }; - proj[2] = (vec4f_t) { 0, 0, fard / (neard - fard), -1 }; + proj[1] = (vec4f_t) { 0, f, 0, 0 }; + proj[2] = (vec4f_t) { 0, 0, fard / (fard - neard), 1 }; proj[3] = (vec4f_t) { 0, 0, (neard * fard) / (neard - fard), 0 }; } diff --git a/libs/video/renderer/vulkan/vulkan_matrices.c b/libs/video/renderer/vulkan/vulkan_matrices.c index b35759ab9..fe66c04d4 100644 --- a/libs/video/renderer/vulkan/vulkan_matrices.c +++ b/libs/video/renderer/vulkan/vulkan_matrices.c @@ -64,11 +64,13 @@ static void setup_view (vulkan_ctx_t *ctx) { mat4f_t view; + // Quake's world is z-up, x-forward, y-left, but Vulkan's world is + // z-forward, x-right, y-down. static mat4f_t z_up = { - { 0, 0, -1, 0}, - {-1, 0, 0, 0}, - { 0, 1, 0, 0}, - { 0, 0, 0, 1}, + { 0, 0, 1, 0}, + {-1, 0, 0, 0}, + { 0,-1, 0, 0}, + { 0, 0, 0, 1}, }; vec4f_t offset = { 0, 0, 0, 1 };