0
0
Fork 0
mirror of https://git.code.sf.net/p/quake/quakeforge synced 2025-04-14 21:33:55 +00:00

[vulkan] Get deferred renderer mostly working

It's just lightmap vs lighting (scene load and bsp rendering) and
compose (attachments or no) that need sorting out, and, of course, a way
to select between the two.
This commit is contained in:
Bill Currie 2024-01-20 02:39:06 +09:00
parent fc5b1d5f6e
commit 13c6065f9f
8 changed files with 78 additions and 76 deletions

View file

@ -378,8 +378,8 @@ qskin_fwdf_src = $(vkshaderpath)/qskin_fwd.frag
qskin_fwdf_c = $(vkshaderpath)/qskin_fwd.frag.spvc
alias_depth_src = $(vkshaderpath)/alias_depth.vert
alias_depth_c = $(vkshaderpath)/alias_depth.vert.spvc
alias_gbuf_src = $(vkshaderpath)/alias_gbuf.frag
alias_gbuf_c = $(vkshaderpath)/alias_gbuf.frag.spvc
qskin_gbuf_src = $(vkshaderpath)/qskin_gbuf.frag
qskin_gbuf_c = $(vkshaderpath)/qskin_gbuf.frag.spvc
alias_shadow_src = $(vkshaderpath)/alias_shadow.vert
alias_shadow_c = $(vkshaderpath)/alias_shadow.vert.spvc
iqmv_src = $(vkshaderpath)/iqm.vert
@ -486,7 +486,7 @@ $(alias_depth_c): $(alias_depth_src) $(matrices_h)
$(qskin_fwdf_c): $(qskin_fwdf_src)
$(alias_gbuf_c): $(alias_gbuf_src)
$(qskin_gbuf_c): $(qskin_gbuf_src)
$(alias_shadow_c): $(alias_shadow_src)
@ -557,7 +557,7 @@ vkshader_c = \
$(aliasv_c) \
$(alias_depth_c) \
$(qskin_fwdf_c) \
$(alias_gbuf_c) \
$(qskin_gbuf_c) \
$(alias_shadow_c) \
$(iqmv_c) \
$(iqmf_c) \
@ -658,7 +658,7 @@ EXTRA_DIST += \
$(aliasv_src) \
$(qskin_fwdf_src) \
$(alias_depth_src) \
$(alias_gbuf_src) \
$(qskin_gbuf_src) \
$(alias_shadow_src) \
$(iqmv_src) \
$(iqmf_src) \

View file

@ -364,11 +364,6 @@ properties = {
name = main;
module = $builtin/alias.vert;
};
gbuf_fragment = {
stage = fragment;
name = main;
module = $builtin/alias_gbuf.frag;
};
};
vertexInput = {
bindings = (
@ -399,7 +394,16 @@ properties = {
shadow_layout = {
descriptorSets = (shadowmat_set);
pushConstants = {
vertex = { Model = mat4; blend = float; MatrixBase = uint; };
vertex = { Model = mat4; blend = float; MatrixBase = uint; };
};
};
};
qskin = {
shader = {
fragment = {
stage = fragment;
name = main;
module = $builtin/qskin_gbuf.frag;
};
};
};
@ -441,11 +445,6 @@ properties = {
data = "array(0)";
};
};
gbuf_fragment = {
stage = fragment;
name = main;
module = $builtin/iqm.frag;
};
};
vertexInput = {
bindings = (
@ -469,16 +468,16 @@ properties = {
primitiveRestartEnable = false;
};
layout = {
// skin
descriptorSets = (matrix_set, shadowmat_set, texture_set, bone_set);
// palette skin
descriptorSets = (matrix_set, texture_set, texture_set, bone_set);
pushConstants = {
vertex = { Model = mat4; blend = float; };
fragment = { colors = uint; base_color = vec4; fog = vec4; };
};
};
shadow_layout = {
// skin
descriptorSets = (matrix_set, shadowmat_set, texture_set, bone_set);
// palette(n/u) skin(n/u)
descriptorSets = (shadowmat_set, texture_set, texture_set, bone_set);
pushConstants = {
vertex = { Model = mat4; blend = float; MatrixBase = uint; };
};
@ -1746,7 +1745,7 @@ renderpasses = {
stages = (
$alias.shader.gbuf_vertex,
$alias.shader.gbuf_fragment,
$qskin.shader.fragment,
);
vertexInput = $alias.vertexInput;
inputAssembly = $alias.inputAssembly;
@ -1761,7 +1760,7 @@ renderpasses = {
stages = (
$iqm.shader.gbuf_vertex,
$iqm.shader.gbuf_fragment,
$qskin.shader.fragment,
);
vertexInput = $iqm.vertexInput;
inputAssembly = $iqm.inputAssembly;
@ -2277,7 +2276,7 @@ renderpasses = {
);
vertexInput = $iqm.vertexInput;
inputAssembly = $iqm.inputAssembly;
layout = $iqm.layout;
layout = $iqm.shadow_layout;
};
};
};

View file

@ -123,7 +123,7 @@ static
static
#include "libs/video/renderer/vulkan/shader/qskin_fwd.frag.spvc"
static
#include "libs/video/renderer/vulkan/shader/alias_gbuf.frag.spvc"
#include "libs/video/renderer/vulkan/shader/qskin_gbuf.frag.spvc"
static
#include "libs/video/renderer/vulkan/shader/alias_shadow.vert.spvc"
static
@ -202,7 +202,7 @@ static shaderdata_t builtin_shaders[] = {
{ "alias.vert", alias_vert, sizeof (alias_vert) },
{ "alias_depth.vert", alias_depth_vert, sizeof (alias_depth_vert) },
{ "qskin_fwd.frag", qskin_fwd_frag, sizeof (qskin_fwd_frag) },
{ "alias_gbuf.frag", alias_gbuf_frag, sizeof (alias_gbuf_frag) },
{ "qskin_gbuf.frag", qskin_gbuf_frag, sizeof (qskin_gbuf_frag) },
{ "alias_shadow.vert", alias_shadow_vert, sizeof (alias_shadow_vert) },
{ "iqm.vert", iqm_vert, sizeof (iqm_vert) },
{ "iqm.frag", iqm_frag, sizeof (iqm_frag) },

View file

@ -30,8 +30,8 @@ main (void)
//vec3 n;
int i;
vec3 normal = normalize (fnormal);
vec3 tangent = normalize (ftangent);
vec3 bitangent = normalize (fbitangent);
//vec3 tangent = normalize (ftangent);
//vec3 bitangent = normalize (fbitangent);
//mat3 tbn = mat3 (tangent, bitangent, normal);
c = texture (Skin, texcoord);// * color;

View file

@ -29,9 +29,9 @@ layout (location = 6) in vec4 vcolor;
layout (location = 0) out vec2 texcoord;
layout (location = 1) out vec4 position;
layout (location = 2) out vec3 normal;
layout (location = 3) out vec3 tangent;
layout (location = 4) out vec3 bitangent;
layout (location = 5) out vec4 color;
//layout (location = 3) out vec3 tangent;
//layout (location = 4) out vec3 bitangent;
//layout (location = 5) out vec4 color;
void
main (void)
@ -45,15 +45,15 @@ main (void)
gl_Position = Projection3d * (View[gl_ViewIndex] * pos);
if (!IQMDepthOnly) {
texcoord = vtexcoord;
position = pos;
mat3 adjTrans = mat3 (cross(m[1].xyz, m[2].xyz),
cross(m[2].xyz, m[0].xyz),
cross(m[0].xyz, m[1].xyz));
normal = normalize (mat3 (Model) * vnormal * adjTrans);
tangent = mat3 (Model) * vtangent.xyz * adjTrans;
tangent = normalize (tangent - dot (tangent, normal) * normal);
bitangent = cross (normal, tangent) * vtangent.w;
texcoord = vtexcoord;
color = vcolor;
//tangent = mat3 (Model) * vtangent.xyz * adjTrans;
//tangent = normalize (tangent - dot (tangent, normal) * normal);
//bitangent = cross (normal, tangent) * vtangent.w;
//color = vcolor;
}
}

View file

@ -3,17 +3,12 @@
#extension GL_EXT_multiview : enable
layout (constant_id = 0) const bool IQMDepthOnly = false;
layout (constant_id = 1) const bool IQMShadow = false;
layout (set = 0, binding = 0) uniform
#include "matrices.h"
;
layout (set = 1, binding = 0) buffer ShadowView {
layout (set = 0, binding = 0) buffer ShadowView {
mat4x4 shadowView[];
};
layout (set = 1, binding = 1) buffer ShadowId {
layout (set = 0, binding = 1) buffer ShadowId {
uint shadowId[];
};
@ -52,12 +47,8 @@ main (void)
m += bones[vbones.w] * vweights.w;
m += mat3x4(1,0,0,0,0,1,0,0,0,0,1,0) * (1 - dot(vweights, vec4(1,1,1,1)));
vec4 pos = Model * vec4 (vec4(vposition, 1) * m, 1);
if (IQMShadow) {
uint matid = shadowId[MatrixBase + gl_ViewIndex];
gl_Position = shadowView[matid] * pos;
} else {
gl_Position = Projection3d * (View[gl_ViewIndex] * pos);
}
uint matid = shadowId[MatrixBase + gl_ViewIndex];
gl_Position = shadowView[matid] * pos;
if (!IQMDepthOnly) {
position = pos;

View file

@ -187,7 +187,7 @@ Vulkan_IQMRemoveSkin (vulkan_ctx_t *ctx, qfv_iqm_skin_t *skin)
}
static void
iqm_draw_ent (qfv_taskctx_t *taskctx, entity_t ent, bool pass)
iqm_draw_ent (qfv_taskctx_t *taskctx, entity_t ent, bool pass, bool shadow)
{
auto ctx = taskctx->ctx;
auto device = ctx->device;
@ -242,33 +242,45 @@ iqm_draw_ent (qfv_taskctx_t *taskctx, entity_t ent, bool pass)
dfunc->vkUnmapMemory (device->dev, mesh->bones->memory);
transform_t transform = Entity_Transform (ent);
qfv_push_constants_t push_constants[] = {
{ VK_SHADER_STAGE_VERTEX_BIT,
field_offset (iqm_push_constants_t, mat),
sizeof (mat4f_t), Transform_GetWorldMatrixPtr (transform) },
{ VK_SHADER_STAGE_VERTEX_BIT,
field_offset (iqm_push_constants_t, blend),
sizeof (float), &constants.blend },
#if 0
{ VK_SHADER_STAGE_VERTEX_BIT,
field_offset (iqm_push_constants_t, matrix_base),
sizeof (uint32_t), &constants.matrix_base },
#endif
{ VK_SHADER_STAGE_FRAGMENT_BIT,
field_offset (iqm_push_constants_t, colors),
sizeof (constants.colors), constants.colors },
{ VK_SHADER_STAGE_FRAGMENT_BIT,
field_offset (iqm_push_constants_t, base_color),
sizeof (constants.base_color), &constants.base_color },
{ VK_SHADER_STAGE_FRAGMENT_BIT,
field_offset (iqm_push_constants_t, fog),
sizeof (constants.fog), &constants.fog },
};
if (shadow) {
qfv_push_constants_t push_constants[] = {
{ VK_SHADER_STAGE_VERTEX_BIT,
field_offset (iqm_push_constants_t, mat),
sizeof (mat4f_t), Transform_GetWorldMatrixPtr (transform) },
{ VK_SHADER_STAGE_VERTEX_BIT,
field_offset (iqm_push_constants_t, blend),
sizeof (float), &constants.blend },
{ VK_SHADER_STAGE_VERTEX_BIT,
field_offset (iqm_push_constants_t, matrix_base),
sizeof (uint32_t), &constants.matrix_base },
};
emit_commands (taskctx->cmd, animation->pose1, animation->pose2,
pass ? skins : 0,
pass ? 5 : 3, push_constants,
iqm, taskctx, ent);
emit_commands (taskctx->cmd, animation->pose1, animation->pose2,
nullptr, 3, push_constants, iqm, taskctx, ent);
} else {
qfv_push_constants_t push_constants[] = {
{ VK_SHADER_STAGE_VERTEX_BIT,
field_offset (iqm_push_constants_t, mat),
sizeof (mat4f_t), Transform_GetWorldMatrixPtr (transform) },
{ VK_SHADER_STAGE_VERTEX_BIT,
field_offset (iqm_push_constants_t, blend),
sizeof (float), &constants.blend },
{ VK_SHADER_STAGE_FRAGMENT_BIT,
field_offset (iqm_push_constants_t, colors),
sizeof (constants.colors), constants.colors },
{ VK_SHADER_STAGE_FRAGMENT_BIT,
field_offset (iqm_push_constants_t, base_color),
sizeof (constants.base_color), &constants.base_color },
{ VK_SHADER_STAGE_FRAGMENT_BIT,
field_offset (iqm_push_constants_t, fog),
sizeof (constants.fog), &constants.fog },
};
emit_commands (taskctx->cmd, animation->pose1, animation->pose2,
pass ? skins : nullptr,
pass ? 5 : 2, push_constants,
iqm, taskctx, ent);
}
}
static void
@ -295,7 +307,7 @@ iqm_draw (const exprval_t **params, exprval_t *result, exprctx_t *ectx)
auto queue = r_ent_queue; //FIXME fetch from scene
for (size_t i = 0; i < queue->ent_queues[mod_iqm].size; i++) {
entity_t ent = queue->ent_queues[mod_iqm].a[i];
iqm_draw_ent (taskctx, ent, pass);
iqm_draw_ent (taskctx, ent, pass, shadow);
}
}