Replaced fullscreen quad from index and vertex buffer with fullscreen triangle generated in VS, code cleanup and cleaner naming
This commit is contained in:
parent
a47aba830e
commit
130e1d5262
5 changed files with 118 additions and 204 deletions
|
|
@ -5,7 +5,7 @@
|
||||||
|
|
||||||
layout (binding = 1) uniform sampler2D samplerColor;
|
layout (binding = 1) uniform sampler2D samplerColor;
|
||||||
|
|
||||||
layout (binding = 2) uniform UBO
|
layout (binding = 0) uniform UBO
|
||||||
{
|
{
|
||||||
float radialBlurScale;
|
float radialBlurScale;
|
||||||
float radialBlurStrength;
|
float radialBlurStrength;
|
||||||
|
|
|
||||||
Binary file not shown.
|
|
@ -3,15 +3,6 @@
|
||||||
#extension GL_ARB_separate_shader_objects : enable
|
#extension GL_ARB_separate_shader_objects : enable
|
||||||
#extension GL_ARB_shading_language_420pack : enable
|
#extension GL_ARB_shading_language_420pack : enable
|
||||||
|
|
||||||
layout (location = 0) in vec3 inPos;
|
|
||||||
layout (location = 1) in vec2 inUV;
|
|
||||||
|
|
||||||
layout (binding = 0) uniform UBO
|
|
||||||
{
|
|
||||||
mat4 projection;
|
|
||||||
mat4 model;
|
|
||||||
} ubo;
|
|
||||||
|
|
||||||
layout (location = 0) out vec2 outUV;
|
layout (location = 0) out vec2 outUV;
|
||||||
|
|
||||||
out gl_PerVertex
|
out gl_PerVertex
|
||||||
|
|
@ -21,6 +12,6 @@ out gl_PerVertex
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
outUV = inUV;
|
outUV = vec2((gl_VertexIndex << 1) & 2, gl_VertexIndex & 2);
|
||||||
gl_Position = ubo.projection * ubo.model * vec4(inPos.xyz, 1.0);
|
gl_Position = vec4(outUV * vec2(2.0f, 2.0f) + vec2(-1.0f, -1.0f), 0.0f, 1.0f);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Binary file not shown.
|
|
@ -44,7 +44,6 @@ public:
|
||||||
|
|
||||||
struct {
|
struct {
|
||||||
vkMeshLoader::MeshBuffer example;
|
vkMeshLoader::MeshBuffer example;
|
||||||
vkMeshLoader::MeshBuffer quad;
|
|
||||||
} meshes;
|
} meshes;
|
||||||
|
|
||||||
struct {
|
struct {
|
||||||
|
|
@ -58,28 +57,27 @@ public:
|
||||||
} vertices;
|
} vertices;
|
||||||
|
|
||||||
struct {
|
struct {
|
||||||
vkTools::UniformData vsScene;
|
vkTools::UniformData scene;
|
||||||
vkTools::UniformData vsQuad;
|
vkTools::UniformData blurParams;
|
||||||
vkTools::UniformData fsQuad;
|
|
||||||
} uniformData;
|
} uniformData;
|
||||||
|
|
||||||
struct UboVS {
|
struct UboVS {
|
||||||
glm::mat4 projection;
|
glm::mat4 projection;
|
||||||
glm::mat4 model;
|
glm::mat4 model;
|
||||||
float gradientPos = 0.0f;
|
float gradientPos = 0.0f;
|
||||||
} uboSceneVS, uboQuadVS;
|
} uboScene;
|
||||||
|
|
||||||
struct UboQuadFS {
|
struct UboBlurParams {
|
||||||
float radialBlurScale = 0.35f;
|
float radialBlurScale = 0.35f;
|
||||||
float radialBlurStrength = 0.75f;
|
float radialBlurStrength = 0.75f;
|
||||||
glm::vec2 radialOrigin = glm::vec2(0.5f, 0.5f);
|
glm::vec2 radialOrigin = glm::vec2(0.5f, 0.5f);
|
||||||
} uboQuadFS;
|
} uboBlurParams;
|
||||||
|
|
||||||
struct {
|
struct {
|
||||||
VkPipeline radialBlur;
|
VkPipeline radialBlur;
|
||||||
VkPipeline colorPass;
|
VkPipeline colorPass;
|
||||||
VkPipeline phongPass;
|
VkPipeline phongPass;
|
||||||
VkPipeline fullScreenOnly;
|
VkPipeline offscreenDisplay;
|
||||||
} pipelines;
|
} pipelines;
|
||||||
|
|
||||||
struct {
|
struct {
|
||||||
|
|
@ -89,12 +87,13 @@ public:
|
||||||
|
|
||||||
struct {
|
struct {
|
||||||
VkDescriptorSet scene;
|
VkDescriptorSet scene;
|
||||||
VkDescriptorSet quad;
|
VkDescriptorSet radialBlur;
|
||||||
} descriptorSets;
|
} descriptorSets;
|
||||||
|
|
||||||
// Descriptor set layout is shared amongst
|
struct {
|
||||||
// all descriptor sets
|
VkDescriptorSetLayout scene;
|
||||||
VkDescriptorSetLayout descriptorSetLayout;
|
VkDescriptorSetLayout radialBlur;
|
||||||
|
} descriptorSetLayouts;
|
||||||
|
|
||||||
// Framebuffer for offscreen rendering
|
// Framebuffer for offscreen rendering
|
||||||
struct FrameBufferAttachment {
|
struct FrameBufferAttachment {
|
||||||
|
|
@ -147,21 +146,20 @@ public:
|
||||||
vkDestroyPipeline(device, pipelines.radialBlur, nullptr);
|
vkDestroyPipeline(device, pipelines.radialBlur, nullptr);
|
||||||
vkDestroyPipeline(device, pipelines.phongPass, nullptr);
|
vkDestroyPipeline(device, pipelines.phongPass, nullptr);
|
||||||
vkDestroyPipeline(device, pipelines.colorPass, nullptr);
|
vkDestroyPipeline(device, pipelines.colorPass, nullptr);
|
||||||
vkDestroyPipeline(device, pipelines.fullScreenOnly, nullptr);
|
vkDestroyPipeline(device, pipelines.offscreenDisplay, nullptr);
|
||||||
|
|
||||||
vkDestroyPipelineLayout(device, pipelineLayouts.radialBlur, nullptr);
|
vkDestroyPipelineLayout(device, pipelineLayouts.radialBlur, nullptr);
|
||||||
vkDestroyPipelineLayout(device, pipelineLayouts.scene, nullptr);
|
vkDestroyPipelineLayout(device, pipelineLayouts.scene, nullptr);
|
||||||
|
|
||||||
vkDestroyDescriptorSetLayout(device, descriptorSetLayout, nullptr);
|
vkDestroyDescriptorSetLayout(device, descriptorSetLayouts.scene, nullptr);
|
||||||
|
vkDestroyDescriptorSetLayout(device, descriptorSetLayouts.radialBlur, nullptr);
|
||||||
|
|
||||||
// Meshes
|
// Meshes
|
||||||
vkMeshLoader::freeMeshBufferResources(device, &meshes.example);
|
vkMeshLoader::freeMeshBufferResources(device, &meshes.example);
|
||||||
vkMeshLoader::freeMeshBufferResources(device, &meshes.quad);
|
|
||||||
|
|
||||||
// Uniform buffers
|
// Uniform buffers
|
||||||
vkTools::destroyUniformData(device, &uniformData.vsScene);
|
vkTools::destroyUniformData(device, &uniformData.scene);
|
||||||
vkTools::destroyUniformData(device, &uniformData.vsQuad);
|
vkTools::destroyUniformData(device, &uniformData.blurParams);
|
||||||
vkTools::destroyUniformData(device, &uniformData.fsQuad);
|
|
||||||
|
|
||||||
vkFreeCommandBuffers(device, cmdPool, 1, &offscreenPass.commandBuffer);
|
vkFreeCommandBuffers(device, cmdPool, 1, &offscreenPass.commandBuffer);
|
||||||
vkDestroySemaphore(device, offscreenPass.semaphore, nullptr);
|
vkDestroySemaphore(device, offscreenPass.semaphore, nullptr);
|
||||||
|
|
@ -440,14 +438,12 @@ public:
|
||||||
vkCmdBindIndexBuffer(drawCmdBuffers[i], meshes.example.indices.buf, 0, VK_INDEX_TYPE_UINT32);
|
vkCmdBindIndexBuffer(drawCmdBuffers[i], meshes.example.indices.buf, 0, VK_INDEX_TYPE_UINT32);
|
||||||
vkCmdDrawIndexed(drawCmdBuffers[i], meshes.example.indexCount, 1, 0, 0, 0);
|
vkCmdDrawIndexed(drawCmdBuffers[i], meshes.example.indexCount, 1, 0, 0, 0);
|
||||||
|
|
||||||
// Fullscreen quad with radial blur
|
// Fullscreen triangle (clipped to a quad) with radial blur
|
||||||
if (blur)
|
if (blur)
|
||||||
{
|
{
|
||||||
vkCmdBindDescriptorSets(drawCmdBuffers[i], VK_PIPELINE_BIND_POINT_GRAPHICS, pipelineLayouts.radialBlur, 0, 1, &descriptorSets.quad, 0, NULL);
|
vkCmdBindDescriptorSets(drawCmdBuffers[i], VK_PIPELINE_BIND_POINT_GRAPHICS, pipelineLayouts.radialBlur, 0, 1, &descriptorSets.radialBlur, 0, NULL);
|
||||||
vkCmdBindPipeline(drawCmdBuffers[i], VK_PIPELINE_BIND_POINT_GRAPHICS, (displayTexture) ? pipelines.fullScreenOnly : pipelines.radialBlur);
|
vkCmdBindPipeline(drawCmdBuffers[i], VK_PIPELINE_BIND_POINT_GRAPHICS, (displayTexture) ? pipelines.offscreenDisplay : pipelines.radialBlur);
|
||||||
vkCmdBindVertexBuffers(drawCmdBuffers[i], VERTEX_BUFFER_BIND_ID, 1, &meshes.quad.vertices.buf, offsets);
|
vkCmdDraw(drawCmdBuffers[i], 3, 1, 0, 0);
|
||||||
vkCmdBindIndexBuffer(drawCmdBuffers[i], meshes.quad.indices.buf, 0, VK_INDEX_TYPE_UINT32);
|
|
||||||
vkCmdDrawIndexed(drawCmdBuffers[i], meshes.quad.indexCount, 1, 0, 0, 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
vkCmdEndRenderPass(drawCmdBuffers[i]);
|
vkCmdEndRenderPass(drawCmdBuffers[i]);
|
||||||
|
|
@ -462,45 +458,6 @@ public:
|
||||||
textureLoader->loadTexture(getAssetPath() + "textures/particle_gradient_rgba.ktx", VK_FORMAT_R8G8B8A8_UNORM, &textures.gradient, false);
|
textureLoader->loadTexture(getAssetPath() + "textures/particle_gradient_rgba.ktx", VK_FORMAT_R8G8B8A8_UNORM, &textures.gradient, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Setup vertices for a single uv-mapped quad
|
|
||||||
void generateQuad()
|
|
||||||
{
|
|
||||||
struct Vertex {
|
|
||||||
float pos[3];
|
|
||||||
float uv[2];
|
|
||||||
float col[3];
|
|
||||||
float normal[3];
|
|
||||||
};
|
|
||||||
|
|
||||||
#define QUAD_COLOR_NORMAL { 1.0f, 1.0f, 1.0f }, { 0.0f, 0.0f, 1.0f }
|
|
||||||
std::vector<Vertex> vertexBuffer =
|
|
||||||
{
|
|
||||||
{ { 1.0f, 1.0f, 0.0f },{ 1.0f, 1.0f }, QUAD_COLOR_NORMAL },
|
|
||||||
{ { 0.0f, 1.0f, 0.0f },{ 0.0f, 1.0f }, QUAD_COLOR_NORMAL },
|
|
||||||
{ { 0.0f, 0.0f, 0.0f },{ 0.0f, 0.0f }, QUAD_COLOR_NORMAL },
|
|
||||||
{ { 1.0f, 0.0f, 0.0f },{ 1.0f, 0.0f }, QUAD_COLOR_NORMAL }
|
|
||||||
};
|
|
||||||
#undef QUAD_COLOR_NORMAL
|
|
||||||
|
|
||||||
createBuffer(
|
|
||||||
VK_BUFFER_USAGE_VERTEX_BUFFER_BIT,
|
|
||||||
vertexBuffer.size() * sizeof(Vertex),
|
|
||||||
vertexBuffer.data(),
|
|
||||||
&meshes.quad.vertices.buf,
|
|
||||||
&meshes.quad.vertices.mem);
|
|
||||||
|
|
||||||
// Setup indices
|
|
||||||
std::vector<uint32_t> indexBuffer = { 0,1,2, 2,3,0 };
|
|
||||||
meshes.quad.indexCount = indexBuffer.size();
|
|
||||||
|
|
||||||
createBuffer(
|
|
||||||
VK_BUFFER_USAGE_INDEX_BUFFER_BIT,
|
|
||||||
indexBuffer.size() * sizeof(uint32_t),
|
|
||||||
indexBuffer.data(),
|
|
||||||
&meshes.quad.indices.buf,
|
|
||||||
&meshes.quad.indices.mem);
|
|
||||||
}
|
|
||||||
|
|
||||||
void setupVertexDescriptions()
|
void setupVertexDescriptions()
|
||||||
{
|
{
|
||||||
// Binding description
|
// Binding description
|
||||||
|
|
@ -569,99 +526,100 @@ public:
|
||||||
|
|
||||||
void setupDescriptorSetLayout()
|
void setupDescriptorSetLayout()
|
||||||
{
|
{
|
||||||
// Textured quad pipeline layout
|
std::vector<VkDescriptorSetLayoutBinding> setLayoutBindings;
|
||||||
std::vector<VkDescriptorSetLayoutBinding> setLayoutBindings =
|
VkDescriptorSetLayoutCreateInfo descriptorLayout;
|
||||||
|
VkPipelineLayoutCreateInfo pPipelineLayoutCreateInfo;
|
||||||
|
|
||||||
|
// Scene rendering
|
||||||
|
setLayoutBindings =
|
||||||
{
|
{
|
||||||
// Binding 0 : Vertex shader uniform buffer
|
// Binding 0: Vertex shader uniform buffer
|
||||||
vkTools::initializers::descriptorSetLayoutBinding(
|
vkTools::initializers::descriptorSetLayoutBinding(
|
||||||
VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
|
VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
|
||||||
VK_SHADER_STAGE_VERTEX_BIT,
|
VK_SHADER_STAGE_VERTEX_BIT,
|
||||||
0),
|
0),
|
||||||
// Binding 1 : Fragment shader image sampler
|
// Binding 1: Fragment shader image sampler
|
||||||
vkTools::initializers::descriptorSetLayoutBinding(
|
vkTools::initializers::descriptorSetLayoutBinding(
|
||||||
VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,
|
VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,
|
||||||
VK_SHADER_STAGE_FRAGMENT_BIT,
|
VK_SHADER_STAGE_FRAGMENT_BIT,
|
||||||
1),
|
1),
|
||||||
// Binding 2 : Fragment shader uniform buffer
|
// Binding 2: Fragment shader uniform buffer
|
||||||
vkTools::initializers::descriptorSetLayoutBinding(
|
vkTools::initializers::descriptorSetLayoutBinding(
|
||||||
VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
|
VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
|
||||||
VK_SHADER_STAGE_FRAGMENT_BIT,
|
VK_SHADER_STAGE_FRAGMENT_BIT,
|
||||||
2)
|
2)
|
||||||
};
|
};
|
||||||
|
descriptorLayout = vkTools::initializers::descriptorSetLayoutCreateInfo(setLayoutBindings.data(), static_cast<uint32_t>(setLayoutBindings.size()));
|
||||||
VkDescriptorSetLayoutCreateInfo descriptorLayout =
|
VK_CHECK_RESULT(vkCreateDescriptorSetLayout(device, &descriptorLayout, nullptr, &descriptorSetLayouts.scene));
|
||||||
vkTools::initializers::descriptorSetLayoutCreateInfo(
|
pPipelineLayoutCreateInfo = vkTools::initializers::pipelineLayoutCreateInfo(&descriptorSetLayouts.scene, 1);
|
||||||
setLayoutBindings.data(),
|
|
||||||
setLayoutBindings.size());
|
|
||||||
|
|
||||||
VK_CHECK_RESULT(vkCreateDescriptorSetLayout(device, &descriptorLayout, nullptr, &descriptorSetLayout));
|
|
||||||
|
|
||||||
VkPipelineLayoutCreateInfo pPipelineLayoutCreateInfo =
|
|
||||||
vkTools::initializers::pipelineLayoutCreateInfo(
|
|
||||||
&descriptorSetLayout,
|
|
||||||
1);
|
|
||||||
|
|
||||||
VK_CHECK_RESULT(vkCreatePipelineLayout(device, &pPipelineLayoutCreateInfo, nullptr, &pipelineLayouts.radialBlur));
|
|
||||||
|
|
||||||
// Offscreen pipeline layout
|
|
||||||
VK_CHECK_RESULT(vkCreatePipelineLayout(device, &pPipelineLayoutCreateInfo, nullptr, &pipelineLayouts.scene));
|
VK_CHECK_RESULT(vkCreatePipelineLayout(device, &pPipelineLayoutCreateInfo, nullptr, &pipelineLayouts.scene));
|
||||||
|
|
||||||
|
// Fullscreen radial blur
|
||||||
|
setLayoutBindings =
|
||||||
|
{
|
||||||
|
// Binding 0 : Vertex shader uniform buffer
|
||||||
|
vkTools::initializers::descriptorSetLayoutBinding(
|
||||||
|
VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
|
||||||
|
VK_SHADER_STAGE_FRAGMENT_BIT,
|
||||||
|
0),
|
||||||
|
// Binding 0: Fragment shader image sampler
|
||||||
|
vkTools::initializers::descriptorSetLayoutBinding(
|
||||||
|
VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,
|
||||||
|
VK_SHADER_STAGE_FRAGMENT_BIT,
|
||||||
|
1)
|
||||||
|
};
|
||||||
|
descriptorLayout = vkTools::initializers::descriptorSetLayoutCreateInfo(setLayoutBindings.data(), static_cast<uint32_t>(setLayoutBindings.size()));
|
||||||
|
VK_CHECK_RESULT(vkCreateDescriptorSetLayout(device, &descriptorLayout, nullptr, &descriptorSetLayouts.radialBlur));
|
||||||
|
pPipelineLayoutCreateInfo = vkTools::initializers::pipelineLayoutCreateInfo(&descriptorSetLayouts.radialBlur, 1);
|
||||||
|
VK_CHECK_RESULT(vkCreatePipelineLayout(device, &pPipelineLayoutCreateInfo, nullptr, &pipelineLayouts.radialBlur));
|
||||||
}
|
}
|
||||||
|
|
||||||
void setupDescriptorSet()
|
void setupDescriptorSet()
|
||||||
{
|
{
|
||||||
// Textured quad descriptor set
|
VkDescriptorSetAllocateInfo descriptorSetAllocInfo;
|
||||||
VkDescriptorSetAllocateInfo allocInfo =
|
|
||||||
vkTools::initializers::descriptorSetAllocateInfo(
|
|
||||||
descriptorPool,
|
|
||||||
&descriptorSetLayout,
|
|
||||||
1);
|
|
||||||
|
|
||||||
VK_CHECK_RESULT(vkAllocateDescriptorSets(device, &allocInfo, &descriptorSets.quad));
|
// Scene rendering
|
||||||
|
descriptorSetAllocInfo = vkTools::initializers::descriptorSetAllocateInfo(descriptorPool, &descriptorSetLayouts.scene, 1);
|
||||||
std::vector<VkWriteDescriptorSet> writeDescriptorSets =
|
VK_CHECK_RESULT(vkAllocateDescriptorSets(device, &descriptorSetAllocInfo, &descriptorSets.scene));
|
||||||
{
|
|
||||||
// Binding 0 : Vertex shader uniform buffer
|
|
||||||
vkTools::initializers::writeDescriptorSet(
|
|
||||||
descriptorSets.quad,
|
|
||||||
VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
|
|
||||||
0,
|
|
||||||
&uniformData.vsScene.descriptor),
|
|
||||||
// Binding 1 : Fragment shader texture sampler
|
|
||||||
vkTools::initializers::writeDescriptorSet(
|
|
||||||
descriptorSets.quad,
|
|
||||||
VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,
|
|
||||||
1,
|
|
||||||
&offscreenPass.descriptor),
|
|
||||||
// Binding 2 : Fragment shader uniform buffer
|
|
||||||
vkTools::initializers::writeDescriptorSet(
|
|
||||||
descriptorSets.quad,
|
|
||||||
VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
|
|
||||||
2,
|
|
||||||
&uniformData.fsQuad.descriptor)
|
|
||||||
};
|
|
||||||
|
|
||||||
vkUpdateDescriptorSets(device, writeDescriptorSets.size(), writeDescriptorSets.data(), 0, NULL);
|
|
||||||
|
|
||||||
// Offscreen 3D scene descriptor set
|
|
||||||
VK_CHECK_RESULT(vkAllocateDescriptorSets(device, &allocInfo, &descriptorSets.scene));
|
|
||||||
|
|
||||||
std::vector<VkWriteDescriptorSet> offScreenWriteDescriptorSets =
|
std::vector<VkWriteDescriptorSet> offScreenWriteDescriptorSets =
|
||||||
{
|
{
|
||||||
// Binding 0 : Vertex shader uniform buffer
|
// Binding 0: Vertex shader uniform buffer
|
||||||
vkTools::initializers::writeDescriptorSet(
|
vkTools::initializers::writeDescriptorSet(
|
||||||
descriptorSets.scene,
|
descriptorSets.scene,
|
||||||
VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
|
VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
|
||||||
0,
|
0,
|
||||||
&uniformData.vsQuad.descriptor),
|
&uniformData.scene.descriptor),
|
||||||
// Binding 1 : Color gradient sampler
|
// Binding 1: Color gradient sampler
|
||||||
vkTools::initializers::writeDescriptorSet(
|
vkTools::initializers::writeDescriptorSet(
|
||||||
descriptorSets.scene,
|
descriptorSets.scene,
|
||||||
VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,
|
VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,
|
||||||
1,
|
1,
|
||||||
&textures.gradient.descriptor)
|
&textures.gradient.descriptor),
|
||||||
|
|
||||||
};
|
};
|
||||||
vkUpdateDescriptorSets(device, offScreenWriteDescriptorSets.size(), offScreenWriteDescriptorSets.data(), 0, NULL);
|
vkUpdateDescriptorSets(device, offScreenWriteDescriptorSets.size(), offScreenWriteDescriptorSets.data(), 0, NULL);
|
||||||
|
|
||||||
|
// Fullscreen radial blur
|
||||||
|
descriptorSetAllocInfo = vkTools::initializers::descriptorSetAllocateInfo(descriptorPool, &descriptorSetLayouts.radialBlur, 1);
|
||||||
|
VK_CHECK_RESULT(vkAllocateDescriptorSets(device, &descriptorSetAllocInfo, &descriptorSets.radialBlur));
|
||||||
|
|
||||||
|
std::vector<VkWriteDescriptorSet> writeDescriptorSets =
|
||||||
|
{
|
||||||
|
// Binding 0: Vertex shader uniform buffer
|
||||||
|
vkTools::initializers::writeDescriptorSet(
|
||||||
|
descriptorSets.radialBlur,
|
||||||
|
VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
|
||||||
|
0,
|
||||||
|
&uniformData.blurParams.descriptor),
|
||||||
|
// Binding 0: Fragment shader texture sampler
|
||||||
|
vkTools::initializers::writeDescriptorSet(
|
||||||
|
descriptorSets.radialBlur,
|
||||||
|
VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,
|
||||||
|
1,
|
||||||
|
&offscreenPass.descriptor),
|
||||||
|
};
|
||||||
|
|
||||||
|
vkUpdateDescriptorSets(device, writeDescriptorSets.size(), writeDescriptorSets.data(), 0, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
void preparePipelines()
|
void preparePipelines()
|
||||||
|
|
@ -713,20 +671,14 @@ public:
|
||||||
dynamicStateEnables.size(),
|
dynamicStateEnables.size(),
|
||||||
0);
|
0);
|
||||||
|
|
||||||
// Radial blur pipeline
|
|
||||||
// Load shaders
|
|
||||||
std::array<VkPipelineShaderStageCreateInfo, 2> shaderStages;
|
std::array<VkPipelineShaderStageCreateInfo, 2> shaderStages;
|
||||||
|
|
||||||
shaderStages[0] = loadShader(getAssetPath() + "shaders/radialblur/radialblur.vert.spv", VK_SHADER_STAGE_VERTEX_BIT);
|
|
||||||
shaderStages[1] = loadShader(getAssetPath() + "shaders/radialblur/radialblur.frag.spv", VK_SHADER_STAGE_FRAGMENT_BIT);
|
|
||||||
|
|
||||||
VkGraphicsPipelineCreateInfo pipelineCreateInfo =
|
VkGraphicsPipelineCreateInfo pipelineCreateInfo =
|
||||||
vkTools::initializers::pipelineCreateInfo(
|
vkTools::initializers::pipelineCreateInfo(
|
||||||
pipelineLayouts.radialBlur,
|
pipelineLayouts.radialBlur,
|
||||||
renderPass,
|
renderPass,
|
||||||
0);
|
0);
|
||||||
|
|
||||||
pipelineCreateInfo.pVertexInputState = &vertices.inputState;
|
|
||||||
pipelineCreateInfo.pInputAssemblyState = &inputAssemblyState;
|
pipelineCreateInfo.pInputAssemblyState = &inputAssemblyState;
|
||||||
pipelineCreateInfo.pRasterizationState = &rasterizationState;
|
pipelineCreateInfo.pRasterizationState = &rasterizationState;
|
||||||
pipelineCreateInfo.pColorBlendState = &colorBlendState;
|
pipelineCreateInfo.pColorBlendState = &colorBlendState;
|
||||||
|
|
@ -737,6 +689,13 @@ public:
|
||||||
pipelineCreateInfo.stageCount = shaderStages.size();
|
pipelineCreateInfo.stageCount = shaderStages.size();
|
||||||
pipelineCreateInfo.pStages = shaderStages.data();
|
pipelineCreateInfo.pStages = shaderStages.data();
|
||||||
|
|
||||||
|
// Radial blur pipeline
|
||||||
|
shaderStages[0] = loadShader(getAssetPath() + "shaders/radialblur/radialblur.vert.spv", VK_SHADER_STAGE_VERTEX_BIT);
|
||||||
|
shaderStages[1] = loadShader(getAssetPath() + "shaders/radialblur/radialblur.frag.spv", VK_SHADER_STAGE_FRAGMENT_BIT);
|
||||||
|
// Empty vertex input state
|
||||||
|
VkPipelineVertexInputStateCreateInfo emptyInputState = vkTools::initializers::pipelineVertexInputStateCreateInfo();
|
||||||
|
pipelineCreateInfo.pVertexInputState = &emptyInputState;
|
||||||
|
pipelineCreateInfo.layout = pipelineLayouts.radialBlur;
|
||||||
// Additive blending
|
// Additive blending
|
||||||
blendAttachmentState.colorWriteMask = 0xF;
|
blendAttachmentState.colorWriteMask = 0xF;
|
||||||
blendAttachmentState.blendEnable = VK_TRUE;
|
blendAttachmentState.blendEnable = VK_TRUE;
|
||||||
|
|
@ -750,12 +709,13 @@ public:
|
||||||
|
|
||||||
// No blending (for debug display)
|
// No blending (for debug display)
|
||||||
blendAttachmentState.blendEnable = VK_FALSE;
|
blendAttachmentState.blendEnable = VK_FALSE;
|
||||||
VK_CHECK_RESULT(vkCreateGraphicsPipelines(device, pipelineCache, 1, &pipelineCreateInfo, nullptr, &pipelines.fullScreenOnly));
|
VK_CHECK_RESULT(vkCreateGraphicsPipelines(device, pipelineCache, 1, &pipelineCreateInfo, nullptr, &pipelines.offscreenDisplay));
|
||||||
|
|
||||||
// Phong pass
|
// Phong pass
|
||||||
|
pipelineCreateInfo.layout = pipelineLayouts.scene;
|
||||||
shaderStages[0] = loadShader(getAssetPath() + "shaders/radialblur/phongpass.vert.spv", VK_SHADER_STAGE_VERTEX_BIT);
|
shaderStages[0] = loadShader(getAssetPath() + "shaders/radialblur/phongpass.vert.spv", VK_SHADER_STAGE_VERTEX_BIT);
|
||||||
shaderStages[1] = loadShader(getAssetPath() + "shaders/radialblur/phongpass.frag.spv", VK_SHADER_STAGE_FRAGMENT_BIT);
|
shaderStages[1] = loadShader(getAssetPath() + "shaders/radialblur/phongpass.frag.spv", VK_SHADER_STAGE_FRAGMENT_BIT);
|
||||||
pipelineCreateInfo.layout = pipelineLayouts.scene;
|
pipelineCreateInfo.pVertexInputState = &vertices.inputState;
|
||||||
blendAttachmentState.blendEnable = VK_FALSE;
|
blendAttachmentState.blendEnable = VK_FALSE;
|
||||||
depthStencilState.depthWriteEnable = VK_TRUE;
|
depthStencilState.depthWriteEnable = VK_TRUE;
|
||||||
VK_CHECK_RESULT(vkCreateGraphicsPipelines(device, pipelineCache, 1, &pipelineCreateInfo, nullptr, &pipelines.phongPass));
|
VK_CHECK_RESULT(vkCreateGraphicsPipelines(device, pipelineCache, 1, &pipelineCreateInfo, nullptr, &pipelines.phongPass));
|
||||||
|
|
@ -764,7 +724,6 @@ public:
|
||||||
shaderStages[0] = loadShader(getAssetPath() + "shaders/radialblur/colorpass.vert.spv", VK_SHADER_STAGE_VERTEX_BIT);
|
shaderStages[0] = loadShader(getAssetPath() + "shaders/radialblur/colorpass.vert.spv", VK_SHADER_STAGE_VERTEX_BIT);
|
||||||
shaderStages[1] = loadShader(getAssetPath() + "shaders/radialblur/colorpass.frag.spv", VK_SHADER_STAGE_FRAGMENT_BIT);
|
shaderStages[1] = loadShader(getAssetPath() + "shaders/radialblur/colorpass.frag.spv", VK_SHADER_STAGE_FRAGMENT_BIT);
|
||||||
pipelineCreateInfo.renderPass = offscreenPass.renderPass;
|
pipelineCreateInfo.renderPass = offscreenPass.renderPass;
|
||||||
pipelineCreateInfo.layout = pipelineLayouts.radialBlur;
|
|
||||||
VK_CHECK_RESULT(vkCreateGraphicsPipelines(device, pipelineCache, 1, &pipelineCreateInfo, nullptr, &pipelines.colorPass));
|
VK_CHECK_RESULT(vkCreateGraphicsPipelines(device, pipelineCache, 1, &pipelineCreateInfo, nullptr, &pipelines.colorPass));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -775,81 +734,47 @@ public:
|
||||||
createBuffer(
|
createBuffer(
|
||||||
VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT,
|
VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT,
|
||||||
VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT,
|
VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT,
|
||||||
sizeof(uboSceneVS),
|
sizeof(uboScene),
|
||||||
&uboSceneVS,
|
&uboScene,
|
||||||
&uniformData.vsScene.buffer,
|
&uniformData.scene.buffer,
|
||||||
&uniformData.vsScene.memory,
|
&uniformData.scene.memory,
|
||||||
&uniformData.vsScene.descriptor);
|
&uniformData.scene.descriptor);
|
||||||
|
|
||||||
// Fullscreen quad vertex shader uniform buffer
|
|
||||||
createBuffer(
|
|
||||||
VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT,
|
|
||||||
VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT,
|
|
||||||
sizeof(uboQuadVS),
|
|
||||||
&uboQuadVS,
|
|
||||||
&uniformData.vsQuad.buffer,
|
|
||||||
&uniformData.vsQuad.memory,
|
|
||||||
&uniformData.vsQuad.descriptor);
|
|
||||||
|
|
||||||
// Fullscreen quad fragment shader uniform buffer
|
// Fullscreen quad fragment shader uniform buffer
|
||||||
createBuffer(
|
createBuffer(
|
||||||
VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT,
|
VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT,
|
||||||
VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT,
|
VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT,
|
||||||
sizeof(uboQuadFS),
|
sizeof(uboBlurParams),
|
||||||
&uboQuadFS,
|
&uboBlurParams,
|
||||||
&uniformData.fsQuad.buffer,
|
&uniformData.blurParams.buffer,
|
||||||
&uniformData.fsQuad.memory,
|
&uniformData.blurParams.memory,
|
||||||
&uniformData.fsQuad.descriptor);
|
&uniformData.blurParams.descriptor);
|
||||||
|
|
||||||
updateUniformBuffersScene();
|
updateUniformBuffersScene();
|
||||||
updateUniformBuffersScreen();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update uniform buffers for rendering the 3D scene
|
// Update uniform buffers for rendering the 3D scene
|
||||||
void updateUniformBuffersScene()
|
void updateUniformBuffersScene()
|
||||||
{
|
{
|
||||||
uboQuadVS.projection = glm::perspective(glm::radians(45.0f), (float)width / (float)height, 1.0f, 256.0f);
|
uboScene.projection = glm::perspective(glm::radians(45.0f), (float)width / (float)height, 1.0f, 256.0f);
|
||||||
glm::mat4 viewMatrix = glm::translate(glm::mat4(), glm::vec3(0.0f, 0.0f, zoom));
|
glm::mat4 viewMatrix = glm::translate(glm::mat4(), glm::vec3(0.0f, 0.0f, zoom));
|
||||||
|
|
||||||
uboQuadVS.model = glm::mat4();
|
uboScene.model = glm::mat4();
|
||||||
uboQuadVS.model = viewMatrix * glm::translate(uboQuadVS.model, cameraPos);
|
uboScene.model = viewMatrix * glm::translate(uboScene.model, cameraPos);
|
||||||
uboQuadVS.model = glm::rotate(uboQuadVS.model, glm::radians(rotation.x), glm::vec3(1.0f, 0.0f, 0.0f));
|
uboScene.model = glm::rotate(uboScene.model, glm::radians(rotation.x), glm::vec3(1.0f, 0.0f, 0.0f));
|
||||||
uboQuadVS.model = glm::rotate(uboQuadVS.model, glm::radians(rotation.y), glm::vec3(0.0f, 1.0f, 0.0f));
|
uboScene.model = glm::rotate(uboScene.model, glm::radians(rotation.y), glm::vec3(0.0f, 1.0f, 0.0f));
|
||||||
uboQuadVS.model = glm::rotate(uboQuadVS.model, glm::radians(timer * 360.0f), glm::vec3(0.0f, 1.0f, 0.0f));
|
uboScene.model = glm::rotate(uboScene.model, glm::radians(timer * 360.0f), glm::vec3(0.0f, 1.0f, 0.0f));
|
||||||
uboQuadVS.model = glm::rotate(uboQuadVS.model, glm::radians(rotation.z), glm::vec3(0.0f, 0.0f, 1.0f));
|
uboScene.model = glm::rotate(uboScene.model, glm::radians(rotation.z), glm::vec3(0.0f, 0.0f, 1.0f));
|
||||||
|
|
||||||
if (!paused)
|
if (!paused)
|
||||||
{
|
{
|
||||||
uboQuadVS.gradientPos += frameTimer * 0.1f;
|
uboScene.gradientPos += frameTimer * 0.1f;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t *pData;
|
uint8_t *pData;
|
||||||
VK_CHECK_RESULT(vkMapMemory(device, uniformData.vsQuad.memory, 0, sizeof(uboQuadVS), 0, (void **)&pData));
|
VK_CHECK_RESULT(vkMapMemory(device, uniformData.scene.memory, 0, sizeof(uboScene), 0, (void **)&pData));
|
||||||
memcpy(pData, &uboQuadVS, sizeof(uboQuadVS));
|
memcpy(pData, &uboScene, sizeof(uboScene));
|
||||||
vkUnmapMemory(device, uniformData.vsQuad.memory);
|
vkUnmapMemory(device, uniformData.scene.memory);
|
||||||
}
|
|
||||||
|
|
||||||
// Update uniform buffers for the fullscreen quad
|
|
||||||
void updateUniformBuffersScreen()
|
|
||||||
{
|
|
||||||
// Vertex shader
|
|
||||||
uboSceneVS.projection = glm::ortho(0.0f, 1.0f, 0.0f, 1.0f, -1.0f, 1.0f);
|
|
||||||
uboSceneVS.model = glm::mat4();
|
|
||||||
|
|
||||||
uint8_t *pData;
|
|
||||||
VK_CHECK_RESULT(vkMapMemory(device, uniformData.vsScene.memory, 0, sizeof(uboSceneVS), 0, (void **)&pData));
|
|
||||||
memcpy(pData, &uboSceneVS, sizeof(uboSceneVS));
|
|
||||||
vkUnmapMemory(device, uniformData.vsScene.memory);
|
|
||||||
|
|
||||||
if (!paused)
|
|
||||||
{
|
|
||||||
uboSceneVS.gradientPos += uboQuadVS.gradientPos;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Fragment shader
|
|
||||||
VK_CHECK_RESULT(vkMapMemory(device, uniformData.fsQuad.memory, 0, sizeof(uboQuadFS), 0, (void **)&pData));
|
|
||||||
memcpy(pData, &uboQuadFS, sizeof(uboQuadFS));
|
|
||||||
vkUnmapMemory(device, uniformData.fsQuad.memory);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void draw()
|
void draw()
|
||||||
|
|
@ -886,7 +811,6 @@ public:
|
||||||
{
|
{
|
||||||
VulkanExampleBase::prepare();
|
VulkanExampleBase::prepare();
|
||||||
loadAssets();
|
loadAssets();
|
||||||
generateQuad();
|
|
||||||
prepareOffscreen();
|
prepareOffscreen();
|
||||||
setupVertexDescriptions();
|
setupVertexDescriptions();
|
||||||
prepareUniformBuffers();
|
prepareUniformBuffers();
|
||||||
|
|
@ -913,7 +837,6 @@ public:
|
||||||
virtual void viewChanged()
|
virtual void viewChanged()
|
||||||
{
|
{
|
||||||
updateUniformBuffersScene();
|
updateUniformBuffersScene();
|
||||||
updateUniformBuffersScreen();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void toggleBlur()
|
void toggleBlur()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue