[vulkan] Implement forward translucent pipelines

This gets skies, liquids and particles working. I think it's only alias
and iqm lighting to go before forward is caught up to deferred.
This commit is contained in:
Bill Currie 2024-01-19 17:06:03 +09:00
parent 1e7cb8ee17
commit 58b42ed1b7
5 changed files with 191 additions and 8 deletions

View file

@ -364,6 +364,8 @@ lighting_planef_c = $(vkshaderpath)/lighting_plane.frag.spvc
lighting_h = $(vkshaderpath)/lighting.h lighting_h = $(vkshaderpath)/lighting.h
composef_src = $(vkshaderpath)/compose.frag composef_src = $(vkshaderpath)/compose.frag
composef_c = $(vkshaderpath)/compose.frag.spvc composef_c = $(vkshaderpath)/compose.frag.spvc
compose_fwdf_src = $(vkshaderpath)/compose_fwd.frag
compose_fwdf_c = $(vkshaderpath)/compose_fwd.frag.spvc
infplane = $(vkshaderpath)/infplane.finc infplane = $(vkshaderpath)/infplane.finc
oit_blend = $(vkshaderpath)/oit_blend.finc oit_blend = $(vkshaderpath)/oit_blend.finc
oit_store = $(vkshaderpath)/oit_store.finc oit_store = $(vkshaderpath)/oit_store.finc
@ -474,6 +476,8 @@ $(lighting_planef_c): $(lighting_planef_src) $(lighting_h) $(lighting_main)
$(composef_c): $(composef_src) $(oit_blend) $(oit_h) $(composef_c): $(composef_src) $(oit_blend) $(oit_h)
$(compose_fwdf_c): $(compose_fwdf_src) $(oit_blend) $(oit_h)
$(aliasv_c): $(aliasv_src) $(matrices_h) $(aliasv_c): $(aliasv_src) $(matrices_h)
$(alias_depth_c): $(alias_depth_src) $(matrices_h) $(alias_depth_c): $(alias_depth_src) $(matrices_h)
@ -545,6 +549,7 @@ vkshader_c = \
$(lighting_nonef_c) \ $(lighting_nonef_c) \
$(lighting_planef_c) \ $(lighting_planef_c) \
$(composef_c) \ $(composef_c) \
$(compose_fwdf_c) \
$(aliasv_c) \ $(aliasv_c) \
$(alias_depth_c) \ $(alias_depth_c) \
$(aliasf_c) \ $(aliasf_c) \
@ -644,6 +649,7 @@ EXTRA_DIST += \
$(lighting_planef_src) \ $(lighting_planef_src) \
$(lighting_h) \ $(lighting_h) \
$(composef_src) \ $(composef_src) \
$(compose_fwdf_src) \
$(aliasv_src) \ $(aliasv_src) \
$(aliasf_src) \ $(aliasf_src) \
$(alias_depth_src) \ $(alias_depth_src) \

View file

@ -52,6 +52,7 @@ properties = {
}; };
cube_image_base = { cube_image_base = {
@inherit = $image_base; @inherit = $image_base;
flags = cube_compatible;
extent = { extent = {
width = "min($render_output.extent.width,$render_output.extent.height)"; width = "min($render_output.extent.width,$render_output.extent.height)";
height = "min($render_output.extent.width,$render_output.extent.height)"; height = "min($render_output.extent.width,$render_output.extent.height)";
@ -579,7 +580,7 @@ properties = {
fragment = { fragment = {
stage = fragment; stage = fragment;
name = main; name = main;
module = $builtin/compose.frag; module = $builtin/compose_fwd.frag;
}; };
}; };
layout = { layout = {
@ -983,6 +984,10 @@ images = {
usage = depth_stencil_attachment|input_attachment|transient_attachment; usage = depth_stencil_attachment|input_attachment|transient_attachment;
}; };
color = { color = {
@inherit = $image_base;
format = r8g8b8a8_unorm;
};
output = {
@inherit = $image_base; @inherit = $image_base;
usage = color_attachment|input_attachment|sampled; usage = color_attachment|input_attachment|sampled;
format = $render_output.format; format = $render_output.format;
@ -993,6 +998,10 @@ images = {
usage = depth_stencil_attachment|input_attachment|transient_attachment; usage = depth_stencil_attachment|input_attachment|transient_attachment;
}; };
cube_color = { cube_color = {
@inherit = $cube_image_base;
format = $render_output.format;
};
cube_output = {
@inherit = $cube_image_base; @inherit = $cube_image_base;
flags = cube_compatible; flags = cube_compatible;
usage = color_attachment|input_attachment|sampled; usage = color_attachment|input_attachment|sampled;
@ -1012,6 +1021,11 @@ imageviews = {
image = color; image = color;
format = $images.color.format; format = $images.color.format;
}; };
output = {
@inherit = $view_base;
image = output;
format = $render_output.format;
};
cube_depth = { cube_depth = {
@inherit = $cube_view_base; @inherit = $cube_view_base;
image = cube_depth; image = cube_depth;
@ -1021,9 +1035,13 @@ imageviews = {
}; };
cube_color = { cube_color = {
@inherit = $cube_view_base; @inherit = $cube_view_base;
viewType = cube;
image = cube_color; image = cube_color;
}; };
cube_output = {
@inherit = $cube_view_base;
viewType = cube;
image = cube_output;
}
}; };
output = { output = {
view = $output; view = $output;
@ -1054,10 +1072,18 @@ renderpasses = {
finalLayout = $render_output.finalLayout; finalLayout = $render_output.finalLayout;
view = color; view = color;
}; };
output = {
@inherit = $attachment_base;
format = $render_output.format;
loadOp = clear;
storeOp = store;
finalLayout = $render_output.finalLayout;
view = output;
};
}; };
}; };
subpasses = { subpasses = {
color = { solid = {
color = "[ 0.3, 0.7, 0.3, 1]"; color = "[ 0.3, 0.7, 0.3, 1]";
attachments = { attachments = {
color = { color = {
@ -1082,8 +1108,6 @@ renderpasses = {
tasks = ( tasks = (
{ func = bsp_draw_queue; { func = bsp_draw_queue;
params = (main, solid, 1); }, params = (main, solid, 1); },
{ func = bsp_draw_queue;
params = (main, sky, 1); },
); );
stages = ( stages = (
@ -1141,13 +1165,127 @@ renderpasses = {
}; };
}; };
}; };
translucent = {
color = "[ 0.25, 0.25, 0.6, 1]";
dependencies = {
solid = $depth_dependency;
}; };
output = color; attachments = {
depth = {
depth = depth_stencil_read_only_optimal;
};
preserve = (color);
};
base_pipeline = {
@inherit = $pipeline_base;
rasterization = $cw_cull_back;
};
pipelines = {
bsp:skybox = {
color = $color.bsp;
tasks = (
// FIXME sky should not use OIT
{ func = bsp_draw_queue;
params = (main, sky, 1); },
);
stages = (
$brush.shader.quake_vertex,
$brush.shader.skybox_fragment,
);
vertexInput = $brush.vertexInput;
inputAssembly = $brush.inputAssembly;
layout = $brush.layout;
};
bsp:skysheet = {
color = $color.bsp;
tasks = (
// FIXME sky should not use OIT
{ func = bsp_draw_queue;
params = (main, sky, 1); },
);
stages = (
$brush.shader.quake_vertex,
$brush.shader.skysheet_fragment,
);
vertexInput = $brush.vertexInput;
inputAssembly = $brush.inputAssembly;
layout = $brush.layout;
};
bsp:trans = {
color = $color.bsp;
tasks = (
{ func = bsp_draw_queue;
params = (main, translucent, 1); },
{ func = bsp_draw_queue;
params = (main, turbulent, 1); },
);
stages = (
$brush.shader.quake_vertex,
$brush.shader.turb_fragment,
);
vertexInput = $brush.vertexInput;
inputAssembly = $brush.inputAssembly;
layout = $brush.layout;
};
particles:trans = {
color = $color.particles;
tasks = (
{ func = particles_draw; },
);
stages = (
$particle.shader.vertex,
$particle.shader.geometry,
$particle.shader.fragment,
);
vertexInput = $particle.vertexInput;
inputAssembly = $particle.inputAssembly;
layout = $particle.layout.draw;
};
};
};
compose = {
color = "[ 0.7, 0.3, 0.3, 1]";
dependencies = {
solid = $color_dependency;
translucent = $color_dependency;//FIXME is this right? no op
};
attachments = {
input = {
color = shader_read_only_optimal;
};
color = {
output = {
layout = color_attachment_optimal;
blend = $additive_blend;
};
};
preserve = (depth);
};
pipelines = {
compose = {
@inherit = $compose_base;
color = $color.compose;
tasks = (
{ func = compose_draw; },
);
stages = (
$fstriangle.shader.vertex,
$compose.shader.fragment,
);
layout = $compose.layout;
};
};
};
};
output = output;
}; };
forward_cube = { forward_cube = {
@inherit = $renderpasses.forward; @inherit = $renderpasses.forward;
@next = (VkRenderPassMultiviewCreateInfo, { @next = (VkRenderPassMultiviewCreateInfo, {
viewMasks = (0x3fu); viewMasks = (0x3fu, 0x3fu, 0x3fu);
}); });
framebuffer = { framebuffer = {
width = "min($render_output.extent.width,$render_output.extent.height)"; width = "min($render_output.extent.width,$render_output.extent.height)";
@ -1170,6 +1308,14 @@ renderpasses = {
finalLayout = $render_output.finalLayout; finalLayout = $render_output.finalLayout;
view = cube_color; view = cube_color;
}; };
output = {
@inherit = $attachment_base;
format = $images.cube_color.format;
loadOp = clear;
storeOp = store;
finalLayout = $render_output.finalLayout;
view = cube_output;
};
}; };
}; };
output = cube_color; output = cube_color;
@ -1335,6 +1481,8 @@ steps = {
params = ("\"main\""); }, params = ("\"main\""); },
{ func = update_framebuffer; { func = update_framebuffer;
params = ("\"main\""); }, params = ("\"main\""); },
{ func = clear_translucent;
params = ("\"main\""); },
{ func = particle_wait_physics; }, { func = particle_wait_physics; },
); );
}; };

View file

@ -115,6 +115,8 @@ static
static static
#include "libs/video/renderer/vulkan/shader/compose.frag.spvc" #include "libs/video/renderer/vulkan/shader/compose.frag.spvc"
static static
#include "libs/video/renderer/vulkan/shader/compose_fwd.frag.spvc"
static
#include "libs/video/renderer/vulkan/shader/alias.vert.spvc" #include "libs/video/renderer/vulkan/shader/alias.vert.spvc"
static static
#include "libs/video/renderer/vulkan/shader/alias_depth.vert.spvc" #include "libs/video/renderer/vulkan/shader/alias_depth.vert.spvc"
@ -194,6 +196,7 @@ static shaderdata_t builtin_shaders[] = {
{ "lighting_plane.frag", lighting_plane_frag, { "lighting_plane.frag", lighting_plane_frag,
sizeof (lighting_plane_frag) }, sizeof (lighting_plane_frag) },
{ "compose.frag", compose_frag, sizeof (compose_frag) }, { "compose.frag", compose_frag, sizeof (compose_frag) },
{ "compose_fwd.frag", compose_fwd_frag, sizeof (compose_fwd_frag) },
{ "alias.vert", alias_vert, sizeof (alias_vert) }, { "alias.vert", alias_vert, sizeof (alias_vert) },
{ "alias_depth.vert", alias_depth_vert, sizeof (alias_depth_vert) }, { "alias_depth.vert", alias_depth_vert, sizeof (alias_depth_vert) },
{ "alias.frag", alias_frag, sizeof (alias_frag) }, { "alias.frag", alias_frag, sizeof (alias_frag) },

View file

@ -0,0 +1,24 @@
#version 450
#extension GL_GOOGLE_include_directive : enable
#extension GL_EXT_multiview : enable
#define OIT_SET 1
#include "oit_blend.finc"
layout (input_attachment_index = 0, set = 0, binding = 0) uniform subpassInput color;
layout (location = 0) out vec4 frag_color;
void
main (void)
{
vec3 c;
vec3 l;
vec3 e;
vec3 o;
c = subpassLoad (color).rgb;
o = max(BlendFrags (vec4 (c, 1)).xyz, vec3(0));
o = pow (o, vec3(0.83));//FIXME make gamma correction configurable
frag_color = vec4 (o, 1);
}

View file

@ -85,8 +85,10 @@ compose_draw (const exprval_t **params, exprval_t *result, exprctx_t *ectx)
cframe->imageInfo[0].imageView = fb->views[QFV_attachColor]; cframe->imageInfo[0].imageView = fb->views[QFV_attachColor];
cframe->imageInfo[1].imageView = fb->views[QFV_attachLight]; cframe->imageInfo[1].imageView = fb->views[QFV_attachLight];
cframe->imageInfo[2].imageView = fb->views[QFV_attachEmission]; cframe->imageInfo[2].imageView = fb->views[QFV_attachEmission];
dfunc->vkUpdateDescriptorSets (device->dev, COMPOSE_IMAGE_INFOS, dfunc->vkUpdateDescriptorSets (device->dev, 1,
cframe->descriptors, 0, 0); cframe->descriptors, 0, 0);
//dfunc->vkUpdateDescriptorSets (device->dev, COMPOSE_IMAGE_INFOS,
// cframe->descriptors, 0, 0);
VkDescriptorSet sets[] = { VkDescriptorSet sets[] = {
cframe->descriptors[0].dstSet, cframe->descriptors[0].dstSet,