diff --git a/include/QF/Vulkan/qf_matrices.h b/include/QF/Vulkan/qf_matrices.h index 505bb1fe9..9b8e6d3b5 100644 --- a/include/QF/Vulkan/qf_matrices.h +++ b/include/QF/Vulkan/qf_matrices.h @@ -39,7 +39,7 @@ typedef struct qfv_matrix_buffer_s { // projection and view matrices (model is push constant) mat4f_t Projection3d; - mat4f_t View; + mat4f_t View[6]; mat4f_t Sky; mat4f_t Projection2d; vec2f_t ScreenSize; diff --git a/libs/video/renderer/vulkan/shader/alias.vert b/libs/video/renderer/vulkan/shader/alias.vert index ccfa78756..4309266f0 100644 --- a/libs/video/renderer/vulkan/shader/alias.vert +++ b/libs/video/renderer/vulkan/shader/alias.vert @@ -1,5 +1,6 @@ #version 450 #extension GL_GOOGLE_include_directive : enable +#extension GL_EXT_multiview : enable layout (set = 0, binding = 0) uniform #include "matrices.h" @@ -30,7 +31,7 @@ main (void) vertex = mix (vertexa, vertexb, blend); norm = mix (normala, normalb, blend); pos = (Model * vertex); - gl_Position = Projection3d * (View * pos); + gl_Position = Projection3d * (View[gl_ViewIndex] * pos); position = pos; normal = normalize (mat3 (Model) * norm); st = uv; diff --git a/libs/video/renderer/vulkan/shader/alias_depth.vert b/libs/video/renderer/vulkan/shader/alias_depth.vert index 7f14e2ace..7d01354f3 100644 --- a/libs/video/renderer/vulkan/shader/alias_depth.vert +++ b/libs/video/renderer/vulkan/shader/alias_depth.vert @@ -1,5 +1,6 @@ #version 450 #extension GL_GOOGLE_include_directive : enable +#extension GL_EXT_multiview : enable layout (set = 0, binding = 0) uniform #include "matrices.h" @@ -23,5 +24,5 @@ main (void) vertex = mix (vertexa, vertexb, blend); pos = (Model * vertex); - gl_Position = Projection3d * (View * pos); + gl_Position = Projection3d * (View[gl_ViewIndex] * pos); } diff --git a/libs/video/renderer/vulkan/shader/bsp_depth.vert b/libs/video/renderer/vulkan/shader/bsp_depth.vert index a3ab262ba..b454b8787 100644 --- a/libs/video/renderer/vulkan/shader/bsp_depth.vert +++ b/libs/video/renderer/vulkan/shader/bsp_depth.vert @@ -1,5 +1,6 @@ #version 450 #extension GL_GOOGLE_include_directive : enable +#extension GL_EXT_multiview : enable #include "entity.h" @@ -18,5 +19,5 @@ void main (void) { vec3 vert = vertex * entities[entid].transform; - gl_Position = Projection3d * (View * vec4 (vert, 1)); + gl_Position = Projection3d * (View[gl_ViewIndex] * vec4 (vert, 1)); } diff --git a/libs/video/renderer/vulkan/shader/bsp_gbuf.geom b/libs/video/renderer/vulkan/shader/bsp_gbuf.geom index 38bba91fa..f5a32ebd2 100644 --- a/libs/video/renderer/vulkan/shader/bsp_gbuf.geom +++ b/libs/video/renderer/vulkan/shader/bsp_gbuf.geom @@ -1,5 +1,6 @@ #version 450 #extension GL_GOOGLE_include_directive : enable +#extension GL_EXT_multiview : enable layout (set = 0, binding = 0) uniform #include "matrices.h" @@ -28,7 +29,7 @@ main() for (int vert = 0; vert < 3; vert++) { vec4 p = gl_in[vert].gl_Position; - gl_Position = Projection3d * (View * (p)); + gl_Position = Projection3d * (View[gl_ViewIndex] * (p)); tl_st = v_tl_st[vert]; direction = v_direction[vert]; color = v_color[vert]; diff --git a/libs/video/renderer/vulkan/shader/iqm.vert b/libs/video/renderer/vulkan/shader/iqm.vert index a40d0ba70..4b5d06433 100644 --- a/libs/video/renderer/vulkan/shader/iqm.vert +++ b/libs/video/renderer/vulkan/shader/iqm.vert @@ -1,5 +1,6 @@ #version 450 #extension GL_GOOGLE_include_directive : enable +#extension GL_EXT_multiview : enable layout (constant_id = 0) const bool IQMDepthOnly = false; @@ -40,7 +41,7 @@ main (void) m += bones[vbones.z] * vweights.z; m += bones[vbones.w] * vweights.w; vec4 pos = Model * vec4 (vec4(vposition, 1) * m, 1); - gl_Position = Projection3d * (View * pos); + gl_Position = Projection3d * (View[gl_ViewIndex] * pos); if (!IQMDepthOnly) { position = pos; diff --git a/libs/video/renderer/vulkan/shader/matrices.h b/libs/video/renderer/vulkan/shader/matrices.h index b5640cc3f..e66bc265b 100644 --- a/libs/video/renderer/vulkan/shader/matrices.h +++ b/libs/video/renderer/vulkan/shader/matrices.h @@ -1,6 +1,6 @@ Matrices { mat4 Projection3d; - mat4 View; + mat4 View[6]; mat4 Sky; mat4 Projection2d; diff --git a/libs/video/renderer/vulkan/shader/particle.vert b/libs/video/renderer/vulkan/shader/particle.vert index 40a35c2c3..4be3dec33 100644 --- a/libs/video/renderer/vulkan/shader/particle.vert +++ b/libs/video/renderer/vulkan/shader/particle.vert @@ -1,5 +1,6 @@ #version 450 #extension GL_GOOGLE_include_directive : enable +#extension GL_EXT_multiview : enable layout (set = 0, binding = 0) uniform #include "matrices.h" @@ -23,8 +24,8 @@ void main (void) { // geometry shader will take care of Projection - gl_Position = View * (Model * position); - o_velocity = View * (Model * velocity); + gl_Position = View[gl_ViewIndex] * (Model * position); + o_velocity = View[gl_ViewIndex] * (Model * velocity); uint c = floatBitsToInt (color.x); uint x = c & 0x0f; uint y = (c >> 4) & 0x0f; diff --git a/libs/video/renderer/vulkan/shader/quakebsp.vert b/libs/video/renderer/vulkan/shader/quakebsp.vert index e93c0ea9e..d10bf89df 100644 --- a/libs/video/renderer/vulkan/shader/quakebsp.vert +++ b/libs/video/renderer/vulkan/shader/quakebsp.vert @@ -1,5 +1,6 @@ #version 450 #extension GL_GOOGLE_include_directive : enable +#extension GL_EXT_multiview : enable #include "entity.h" @@ -23,7 +24,7 @@ void main (void) { vec3 vert = vertex * entities[entid].transform; - gl_Position = Projection3d * (View * vec4 (vert, 1)); + gl_Position = Projection3d * (View[gl_ViewIndex] * vec4 (vert, 1)); direction = (Sky * vertex).xyz; tl_st = tl_uv; color = entities[entid].color; diff --git a/libs/video/renderer/vulkan/shader/sprite_depth.vert b/libs/video/renderer/vulkan/shader/sprite_depth.vert index 20f6dc0d6..1eca8e043 100644 --- a/libs/video/renderer/vulkan/shader/sprite_depth.vert +++ b/libs/video/renderer/vulkan/shader/sprite_depth.vert @@ -1,5 +1,6 @@ #version 450 #extension GL_GOOGLE_include_directive : enable +#extension GL_EXT_multiview : enable layout (set = 0, binding = 0) uniform #include "matrices.h" @@ -24,6 +25,6 @@ main (void) vec4 pos = Model[3]; pos += v.x * Model[1] + v.y * Model[2]; - gl_Position = Projection3d * (View * pos); + gl_Position = Projection3d * (View[gl_ViewIndex] * pos); st = v.zw; } diff --git a/libs/video/renderer/vulkan/shader/sprite_gbuf.vert b/libs/video/renderer/vulkan/shader/sprite_gbuf.vert index 1cdfb0f26..e96d25848 100644 --- a/libs/video/renderer/vulkan/shader/sprite_gbuf.vert +++ b/libs/video/renderer/vulkan/shader/sprite_gbuf.vert @@ -1,5 +1,6 @@ #version 450 #extension GL_GOOGLE_include_directive : enable +#extension GL_EXT_multiview : enable layout (set = 0, binding = 0) uniform #include "matrices.h" @@ -26,7 +27,7 @@ main (void) vec4 pos = Model[3]; pos += v.x * Model[1] + v.y * Model[2]; - gl_Position = Projection3d * (View * pos); + gl_Position = Projection3d * (View[gl_ViewIndex] * pos); st = v.zw; position = pos; normal = -vec3(Model[0]); diff --git a/libs/video/renderer/vulkan/vulkan_matrices.c b/libs/video/renderer/vulkan/vulkan_matrices.c index e22f1ff3b..41f031e2b 100644 --- a/libs/video/renderer/vulkan/vulkan_matrices.c +++ b/libs/video/renderer/vulkan/vulkan_matrices.c @@ -103,8 +103,8 @@ Vulkan_SetViewMatrix (vulkan_ctx_t *ctx, mat4f_t view) { __auto_type mctx = ctx->matrix_context; - if (memcmp (mctx->matrices.View, view, sizeof (mat4f_t))) { - memcpy (mctx->matrices.View, view, sizeof (mat4f_t)); + if (memcmp (mctx->matrices.View[0], view, sizeof (mat4f_t))) { + memcpy (mctx->matrices.View[0], view, sizeof (mat4f_t)); mctx->dirty = mctx->frames.size; } } @@ -238,7 +238,9 @@ Vulkan_Matrix_Init (vulkan_ctx_t *ctx) mctx->sky_time = vr_data.realtime; mat4fidentity (mctx->matrices.Projection3d); - mat4fidentity (mctx->matrices.View); + for (int i = 0; i < 6; i++) { + mat4fidentity (mctx->matrices.View[i]); + } mat4fidentity (mctx->matrices.Sky); mat4fidentity (mctx->matrices.Projection2d);