mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2024-11-26 06:10:56 +00:00
[vulkan] Adapt the shaders for multi-view
Multi-view will be used for shadows and fisheye.
This commit is contained in:
parent
e709eceb75
commit
25ac0ff303
12 changed files with 26 additions and 15 deletions
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
|
|
|
@ -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];
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
Matrices {
|
||||
mat4 Projection3d;
|
||||
mat4 View;
|
||||
mat4 View[6];
|
||||
mat4 Sky;
|
||||
mat4 Projection2d;
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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]);
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
Loading…
Reference in a new issue