mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2024-11-10 15:22:04 +00:00
[vulkan] Start work on shadows
This gets the shaders needed for creating shadow maps, and the changes to the lighting pipeline for binding the shadow maps, but no generation or reading is done yet. It feels like parts of various systems are getting a little big for their britches and I need to do an audit of various things.
This commit is contained in:
parent
c29e9828b6
commit
8c03ed8be5
11 changed files with 389 additions and 44 deletions
|
@ -35,6 +35,7 @@
|
|||
#include "QF/modelgen.h"
|
||||
#include "QF/Vulkan/qf_vid.h"
|
||||
#include "QF/Vulkan/command.h"
|
||||
#include "QF/simd/types.h"
|
||||
|
||||
typedef struct qfv_light_s {
|
||||
vec3_t color;
|
||||
|
@ -53,21 +54,35 @@ typedef struct qfv_lightvisset_s DARRAY_TYPE (byte) qfv_lightvisset_t;
|
|||
#define NUM_STYLES 64
|
||||
|
||||
typedef struct qfv_light_buffer_s {
|
||||
float intensity[NUM_STYLES + 3];
|
||||
float intensity[NUM_STYLES + 4];
|
||||
int cascadeCount;
|
||||
int planeCount;
|
||||
int cubeCount;
|
||||
int lightCount;
|
||||
qfv_light_t lights[NUM_LIGHTS] __attribute__((aligned(16)));
|
||||
mat4f_t shadowMat[NUM_LIGHTS];
|
||||
vec4f_t shadowCascade[NUM_LIGHTS];
|
||||
} qfv_light_buffer_t;
|
||||
|
||||
#define LIGHTING_BUFFER_INFOS 1
|
||||
#define LIGHTING_IMAGE_INFOS 5
|
||||
#define LIGHTING_ATTACH_INFOS 5
|
||||
#define LIGHTING_SHADOW_INFOS NUM_LIGHTS
|
||||
#define LIGHTING_DESCRIPTORS (LIGHTING_BUFFER_INFOS + LIGHTING_ATTACH_INFOS + 1)
|
||||
|
||||
typedef struct lightingframe_s {
|
||||
VkCommandBuffer cmd;
|
||||
VkBuffer light_buffer;
|
||||
VkDescriptorBufferInfo bufferInfo[LIGHTING_BUFFER_INFOS];
|
||||
VkDescriptorImageInfo imageInfo[LIGHTING_IMAGE_INFOS];
|
||||
VkWriteDescriptorSet descriptors[LIGHTING_BUFFER_INFOS
|
||||
+ LIGHTING_IMAGE_INFOS];
|
||||
VkDescriptorImageInfo attachInfo[LIGHTING_ATTACH_INFOS];
|
||||
VkDescriptorImageInfo shadowInfo[LIGHTING_SHADOW_INFOS];
|
||||
union {
|
||||
VkWriteDescriptorSet descriptors[LIGHTING_DESCRIPTORS];
|
||||
struct {
|
||||
VkWriteDescriptorSet bufferWrite[LIGHTING_BUFFER_INFOS];
|
||||
VkWriteDescriptorSet attachWrite[LIGHTING_ATTACH_INFOS];
|
||||
VkWriteDescriptorSet shadowWrite;
|
||||
};
|
||||
};
|
||||
// A fat PVS of leafs visible from visible leafs so hidden lights can
|
||||
// illuminate the leafs visible to the player
|
||||
byte pvs[MAP_PVS_BYTES];
|
||||
|
@ -82,6 +97,7 @@ typedef struct lightingctx_s {
|
|||
lightingframeset_t frames;
|
||||
VkPipeline pipeline;
|
||||
VkPipelineLayout layout;
|
||||
VkSampler sampler;
|
||||
VkDeviceMemory light_memory;
|
||||
qfv_lightset_t lights;
|
||||
qfv_lightleafset_t lightleafs;
|
||||
|
|
|
@ -169,8 +169,7 @@ Mod_LeafPVS_set (const mleaf_t *leaf, const model_t *model, byte defvis,
|
|||
memset (out, defvis, sizeof (mod_novis));
|
||||
return;
|
||||
}
|
||||
return Mod_DecompressVis_set (leaf->compressed_vis, &model->brush, defvis,
|
||||
out);
|
||||
Mod_DecompressVis_set (leaf->compressed_vis, &model->brush, defvis, out);
|
||||
}
|
||||
|
||||
VISIBLE void
|
||||
|
@ -183,8 +182,7 @@ Mod_LeafPVS_mix (const mleaf_t *leaf, const model_t *model, byte defvis,
|
|||
}
|
||||
return;
|
||||
}
|
||||
return Mod_DecompressVis_mix (leaf->compressed_vis, &model->brush, defvis,
|
||||
out);
|
||||
Mod_DecompressVis_mix (leaf->compressed_vis, &model->brush, defvis, out);
|
||||
}
|
||||
|
||||
// BRUSHMODEL LOADING =========================================================
|
||||
|
|
|
@ -311,6 +311,8 @@ bsp_gbufg_src = $(vkshaderpath)/bsp_gbuf.geom
|
|||
bsp_gbufg_c = $(vkshaderpath)/bsp_gbuf.geom.spvc
|
||||
bsp_gbuff_src = $(vkshaderpath)/bsp_gbuf.frag
|
||||
bsp_gbuff_c = $(vkshaderpath)/bsp_gbuf.frag.spvc
|
||||
bsp_shadow_src = $(vkshaderpath)/bsp_shadow.vert
|
||||
bsp_shadow_c = $(vkshaderpath)/bsp_shadow.vert.spvc
|
||||
bsp_skyf_src = $(vkshaderpath)/bsp_sky.frag
|
||||
bsp_skyf_c = $(vkshaderpath)/bsp_sky.frag.spvc
|
||||
bsp_turbf_src = $(vkshaderpath)/bsp_turb.frag
|
||||
|
@ -327,10 +329,14 @@ 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
|
||||
alias_shadow_src = $(vkshaderpath)/alias_shadow.vert
|
||||
alias_shadow_c = $(vkshaderpath)/alias_shadow.vert.spvc
|
||||
passthrough_src = $(vkshaderpath)/passthrough.vert
|
||||
passthrough_c = $(vkshaderpath)/passthrough.vert.spvc
|
||||
pushcolor_src = $(vkshaderpath)/pushcolor.frag
|
||||
pushcolor_c = $(vkshaderpath)/pushcolor.frag.spvc
|
||||
shadow_src = $(vkshaderpath)/shadow.geom
|
||||
shadow_c = $(vkshaderpath)/shadow.geom.spvc
|
||||
|
||||
$(twodv_c): $(twodv_src)
|
||||
|
||||
|
@ -348,6 +354,8 @@ $(bsp_gbufg_c): $(bsp_gbufg_src)
|
|||
|
||||
$(bsp_gbuff_c): $(bsp_gbuff_src)
|
||||
|
||||
$(bsp_shadow_c): $(bsp_shadow_src)
|
||||
|
||||
$(bsp_skyf_c): $(bsp_skyf_src)
|
||||
|
||||
$(bsp_turbf_c): $(bsp_turbf_src)
|
||||
|
@ -364,10 +372,14 @@ $(aliasf_c): $(aliasf_src)
|
|||
|
||||
$(alias_gbuf_c): $(alias_gbuf_src)
|
||||
|
||||
$(alias_shadow_c): $(alias_shadow_src)
|
||||
|
||||
$(passthrough_c): $(passthrough_src)
|
||||
|
||||
$(pushcolor_c): $(pushcolor_src)
|
||||
|
||||
$(shadow_c): $(shadow_src)
|
||||
|
||||
vkshader_c = \
|
||||
$(twodv_c) \
|
||||
$(twodf_c) \
|
||||
|
@ -377,6 +389,7 @@ vkshader_c = \
|
|||
$(bsp_gbufv_c) \
|
||||
$(bsp_gbufg_c) \
|
||||
$(bsp_gbuff_c) \
|
||||
$(bsp_shadow_c) \
|
||||
$(bsp_skyf_c) \
|
||||
$(bsp_turbf_c) \
|
||||
$(lightingf_c) \
|
||||
|
@ -385,8 +398,10 @@ vkshader_c = \
|
|||
$(alias_depth_c) \
|
||||
$(aliasf_c) \
|
||||
$(alias_gbuf_c) \
|
||||
$(alias_shadow_c) \
|
||||
$(passthrough_c) \
|
||||
$(pushcolor_c)
|
||||
$(pushcolor_c) \
|
||||
$(shadow_c)
|
||||
|
||||
V_VKGEN = $(V_VKGEN_@AM_V@)
|
||||
V_VKGEN_ = $(V_VKGEN_@AM_DEFAULT_V@)
|
||||
|
@ -427,10 +442,12 @@ EXTRA_DIST += \
|
|||
libs/video/renderer/vulkan/shader/alias.vert \
|
||||
libs/video/renderer/vulkan/shader/alias_depth.vert \
|
||||
libs/video/renderer/vulkan/shader/alias_gbuf.frag \
|
||||
libs/video/renderer/vulkan/shader/alias_shadow.frag \
|
||||
libs/video/renderer/vulkan/shader/bsp_depth.vert \
|
||||
libs/video/renderer/vulkan/shader/bsp_gbuf.frag \
|
||||
libs/video/renderer/vulkan/shader/bsp_gbuf.geom \
|
||||
libs/video/renderer/vulkan/shader/bsp_gbuf.vert \
|
||||
libs/video/renderer/vulkan/shader/bsp_shadow.vert \
|
||||
libs/video/renderer/vulkan/shader/bsp_sky.frag \
|
||||
libs/video/renderer/vulkan/shader/bsp_turb.frag \
|
||||
libs/video/renderer/vulkan/shader/compose.frag \
|
||||
|
@ -439,5 +456,6 @@ EXTRA_DIST += \
|
|||
libs/video/renderer/vulkan/shader/pushcolor.frag \
|
||||
libs/video/renderer/vulkan/shader/quakebsp.frag \
|
||||
libs/video/renderer/vulkan/shader/quakebsp.vert \
|
||||
libs/video/renderer/vulkan/shader/shadow.geom \
|
||||
libs/video/renderer/vulkan/shader/twod.frag \
|
||||
libs/video/renderer/vulkan/shader/twod.vert
|
||||
|
|
|
@ -51,6 +51,23 @@
|
|||
borderColor = float_transparent_black;
|
||||
unnormalizedCoordinates = false;
|
||||
};
|
||||
shadow_sampler = {
|
||||
magFilter = linear;
|
||||
minFilter = linear;
|
||||
mipmapMode = linear;
|
||||
addressModeU = clamp_to_edge;
|
||||
addressModeV = clamp_to_edge;
|
||||
addressModeW = clamp_to_edge;
|
||||
mipLodBias = 0;
|
||||
anisotropyEnable = false;
|
||||
maxAnisotropy = 0;
|
||||
compareEnable = true;
|
||||
compareOp = greater_or_equal;
|
||||
minLod = 0;
|
||||
maxLod = 1000;
|
||||
borderColor = float_transparent_black;
|
||||
unnormalizedCoordinates = false;
|
||||
};
|
||||
};
|
||||
descriptorPools = {
|
||||
twod_pool = {
|
||||
|
@ -97,6 +114,16 @@
|
|||
},
|
||||
);
|
||||
};
|
||||
lighting_shadow_pool = {
|
||||
flags = 0;
|
||||
maxSets = $frames.size;
|
||||
bindings = (
|
||||
{
|
||||
type = combined_image_sampler;
|
||||
descriptorCount = "$frames.size * 256z";
|
||||
},
|
||||
);
|
||||
};
|
||||
compose_attach_pool = {
|
||||
flags = 0;
|
||||
maxSets = $frames.size;
|
||||
|
@ -276,6 +303,16 @@
|
|||
},
|
||||
);
|
||||
};
|
||||
lighting_shadow = {
|
||||
bindings = (
|
||||
{
|
||||
binding = 0;
|
||||
descriptorType = combined_image_sampler;
|
||||
descriptorCount = 256;
|
||||
stageFlags = fragment;
|
||||
},
|
||||
);
|
||||
};
|
||||
compose_attach = {
|
||||
bindings = (
|
||||
{
|
||||
|
@ -329,7 +366,7 @@
|
|||
);
|
||||
};
|
||||
lighting_layout = {
|
||||
setLayouts = (lighting_attach, lighting_lights);
|
||||
setLayouts = (lighting_attach, lighting_lights, lighting_shadow);
|
||||
};
|
||||
compose_layout = {
|
||||
setLayouts = (compose_attach);
|
||||
|
@ -499,6 +536,67 @@
|
|||
};
|
||||
|
||||
pipelines = {
|
||||
alias_shadow = {
|
||||
subpass = 0;
|
||||
stages = (
|
||||
{
|
||||
stage = vertex;
|
||||
name = main;
|
||||
module = $builtin/alias_shadow.vert;
|
||||
},
|
||||
);
|
||||
vertexInput = {
|
||||
bindings = (
|
||||
"$properties.vertexInput.alias.bindings[0]",
|
||||
"$properties.vertexInput.alias.bindings[1]",
|
||||
);
|
||||
attributes = (
|
||||
"$properties.vertexInput.alias.attributes[0]",
|
||||
"$properties.vertexInput.alias.attributes[1]",
|
||||
"$properties.vertexInput.alias.attributes[2]",
|
||||
"$properties.vertexInput.alias.attributes[3]",
|
||||
);
|
||||
};
|
||||
inputAssembly = $properties.inputAssembly.alias;
|
||||
viewport = $properties.viewport;
|
||||
rasterization = $properties.rasterization.cw_cull_back;
|
||||
multisample = $properties.multisample;
|
||||
depthStencil = $properties.depthStencil.test_and_write;
|
||||
colorBlend = $properties.pipelines.alias_gbuf.colorBlend;
|
||||
dynamic = {
|
||||
dynamicState = ( viewport, scissor );
|
||||
};
|
||||
layout = alias_layout;
|
||||
};
|
||||
bsp_shadow = {
|
||||
subpass = 0;
|
||||
stages = (
|
||||
{
|
||||
stage = vertex;
|
||||
name = main;
|
||||
module = $builtin/bsp_shadow.vert;
|
||||
},
|
||||
);
|
||||
vertexInput = {
|
||||
bindings = (
|
||||
"$properties.vertexInput.brush.bindings[0]",
|
||||
);
|
||||
attributes = (
|
||||
"$properties.vertexInput.brush.attributes[0]",
|
||||
);
|
||||
};
|
||||
inputAssembly = $properties.inputAssembly.brush;
|
||||
viewport = $properties.viewport;
|
||||
rasterization = $properties.rasterization.cw_cull_back;
|
||||
multisample = $properties.multisample;
|
||||
depthStencil = $properties.depthStencil.test_and_write;
|
||||
colorBlend = $properties.pipelines.bsp_gbuf.colorBlend;
|
||||
dynamic = {
|
||||
dynamicState = ( viewport, scissor );
|
||||
};
|
||||
layout = quakebsp_layout;
|
||||
//renderPass = renderpass;
|
||||
};
|
||||
alias_depth = {
|
||||
subpass = 0;
|
||||
stages = (
|
||||
|
@ -805,12 +903,6 @@
|
|||
stage = fragment;
|
||||
name = main;
|
||||
module = $builtin/lighting.frag;
|
||||
specializationInfo = {
|
||||
mapEntries = (
|
||||
{ size = 4; offset = 0; constantID = 0; },
|
||||
);
|
||||
data = <00000100>;
|
||||
};
|
||||
},
|
||||
);
|
||||
vertexInput = $properties.fsquad.vertexInput;
|
||||
|
|
|
@ -71,6 +71,8 @@ static
|
|||
static
|
||||
#include "libs/video/renderer/vulkan/shader/bsp_gbuf.frag.spvc"
|
||||
static
|
||||
#include "libs/video/renderer/vulkan/shader/bsp_shadow.vert.spvc"
|
||||
static
|
||||
#include "libs/video/renderer/vulkan/shader/bsp_sky.frag.spvc"
|
||||
static
|
||||
#include "libs/video/renderer/vulkan/shader/bsp_turb.frag.spvc"
|
||||
|
@ -87,9 +89,13 @@ static
|
|||
static
|
||||
#include "libs/video/renderer/vulkan/shader/alias_gbuf.frag.spvc"
|
||||
static
|
||||
#include "libs/video/renderer/vulkan/shader/alias_shadow.vert.spvc"
|
||||
static
|
||||
#include "libs/video/renderer/vulkan/shader/passthrough.vert.spvc"
|
||||
static
|
||||
#include "libs/video/renderer/vulkan/shader/pushcolor.frag.spvc"
|
||||
static
|
||||
#include "libs/video/renderer/vulkan/shader/shadow.geom.spvc"
|
||||
|
||||
typedef struct shaderdata_s {
|
||||
const char *name;
|
||||
|
@ -106,6 +112,7 @@ static shaderdata_t builtin_shaders[] = {
|
|||
{ "bsp_gbuf.vert", bsp_gbuf_vert, sizeof (bsp_gbuf_vert) },
|
||||
{ "bsp_gbuf.geom", bsp_gbuf_geom, sizeof (bsp_gbuf_geom) },
|
||||
{ "bsp_gbuf.frag", bsp_gbuf_frag, sizeof (bsp_gbuf_frag) },
|
||||
{ "bsp_shadow.vert", bsp_shadow_vert, sizeof (bsp_shadow_vert) },
|
||||
{ "bsp_sky.frag", bsp_sky_frag, sizeof (bsp_sky_frag) },
|
||||
{ "bsp_turb.frag", bsp_turb_frag, sizeof (bsp_turb_frag) },
|
||||
{ "lighting.frag", lighting_frag, sizeof (lighting_frag) },
|
||||
|
@ -114,8 +121,10 @@ static shaderdata_t builtin_shaders[] = {
|
|||
{ "alias_depth.vert", alias_depth_vert, sizeof (alias_depth_vert) },
|
||||
{ "alias.frag", alias_frag, sizeof (alias_frag) },
|
||||
{ "alias_gbuf.frag", alias_gbuf_frag, sizeof (alias_gbuf_frag) },
|
||||
{ "alias_shadow.vert", alias_shadow_vert, sizeof (alias_shadow_vert) },
|
||||
{ "passthrough.vert", passthrough_vert, sizeof (passthrough_vert) },
|
||||
{ "pushcolor.frag", pushcolor_frag, sizeof (pushcolor_frag) },
|
||||
{ "shadow.geom", shadow_geom, sizeof (shadow_geom) },
|
||||
{}
|
||||
};
|
||||
|
||||
|
|
23
libs/video/renderer/vulkan/shader/alias_shadow.vert
Normal file
23
libs/video/renderer/vulkan/shader/alias_shadow.vert
Normal file
|
@ -0,0 +1,23 @@
|
|||
#version 450
|
||||
|
||||
layout (push_constant) uniform PushConstants {
|
||||
mat4 Model;
|
||||
float blend;
|
||||
};
|
||||
|
||||
layout (location = 0) in vec4 vertexa;
|
||||
layout (location = 1) in vec3 normala;
|
||||
layout (location = 2) in vec4 vertexb;
|
||||
layout (location = 3) in vec3 normalb;
|
||||
|
||||
layout (location = 0) out int InstanceIndex;
|
||||
|
||||
void
|
||||
main (void)
|
||||
{
|
||||
vec4 vertex;
|
||||
|
||||
vertex = mix (vertexa, vertexb, blend);
|
||||
gl_Position = Model * vertex;
|
||||
InstanceIndex = gl_InstanceIndex;
|
||||
}
|
16
libs/video/renderer/vulkan/shader/bsp_shadow.vert
Normal file
16
libs/video/renderer/vulkan/shader/bsp_shadow.vert
Normal file
|
@ -0,0 +1,16 @@
|
|||
#version 450
|
||||
|
||||
layout (push_constant) uniform PushConstants {
|
||||
mat4 Model;
|
||||
};
|
||||
|
||||
layout (location = 0) in vec4 vertex;
|
||||
|
||||
layout (location = 0) out int InstanceIndex;
|
||||
|
||||
void
|
||||
main (void)
|
||||
{
|
||||
gl_Position = Model * vertex;
|
||||
InstanceIndex = gl_InstanceIndex;
|
||||
}
|
|
@ -15,12 +15,18 @@ struct LightData {
|
|||
float cone;
|
||||
};
|
||||
|
||||
layout (constant_id = 0) const int MaxLights = 128;
|
||||
#define MaxLights 256
|
||||
|
||||
layout (set = 2, binding = 0) uniform sampler2DArrayShadow shadowCascade[MaxLights];
|
||||
layout (set = 2, binding = 0) uniform sampler2DShadow shadowPlane[MaxLights];
|
||||
layout (set = 2, binding = 0) uniform samplerCubeShadow shadowCube[MaxLights];
|
||||
|
||||
layout (set = 1, binding = 0) uniform Lights {
|
||||
vec4 intensity[16]; // 64 floats
|
||||
vec3 intensity2;
|
||||
int lightCount;
|
||||
vec4 intensity[17]; // 68 floats
|
||||
ivec4 lightCounts;
|
||||
LightData lights[MaxLights];
|
||||
mat4 shadowMat[MaxLights];
|
||||
vec4 shadowCascale[MaxLights];
|
||||
};
|
||||
|
||||
layout (location = 0) out vec4 frag_color;
|
||||
|
@ -48,6 +54,24 @@ calc_light (LightData light, vec3 position, vec3 normal)
|
|||
return light.color * i * (r - d);
|
||||
}
|
||||
|
||||
vec3
|
||||
shadow_cascade (sampler2DArrayShadow map)
|
||||
{
|
||||
return vec3(1);
|
||||
}
|
||||
|
||||
vec3
|
||||
shadow_plane (sampler2DShadow map)
|
||||
{
|
||||
return vec3(1);
|
||||
}
|
||||
|
||||
vec3
|
||||
shadow_cube (samplerCubeShadow map)
|
||||
{
|
||||
return vec3(1);
|
||||
}
|
||||
|
||||
void
|
||||
main (void)
|
||||
{
|
||||
|
@ -59,8 +83,22 @@ main (void)
|
|||
vec3 light = vec3 (0);
|
||||
|
||||
if (MaxLights > 0) {
|
||||
for (int i = 0; i < lightCount; i++) {
|
||||
int i = 0;
|
||||
while (i < lightCounts.x) {
|
||||
shadow_cascade (shadowCascade[i]);
|
||||
i++;
|
||||
}
|
||||
while (i < lightCounts.y) {
|
||||
shadow_plane (shadowPlane[i]);
|
||||
i++;
|
||||
}
|
||||
while (i < lightCounts.z) {
|
||||
shadow_cube (shadowCube[i]);
|
||||
i++;
|
||||
}
|
||||
while (i < lightCounts.w) {
|
||||
light += calc_light (lights[i], p, n);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
frag_color = vec4 (c * light + e, 1);
|
||||
|
|
25
libs/video/renderer/vulkan/shader/shadow.geom
Normal file
25
libs/video/renderer/vulkan/shader/shadow.geom
Normal file
|
@ -0,0 +1,25 @@
|
|||
#version 450
|
||||
|
||||
layout (triangles) in;
|
||||
layout (triangle_strip, max_vertices = 3) out;
|
||||
|
||||
layout (constant_id = 0) const int MaxLights = 128;
|
||||
|
||||
layout (set = 0, binding = 0) uniform UBO {
|
||||
mat4 vp[MaxLights];
|
||||
} ubo;
|
||||
|
||||
layout (location = 0) in int InstanceIndex[];
|
||||
|
||||
void
|
||||
main (void)
|
||||
{
|
||||
int index = InstanceIndex[0];
|
||||
|
||||
for (int i = 0; i < gl_in.length(); i++) {
|
||||
gl_Layer = index;
|
||||
gl_Position = ubo.vp[index] * gl_in[i].gl_Position;
|
||||
EmitVertex();
|
||||
}
|
||||
EndPrimitive();
|
||||
}
|
71
libs/video/renderer/vulkan/shadow.plist
Normal file
71
libs/video/renderer/vulkan/shadow.plist
Normal file
|
@ -0,0 +1,71 @@
|
|||
{
|
||||
images = {
|
||||
shadow = {
|
||||
flags = cube_compatible;
|
||||
imageType = VK_IMAGE_TYPE_2D; //FIXME short form is 2d...
|
||||
format = x8_d24_unorm_pack32;
|
||||
samples = 1;
|
||||
extent = {
|
||||
width = 256; // FIXME config
|
||||
height = 256; // FIXME config
|
||||
depth = 1;
|
||||
};
|
||||
mipLevels = 1;
|
||||
arrayLayers = 2048; // FIXME config
|
||||
tiling = optimal;
|
||||
usage = depth_stencil_attachment|sampled;
|
||||
initialLayout = undefined;
|
||||
};
|
||||
};
|
||||
imageViews = {
|
||||
shadow = {
|
||||
image = depth;
|
||||
viewType = VK_IMAGE_VIEW_TYPE_2D_ARRAY;
|
||||
format = $properties.images.shadow.format;
|
||||
components = {
|
||||
r = identity;
|
||||
g = identity;
|
||||
b = identity;
|
||||
a = identity;
|
||||
};
|
||||
subresourceRange = {
|
||||
aspectMask = depth;
|
||||
levelCount = 1;
|
||||
layerCount = $properties.images.shadow.arrayLayers;
|
||||
};
|
||||
};
|
||||
};
|
||||
framebuffer = {
|
||||
renderPass = $properties.renderpass;
|
||||
attachments = (shadown);
|
||||
width = $properties.images.shadow.extent.width;
|
||||
height = $properties.images.shadow.extent.height;
|
||||
layers = $properties.images.shadow.arrayLayers;
|
||||
};
|
||||
clearValues = (
|
||||
{ depthStencil = { depth = 1; stencil = 0; }; },
|
||||
);
|
||||
renderpass = {
|
||||
attachments = (
|
||||
{
|
||||
format = $properties.images.depth.format;
|
||||
samples = 1;
|
||||
loadOp = dont_care;
|
||||
storeOp = store;
|
||||
stencilLoadOp = dont_care;
|
||||
stencilStoreOp = dont_care;
|
||||
initialLayout = undefined;
|
||||
finalLayout = shader_read_only_optimal;
|
||||
},
|
||||
);
|
||||
subpasses = (
|
||||
{ // 0 depth
|
||||
pipelineBindPoint = graphics;
|
||||
depthStencilAttachment = {
|
||||
attachment = 0;
|
||||
layout = depth_stencil_attachment_optimal;
|
||||
};
|
||||
}
|
||||
);
|
||||
};
|
||||
}
|
|
@ -49,6 +49,7 @@
|
|||
#include "QF/va.h"
|
||||
|
||||
#include "QF/Vulkan/qf_lighting.h"
|
||||
#include "QF/Vulkan/qf_texture.h"
|
||||
#include "QF/Vulkan/buffer.h"
|
||||
#include "QF/Vulkan/debug.h"
|
||||
#include "QF/Vulkan/descriptor.h"
|
||||
|
@ -128,7 +129,11 @@ update_lights (vulkan_ctx_t *ctx)
|
|||
light_data->intensity[64] = 1 / 16.0;
|
||||
light_data->intensity[65] = 1 / 16.0;
|
||||
light_data->intensity[66] = 1 / 16.0;
|
||||
light_data->intensity[67] = 1 / 16.0;
|
||||
|
||||
light_data->cascadeCount = 0;
|
||||
light_data->planeCount = 0;
|
||||
light_data->cubeCount = 0;
|
||||
light_data->lightCount = 0;
|
||||
R_FindNearLights (r_origin, NUM_LIGHTS - 1, lights);
|
||||
for (int i = 0; i < NUM_LIGHTS - 1; i++) {
|
||||
|
@ -213,24 +218,25 @@ Vulkan_Lighting_Draw (vulkan_ctx_t *ctx)
|
|||
lctx->pipeline);
|
||||
|
||||
lframe->bufferInfo[0].buffer = lframe->light_buffer;
|
||||
lframe->imageInfo[0].imageView = ctx->attachment_views->a[QFV_attachDepth];
|
||||
lframe->imageInfo[1].imageView = ctx->attachment_views->a[QFV_attachColor];
|
||||
lframe->imageInfo[2].imageView
|
||||
lframe->attachInfo[0].imageView = ctx->attachment_views->a[QFV_attachDepth];
|
||||
lframe->attachInfo[1].imageView = ctx->attachment_views->a[QFV_attachColor];
|
||||
lframe->attachInfo[2].imageView
|
||||
= ctx->attachment_views->a[QFV_attachEmission];
|
||||
lframe->imageInfo[3].imageView
|
||||
lframe->attachInfo[3].imageView
|
||||
= ctx->attachment_views->a[QFV_attachNormal];
|
||||
lframe->imageInfo[4].imageView
|
||||
lframe->attachInfo[4].imageView
|
||||
= ctx->attachment_views->a[QFV_attachPosition];
|
||||
dfunc->vkUpdateDescriptorSets (device->dev,
|
||||
LIGHTING_BUFFER_INFOS + LIGHTING_IMAGE_INFOS,
|
||||
LIGHTING_DESCRIPTORS,
|
||||
lframe->descriptors, 0, 0);
|
||||
|
||||
VkDescriptorSet sets[] = {
|
||||
lframe->descriptors[1].dstSet,
|
||||
lframe->descriptors[0].dstSet,
|
||||
lframe->attachWrite[0].dstSet,
|
||||
lframe->bufferWrite[0].dstSet,
|
||||
lframe->shadowWrite.dstSet,
|
||||
};
|
||||
dfunc->vkCmdBindDescriptorSets (cmd, VK_PIPELINE_BIND_POINT_GRAPHICS,
|
||||
lctx->layout, 0, 2, sets, 0, 0);
|
||||
lctx->layout, 0, 3, sets, 0, 0);
|
||||
|
||||
dfunc->vkCmdSetViewport (cmd, 0, 1, &ctx->viewport);
|
||||
dfunc->vkCmdSetScissor (cmd, 0, 1, &ctx->scissor);
|
||||
|
@ -255,12 +261,18 @@ static VkWriteDescriptorSet base_buffer_write = {
|
|||
VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
|
||||
0, 0, 0
|
||||
};
|
||||
static VkWriteDescriptorSet base_image_write = {
|
||||
static VkWriteDescriptorSet base_attachment_write = {
|
||||
VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET, 0, 0,
|
||||
0, 0, 1,
|
||||
VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT,
|
||||
0, 0, 0
|
||||
};
|
||||
static VkWriteDescriptorSet base_image_write = {
|
||||
VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET, 0, 0,
|
||||
0, 0, 1,
|
||||
VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,
|
||||
0, 0, 0
|
||||
};
|
||||
|
||||
void
|
||||
Vulkan_Lighting_Init (vulkan_ctx_t *ctx)
|
||||
|
@ -281,6 +293,7 @@ Vulkan_Lighting_Init (vulkan_ctx_t *ctx)
|
|||
|
||||
lctx->pipeline = Vulkan_CreatePipeline (ctx, "lighting");
|
||||
lctx->layout = Vulkan_CreatePipelineLayout (ctx, "lighting_layout");
|
||||
lctx->sampler = Vulkan_CreateSampler (ctx, "shadow_sampler");
|
||||
|
||||
__auto_type lbuffers = QFV_AllocBufferSet (frames, alloca);
|
||||
for (size_t i = 0; i < frames; i++) {
|
||||
|
@ -305,24 +318,41 @@ Vulkan_Lighting_Init (vulkan_ctx_t *ctx)
|
|||
|
||||
__auto_type attach = QFV_AllocDescriptorSetLayoutSet (frames, alloca);
|
||||
__auto_type lights = QFV_AllocDescriptorSetLayoutSet (frames, alloca);
|
||||
__auto_type shadow = QFV_AllocDescriptorSetLayoutSet (frames, alloca);
|
||||
for (size_t i = 0; i < frames; i++) {
|
||||
attach->a[i] = Vulkan_CreateDescriptorSetLayout (ctx,
|
||||
"lighting_attach");
|
||||
lights->a[i] = Vulkan_CreateDescriptorSetLayout (ctx,
|
||||
"lighting_lights");
|
||||
shadow->a[i] = Vulkan_CreateDescriptorSetLayout (ctx,
|
||||
"lighting_shadow");
|
||||
}
|
||||
__auto_type attach_pool = Vulkan_CreateDescriptorPool (ctx,
|
||||
"lighting_attach_pool");
|
||||
__auto_type lights_pool = Vulkan_CreateDescriptorPool (ctx,
|
||||
"lighting_lights_pool");
|
||||
__auto_type shadow_pool = Vulkan_CreateDescriptorPool (ctx,
|
||||
"lighting_shadow_pool");
|
||||
|
||||
__auto_type attach_set = QFV_AllocateDescriptorSet (device, attach_pool,
|
||||
attach);
|
||||
__auto_type lights_set = QFV_AllocateDescriptorSet (device, lights_pool,
|
||||
lights);
|
||||
__auto_type shadow_set = QFV_AllocateDescriptorSet (device, shadow_pool,
|
||||
shadow);
|
||||
for (size_t i = 0; i < frames; i++) {
|
||||
__auto_type lframe = &lctx->frames.a[i];
|
||||
|
||||
QFV_duSetObjectName (device, VK_OBJECT_TYPE_DESCRIPTOR_SET,
|
||||
attach_set->a[i],
|
||||
va (ctx->va_ctx, "lighting:attach_set:%zd", i));
|
||||
QFV_duSetObjectName (device, VK_OBJECT_TYPE_DESCRIPTOR_SET,
|
||||
lights_set->a[i],
|
||||
va (ctx->va_ctx, "lighting:lights_set:%zd", i));
|
||||
QFV_duSetObjectName (device, VK_OBJECT_TYPE_DESCRIPTOR_SET,
|
||||
shadow_set->a[i],
|
||||
va (ctx->va_ctx, "lighting:shadow_set:%zd", i));
|
||||
|
||||
DARRAY_INIT (&lframe->lightvis, 16);
|
||||
lframe->leaf = 0;
|
||||
|
||||
|
@ -337,20 +367,29 @@ Vulkan_Lighting_Init (vulkan_ctx_t *ctx)
|
|||
lframe->cmd, "cmd:lighting");
|
||||
for (int j = 0; j < LIGHTING_BUFFER_INFOS; j++) {
|
||||
lframe->bufferInfo[j] = base_buffer_info;
|
||||
lframe->descriptors[j] = base_buffer_write;
|
||||
lframe->descriptors[j].dstSet = lights_set->a[i];
|
||||
lframe->descriptors[j].dstBinding = j;
|
||||
lframe->descriptors[j].pBufferInfo = &lframe->bufferInfo[j];
|
||||
lframe->bufferWrite[j] = base_buffer_write;
|
||||
lframe->bufferWrite[j].dstSet = lights_set->a[i];
|
||||
lframe->bufferWrite[j].dstBinding = j;
|
||||
lframe->bufferWrite[j].pBufferInfo = &lframe->bufferInfo[j];
|
||||
}
|
||||
for (int j = 0; j < LIGHTING_IMAGE_INFOS; j++) {
|
||||
lframe->imageInfo[j] = base_image_info;
|
||||
lframe->imageInfo[j].sampler = 0;
|
||||
int k = j + LIGHTING_BUFFER_INFOS;
|
||||
lframe->descriptors[k] = base_image_write;
|
||||
lframe->descriptors[k].dstSet = attach_set->a[i];
|
||||
lframe->descriptors[k].dstBinding = j;
|
||||
lframe->descriptors[k].pImageInfo = &lframe->imageInfo[j];
|
||||
for (int j = 0; j < LIGHTING_ATTACH_INFOS; j++) {
|
||||
lframe->attachInfo[j] = base_image_info;
|
||||
lframe->attachInfo[j].sampler = 0;
|
||||
lframe->attachWrite[j] = base_attachment_write;
|
||||
lframe->attachWrite[j].dstSet = attach_set->a[i];
|
||||
lframe->attachWrite[j].dstBinding = j;
|
||||
lframe->attachWrite[j].pImageInfo = &lframe->attachInfo[j];
|
||||
}
|
||||
for (int j = 0; j < LIGHTING_SHADOW_INFOS; j++) {
|
||||
lframe->shadowInfo[j] = base_image_info;
|
||||
lframe->shadowInfo[j].sampler = lctx->sampler;
|
||||
lframe->shadowInfo[j].imageView = ctx->default_black->view;
|
||||
}
|
||||
lframe->shadowWrite = base_image_write;
|
||||
lframe->shadowWrite.dstSet = shadow_set->a[i];
|
||||
lframe->shadowWrite.dstBinding = 0;
|
||||
lframe->shadowWrite.descriptorCount = NUM_LIGHTS;
|
||||
lframe->shadowWrite.pImageInfo = lframe->shadowInfo;
|
||||
}
|
||||
free (attach_set);
|
||||
free (lights_set);
|
||||
|
|
Loading…
Reference in a new issue