[vulkan] Get sky sheets working

The sky texture is loaded with black's alpha set to 0. While this does
hit both layers, the screen is cleared to black so it shouldn't be a
problem (and will allow having a skybox behind the sheets).
This commit is contained in:
Bill Currie 2021-01-23 23:58:34 +09:00
parent 145e7478a7
commit 3132aa91a8
5 changed files with 35 additions and 15 deletions

View file

@ -81,6 +81,11 @@ typedef struct bspframe_s {
VkWriteDescriptorSet descriptors[BSP_BUFFER_INFOS + BSP_IMAGE_INFOS]; VkWriteDescriptorSet descriptors[BSP_BUFFER_INFOS + BSP_IMAGE_INFOS];
} bspframe_t; } bspframe_t;
typedef struct fragconst_s {
quat_t fog;
float time;
} fragconst_t;
typedef struct bspframeset_s typedef struct bspframeset_s
DARRAY_TYPE (bspframe_t) bspframeset_t; DARRAY_TYPE (bspframe_t) bspframeset_t;

View file

@ -101,7 +101,7 @@ get_image_size (VkImage image, qfv_device_t *device)
} }
static void static void
transfer_mips (byte *dst, const void *_src, const texture_t *tx) transfer_mips (byte *dst, const void *_src, const texture_t *tx, byte *palette)
{ {
const byte *src = _src; const byte *src = _src;
unsigned width = tx->width; unsigned width = tx->width;
@ -113,7 +113,7 @@ transfer_mips (byte *dst, const void *_src, const texture_t *tx)
// end of the texture struct // end of the texture struct
offset = tx->offsets[i] - sizeof (texture_t); offset = tx->offsets[i] - sizeof (texture_t);
count = width * height; count = width * height;
Vulkan_ExpandPalette (dst, src + offset, vid.palette, 1, count); Vulkan_ExpandPalette (dst, src + offset, palette, 2, count);
dst += count * 4; dst += count * 4;
width >>= 1; width >>= 1;
height >>= 1; height >>= 1;
@ -218,6 +218,7 @@ load_textures (model_t *model, vulkan_ctx_t *ctx)
for (int i = 0; i < model->numtextures; i++) { for (int i = 0; i < model->numtextures; i++) {
texture_t *tx = model->textures[i]; texture_t *tx = model->textures[i];
byte *palette = vid.palette32;
if (!tx) { if (!tx) {
continue; continue;
} }
@ -227,12 +228,18 @@ load_textures (model_t *model, vulkan_ctx_t *ctx)
tex->tex->offset); tex->tex->offset);
VkImageViewType type = VK_IMAGE_VIEW_TYPE_2D; VkImageViewType type = VK_IMAGE_VIEW_TYPE_2D;
if (strncmp (tx->name, "sky", 3) == 0) { if (strncmp (tx->name, "sky", 3) == 0) {
palette = alloca (256 * 4);
memcpy (palette, vid.palette32, 256 * 4);
// sky's black is transparent
// this hits both layers, but so long as the screen is cleared
// to black, no one should notice :)
palette[3] = 0;
type = VK_IMAGE_VIEW_TYPE_2D_ARRAY; type = VK_IMAGE_VIEW_TYPE_2D_ARRAY;
} }
tex->tex->view = QFV_CreateImageView (device, tex->tex->image, tex->tex->view = QFV_CreateImageView (device, tex->tex->image,
type, VK_FORMAT_R8G8B8A8_UNORM, type, VK_FORMAT_R8G8B8A8_UNORM,
VK_IMAGE_ASPECT_COLOR_BIT); VK_IMAGE_ASPECT_COLOR_BIT);
transfer_mips (buffer + tex->tex->offset, tx + 1, tx); transfer_mips (buffer + tex->tex->offset, tx + 1, tx, palette);
if (tex->glow) { if (tex->glow) {
dfunc->vkBindImageMemory (device->dev, tex->glow->image, mem, dfunc->vkBindImageMemory (device->dev, tex->glow->image, mem,
tex->glow->offset); tex->glow->offset);
@ -242,7 +249,8 @@ load_textures (model_t *model, vulkan_ctx_t *ctx)
VK_IMAGE_VIEW_TYPE_2D, VK_IMAGE_VIEW_TYPE_2D,
VK_FORMAT_R8G8B8A8_UNORM, VK_FORMAT_R8G8B8A8_UNORM,
VK_IMAGE_ASPECT_COLOR_BIT); VK_IMAGE_ASPECT_COLOR_BIT);
transfer_mips (buffer + tex->glow->offset, tex->glow->memory, tx); transfer_mips (buffer + tex->glow->offset, tex->glow->memory, tx,
palette);
} }
} }

View file

@ -8,8 +8,8 @@ layout (set = 0, binding = 5) uniform samplerCube SkyCube;
layout (push_constant) uniform PushConstants { layout (push_constant) uniform PushConstants {
layout (offset = 64) layout (offset = 64)
float time;
vec4 fog; vec4 fog;
float time;
}; };
layout (location = 0) in vec4 tl_st; layout (location = 0) in vec4 tl_st;

View file

@ -908,6 +908,9 @@ turb_begin (bspctx_t *bctx)
glsl_Fog_GetColor (fog); glsl_Fog_GetColor (fog);
fog[3] = glsl_Fog_GetDensity () / 64.0; fog[3] = glsl_Fog_GetDensity () / 64.0;
fragconst_t frag_constants = { time: vr_data.realtime };
dfunc->vkCmdPushConstants (cmd, bctx->layout, VK_SHADER_STAGE_FRAGMENT_BIT,
64, sizeof (fragconst_t), &frag_constants);
qfeglUniform4fv (quake_turb.fog.location, 1, fog); qfeglUniform4fv (quake_turb.fog.location, 1, fog);
qfeglUniform1i (quake_turb.palette.location, 1); qfeglUniform1i (quake_turb.palette.location, 1);
@ -967,15 +970,10 @@ sky_begin (vulkan_ctx_t *ctx)
qfv_device_t *device = ctx->device; qfv_device_t *device = ctx->device;
qfv_devfuncs_t *dfunc = device->funcs; qfv_devfuncs_t *dfunc = device->funcs;
bspctx_t *bctx = ctx->bsp_context; bspctx_t *bctx = ctx->bsp_context;
//XXX quat_t fog;
bctx->default_color[3] = 1; bctx->default_color[3] = 1;
QuatCopy (bctx->default_color, bctx->last_color); QuatCopy (bctx->default_color, bctx->last_color);
//XXX glsl_Fog_GetColor (fog);
//fog[3] = glsl_Fog_GetDensity () / 64.0;
//qfeglUniform4fv (sky_params.fog->location, 1, fog);
spin (ctx->matrices.sky_3d, bctx); spin (ctx->matrices.sky_3d, bctx);
__auto_type cframe = &ctx->framebuffers.a[ctx->curFrame]; __auto_type cframe = &ctx->framebuffers.a[ctx->curFrame];
@ -1121,10 +1119,10 @@ Vulkan_DrawWorld (vulkan_ctx_t *ctx)
dfunc->vkCmdPushConstants (bframe->bsp_cmd, bctx->layout, dfunc->vkCmdPushConstants (bframe->bsp_cmd, bctx->layout,
VK_SHADER_STAGE_VERTEX_BIT, VK_SHADER_STAGE_VERTEX_BIT,
0, 16 * sizeof (float), identity); 0, 16 * sizeof (float), identity);
float frag_pc[8] = { }; fragconst_t frag_constants = { time: vr_data.realtime };
dfunc->vkCmdPushConstants (bframe->bsp_cmd, bctx->layout, dfunc->vkCmdPushConstants (bframe->bsp_cmd, bctx->layout,
VK_SHADER_STAGE_FRAGMENT_BIT, VK_SHADER_STAGE_FRAGMENT_BIT,
64, 8 * sizeof (float), &frag_pc); 64, sizeof (fragconst_t), &frag_constants);
//XXX qfeglActiveTexture (GL_TEXTURE0 + 0); //XXX qfeglActiveTexture (GL_TEXTURE0 + 0);
for (size_t i = 0; i < bctx->texture_chains.size; i++) { for (size_t i = 0; i < bctx->texture_chains.size; i++) {
vulktex_t *tex; vulktex_t *tex;
@ -1234,10 +1232,10 @@ Vulkan_DrawSky (vulkan_ctx_t *ctx)
dfunc->vkCmdPushConstants (bframe->sky_cmd, bctx->layout, dfunc->vkCmdPushConstants (bframe->sky_cmd, bctx->layout,
VK_SHADER_STAGE_VERTEX_BIT, VK_SHADER_STAGE_VERTEX_BIT,
0, 16 * sizeof (float), identity); 0, 16 * sizeof (float), identity);
float frag_pc[8] = { }; fragconst_t frag_constants = { time: vr_data.realtime };
dfunc->vkCmdPushConstants (bframe->sky_cmd, bctx->layout, dfunc->vkCmdPushConstants (bframe->sky_cmd, bctx->layout,
VK_SHADER_STAGE_FRAGMENT_BIT, VK_SHADER_STAGE_FRAGMENT_BIT,
64, 8 * sizeof (float), &frag_pc); 64, sizeof (fragconst_t), &frag_constants);
for (is = bctx->sky_chain; is; is = is->tex_chain) { for (is = bctx->sky_chain; is; is = is->tex_chain) {
surf = is->surface; surf = is->surface;
if (tex != surf->texinfo->texture->render) { if (tex != surf->texinfo->texture->render) {

View file

@ -89,7 +89,16 @@ void
Vulkan_ExpandPalette (byte *dst, const byte *src, const byte *palette, Vulkan_ExpandPalette (byte *dst, const byte *src, const byte *palette,
int alpha, int count) int alpha, int count)
{ {
if (alpha) { if (alpha > 1) {
while (count-- > 0) {
int pix = *src++;
const byte *col = palette + pix * 4;
*dst++ = *col++;
*dst++ = *col++;
*dst++ = *col++;
*dst++ = *col++;
}
} else if (alpha) {
while (count-- > 0) { while (count-- > 0) {
byte pix = *src++; byte pix = *src++;
const byte *col = palette + pix * 3; const byte *col = palette + pix * 3;