[vulkan] Update the sky matrix

Regardless of whether the sky is spinning or not, the matrix needs to be
updated with the current origin in order to get the direction vector
right in the shader. Also, it's in the update that the required x-y
plane rotation gets in so the skies move in the correct direction.
This commit is contained in:
Bill Currie 2022-02-18 13:29:41 +09:00
parent 981fcca76d
commit cd26073b6a
4 changed files with 52 additions and 36 deletions

View file

@ -133,10 +133,6 @@ typedef struct bspctx_s {
struct qfv_tex_s *default_skybox;
struct qfv_tex_s *skybox_tex;
VkDescriptorSet skybox_descriptor;
vec4f_t sky_rotation[2];
vec4f_t sky_velocity;
vec4f_t sky_fix;
double sky_time;
quat_t default_color;
quat_t last_color;

View file

@ -68,6 +68,11 @@ typedef struct matrixctx_s {
struct qfv_stagebuf_s *stage;
VkDescriptorPool pool;
VkDescriptorSetLayout setLayout;
vec4f_t sky_rotation[2];
vec4f_t sky_velocity;
vec4f_t sky_fix;
double sky_time;
} matrixctx_t;
struct vulkan_ctx_s;
@ -77,6 +82,7 @@ void Vulkan_CalcProjectionMatrices (struct vulkan_ctx_s *ctx);
void Vulkan_CalcViewMatrix (struct vulkan_ctx_s *ctx);
void Vulkan_SetViewMatrix (struct vulkan_ctx_s *ctx, mat4f_t view);
void Vulkan_SetSkyMatrix (struct vulkan_ctx_s *ctx, mat4f_t sky);
void Vulkan_SetSkyMatrix (struct vulkan_ctx_s *ctx, mat4f_t sky);
void Vulkan_Matrix_Init (struct vulkan_ctx_s *ctx);
void Vulkan_Matrix_Shutdown (struct vulkan_ctx_s *ctx);

View file

@ -413,13 +413,6 @@ Vulkan_BuildDisplayLists (model_t **models, int num_models, vulkan_ctx_t *ctx)
bsppoly_t *poly;
mod_brush_t *brush;
bctx->sky_fix = (vec4f_t) { 0, 0, 1, 1 } * sqrtf (0.5);
bctx->sky_rotation[0] = (vec4f_t) { 0, 0, 0, 1};
bctx->sky_rotation[1] = bctx->sky_rotation[0];
bctx->sky_velocity = (vec4f_t) { };
bctx->sky_velocity = qexpf (bctx->sky_velocity);
bctx->sky_time = vr_data.realtime;
// run through all surfaces, chaining them to their textures, thus
// effectively sorting the surfaces by texture (without worrying about
// surface order on the same texture chain).
@ -948,30 +941,7 @@ turb_end (vulkan_ctx_t *ctx)
bsp_end_subpass (bframe->cmdSet.a[QFV_bspTurb], ctx);
}
/*XXX
static void
spin (mat4f_t mat, bspctx_t *bctx)
{
vec4f_t q;
mat4f_t m;
float blend;
while (vr_data.realtime - bctx->sky_time > 1) {
bctx->sky_rotation[0] = bctx->sky_rotation[1];
bctx->sky_rotation[1] = qmulf (bctx->sky_velocity,
bctx->sky_rotation[0]);
bctx->sky_time += 1;
}
blend = bound (0, (vr_data.realtime - bctx->sky_time), 1);
q = Blend (bctx->sky_rotation[0], bctx->sky_rotation[1], blend);
q = normalf (qmulf (bctx->sky_fix, q));
mat4fidentity (mat);
VectorNegate (r_origin, mat[3]);
mat4fquat (m, q);
mmulf (mat, m, mat);
}
*/
static void
sky_begin (qfv_renderframe_t *rFrame)
{
@ -981,8 +951,6 @@ sky_begin (qfv_renderframe_t *rFrame)
bctx->default_color[3] = 1;
QuatCopy (bctx->default_color, bctx->last_color);
//XXX spin (ctx->matrices.sky_3d, bctx);
bspframe_t *bframe = &bctx->frames.a[ctx->curFrame];
DARRAY_APPEND (&rFrame->subpassCmdSets[QFV_passTranslucent],

View file

@ -86,6 +86,32 @@ setup_view (vulkan_ctx_t *ctx)
Vulkan_SetViewMatrix (ctx, view);
}
static void
setup_sky (vulkan_ctx_t *ctx)
{
__auto_type mctx = ctx->matrix_context;
vec4f_t q;
mat4f_t m;
float blend;
mat4f_t mat;
while (vr_data.realtime - mctx->sky_time > 1) {
mctx->sky_rotation[0] = mctx->sky_rotation[1];
mctx->sky_rotation[1] = qmulf (mctx->sky_velocity,
mctx->sky_rotation[0]);
mctx->sky_time += 1;
}
blend = bound (0, (vr_data.realtime - mctx->sky_time), 1);
q = Blend (mctx->sky_rotation[0], mctx->sky_rotation[1], blend);
q = normalf (qmulf (mctx->sky_fix, q));
mat4fidentity (mat);
VectorNegate (r_origin, mat[3]);
mat4fquat (m, q);
mmulf (mat, m, mat);
Vulkan_SetSkyMatrix (ctx, mat);
}
void
Vulkan_SetViewMatrix (vulkan_ctx_t *ctx, mat4f_t view)
{
@ -97,6 +123,17 @@ Vulkan_SetViewMatrix (vulkan_ctx_t *ctx, mat4f_t view)
}
}
void
Vulkan_SetSkyMatrix (vulkan_ctx_t *ctx, mat4f_t sky)
{
__auto_type mctx = ctx->matrix_context;
if (memcmp (mctx->matrices.Sky, sky, sizeof (mat4f_t))) {
memcpy (mctx->matrices.Sky, sky, sizeof (mat4f_t));
mctx->dirty = mctx->frames.size;
}
}
void
Vulkan_Matrix_Draw (qfv_renderframe_t *rFrame)
{
@ -108,6 +145,7 @@ Vulkan_Matrix_Draw (qfv_renderframe_t *rFrame)
__auto_type mframe = &mctx->frames.a[ctx->curFrame];
setup_view (ctx);
setup_sky (ctx);
if (mctx->dirty <= 0) {
mctx->dirty = 0;
@ -241,10 +279,18 @@ Vulkan_Matrix_Init (vulkan_ctx_t *ctx)
}
free (sets);
mctx->sky_fix = (vec4f_t) { 0, 0, 1, 1 } * sqrtf (0.5);
mctx->sky_rotation[0] = (vec4f_t) { 0, 0, 0, 1};
mctx->sky_rotation[1] = mctx->sky_rotation[0];
mctx->sky_velocity = (vec4f_t) { };
mctx->sky_velocity = qexpf (mctx->sky_velocity);
mctx->sky_time = vr_data.realtime;
mat4fidentity (mctx->matrices.Projection3d);
mat4fidentity (mctx->matrices.View);
mat4fidentity (mctx->matrices.Sky);
mat4fidentity (mctx->matrices.Projection2d);
mctx->dirty = mctx->frames.size;
mctx->stage = QFV_CreateStagingBuffer (device, "matrix",