[vulkan] Get particle colors working for id style

This required making the texture set accessible to the vertex shader
(instead of using a dedicated palette set), which I don't particularly
like, but I don't feel like dealing with the texture code's hard-coded
use of the texture set. QF style particles need something mostly for the
smoke puffs as they expect a texture.
This commit is contained in:
Bill Currie 2022-11-28 22:57:22 +09:00
parent 76258906f9
commit b81a77c3f7
4 changed files with 12 additions and 6 deletions

View file

@ -289,7 +289,7 @@
binding = 0;
descriptorType = combined_image_sampler;
descriptorCount = 1;
stageFlags = fragment;
stageFlags = fragment|vertex;
},
);
};
@ -507,7 +507,7 @@
setLayouts = (particle_set, particle_set, particle_set);
};
partdraw_layout = {
setLayouts = (matrix_set);
setLayouts = (matrix_set, texture_set);
pushConstantRanges = (
{
stageFlags = vertex;

View file

@ -8,13 +8,13 @@ layout (location = 0) out vec4 frag_color;
void
main (void)
{
vec4 c = vec4 (1,1,1,1);//color;
vec4 c = color;
vec2 x = uv_tr.xy;
float a = 1 - dot (x, x);
if (a <= 0) {
discard;
}
c.a *= sqrt (a);
c *= (a);
frag_color = c;
}

View file

@ -4,6 +4,7 @@
layout (set = 0, binding = 0) uniform
#include "matrices.h"
;
layout (set = 1, binding = 0) uniform sampler2D Palette;
layout (push_constant) uniform PushConstants {
mat4 Model;
@ -24,6 +25,9 @@ main (void)
// geometry shader will take care of Projection
gl_Position = View * (Model * position);
o_velocity = View * (Model * velocity);
o_color = color;
uint c = floatBitsToInt (color.x);
uint x = c & 0x0f;
uint y = (c >> 4) & 0x0f;
o_color = texture (Palette, vec2 (x, y) / 15.0);
o_ramp = ramp;
}

View file

@ -50,6 +50,7 @@
#include "QF/Vulkan/resource.h"
#include "QF/Vulkan/staging.h"
#include "QF/Vulkan/qf_matrices.h"
#include "QF/Vulkan/qf_palette.h"
#include "QF/Vulkan/qf_particles.h"
#include "QF/Vulkan/qf_renderpass.h"
@ -98,9 +99,10 @@ particle_begin_subpass (VkPipeline pipeline, qfv_renderframe_t *rFrame)
dfunc->vkCmdBindPipeline (cmd, VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
VkDescriptorSet sets[] = {
Vulkan_Matrix_Descriptors (ctx, ctx->curFrame),
Vulkan_Palette_Descriptor (ctx),
};
dfunc->vkCmdBindDescriptorSets (cmd, VK_PIPELINE_BIND_POINT_GRAPHICS,
pctx->draw_layout, 0, 1, sets, 0, 0);
pctx->draw_layout, 0, 2, sets, 0, 0);
dfunc->vkCmdSetViewport (cmd, 0, 1, &rFrame->renderpass->viewport);
dfunc->vkCmdSetScissor (cmd, 0, 1, &rFrame->renderpass->scissor);
}