2016-10-28 21:16:21 +02:00
|
|
|
/*
|
|
|
|
|
* Vulkan Example - Screen space ambient occlusion example
|
|
|
|
|
*
|
|
|
|
|
* Copyright (C) 2016 by Sascha Willems - www.saschawillems.de
|
|
|
|
|
*
|
|
|
|
|
* This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT)
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
#include <assert.h>
|
|
|
|
|
#include <vector>
|
|
|
|
|
#include <random>
|
|
|
|
|
|
|
|
|
|
#define GLM_FORCE_RADIANS
|
|
|
|
|
#define GLM_FORCE_DEPTH_ZERO_TO_ONE
|
|
|
|
|
#include <glm/glm.hpp>
|
|
|
|
|
#include <glm/gtc/matrix_transform.hpp>
|
|
|
|
|
|
|
|
|
|
#include <vulkan/vulkan.h>
|
|
|
|
|
#include "vulkanexamplebase.h"
|
2017-02-09 21:55:35 +01:00
|
|
|
#include "VulkanTexture.hpp"
|
2017-02-11 14:18:24 +01:00
|
|
|
#include "VulkanModel.hpp"
|
2016-10-28 21:16:21 +02:00
|
|
|
|
|
|
|
|
#define VERTEX_BUFFER_BIND_ID 0
|
|
|
|
|
#define ENABLE_VALIDATION false
|
|
|
|
|
|
2016-10-30 13:49:30 +01:00
|
|
|
#define SSAO_KERNEL_SIZE 32
|
2016-11-01 15:39:54 +01:00
|
|
|
#define SSAO_RADIUS 0.5f
|
2016-10-30 13:49:30 +01:00
|
|
|
|
|
|
|
|
#if defined(__ANDROID__)
|
|
|
|
|
#define SSAO_NOISE_DIM 8
|
|
|
|
|
#else
|
2016-10-28 21:16:21 +02:00
|
|
|
#define SSAO_NOISE_DIM 4
|
2016-10-30 13:49:30 +01:00
|
|
|
#endif
|
2016-10-28 21:16:21 +02:00
|
|
|
|
|
|
|
|
class VulkanExample : public VulkanExampleBase
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
struct {
|
2017-02-09 21:55:35 +01:00
|
|
|
vks::Texture2D ssaoNoise;
|
2016-10-28 21:16:21 +02:00
|
|
|
} textures;
|
|
|
|
|
|
2017-02-11 14:18:24 +01:00
|
|
|
// Vertex layout for the models
|
|
|
|
|
vks::VertexLayout vertexLayout = vks::VertexLayout({
|
|
|
|
|
vks::VERTEX_COMPONENT_POSITION,
|
|
|
|
|
vks::VERTEX_COMPONENT_UV,
|
|
|
|
|
vks::VERTEX_COMPONENT_COLOR,
|
|
|
|
|
vks::VERTEX_COMPONENT_NORMAL,
|
|
|
|
|
});
|
|
|
|
|
|
2016-10-28 21:16:21 +02:00
|
|
|
struct {
|
2017-02-11 14:18:24 +01:00
|
|
|
vks::Model scene;
|
|
|
|
|
} models;
|
2016-10-28 21:16:21 +02:00
|
|
|
|
|
|
|
|
struct {
|
|
|
|
|
VkPipelineVertexInputStateCreateInfo inputState;
|
|
|
|
|
std::vector<VkVertexInputBindingDescription> bindingDescriptions;
|
|
|
|
|
std::vector<VkVertexInputAttributeDescription> attributeDescriptions;
|
|
|
|
|
} vertices;
|
|
|
|
|
|
|
|
|
|
struct UBOSceneMatrices {
|
|
|
|
|
glm::mat4 projection;
|
|
|
|
|
glm::mat4 model;
|
|
|
|
|
glm::mat4 view;
|
|
|
|
|
} uboSceneMatrices;
|
|
|
|
|
|
|
|
|
|
struct UBOSSAOParams {
|
|
|
|
|
glm::mat4 projection;
|
|
|
|
|
uint32_t ssao = true;
|
|
|
|
|
uint32_t ssaoOnly = false;
|
|
|
|
|
uint32_t ssaoBlur = true;
|
|
|
|
|
} uboSSAOParams;
|
|
|
|
|
|
|
|
|
|
struct {
|
|
|
|
|
VkPipeline offscreen;
|
|
|
|
|
VkPipeline composition;
|
|
|
|
|
VkPipeline ssao;
|
|
|
|
|
VkPipeline ssaoBlur;
|
|
|
|
|
} pipelines;
|
|
|
|
|
|
|
|
|
|
struct {
|
|
|
|
|
VkPipelineLayout gBuffer;
|
|
|
|
|
VkPipelineLayout ssao;
|
|
|
|
|
VkPipelineLayout ssaoBlur;
|
|
|
|
|
VkPipelineLayout composition;
|
|
|
|
|
} pipelineLayouts;
|
|
|
|
|
|
|
|
|
|
struct {
|
|
|
|
|
const uint32_t count = 5;
|
|
|
|
|
VkDescriptorSet model;
|
|
|
|
|
VkDescriptorSet floor;
|
|
|
|
|
VkDescriptorSet ssao;
|
|
|
|
|
VkDescriptorSet ssaoBlur;
|
|
|
|
|
VkDescriptorSet composition;
|
|
|
|
|
} descriptorSets;
|
|
|
|
|
|
|
|
|
|
struct {
|
|
|
|
|
VkDescriptorSetLayout gBuffer;
|
|
|
|
|
VkDescriptorSetLayout ssao;
|
|
|
|
|
VkDescriptorSetLayout ssaoBlur;
|
|
|
|
|
VkDescriptorSetLayout composition;
|
|
|
|
|
} descriptorSetLayouts;
|
|
|
|
|
|
|
|
|
|
struct {
|
2017-02-12 10:44:51 +01:00
|
|
|
vks::Buffer sceneMatrices;
|
|
|
|
|
vks::Buffer ssaoKernel;
|
|
|
|
|
vks::Buffer ssaoParams;
|
2016-10-28 21:16:21 +02:00
|
|
|
} uniformBuffers;
|
|
|
|
|
|
|
|
|
|
// Framebuffer for offscreen rendering
|
|
|
|
|
struct FrameBufferAttachment {
|
|
|
|
|
VkImage image;
|
|
|
|
|
VkDeviceMemory mem;
|
|
|
|
|
VkImageView view;
|
|
|
|
|
VkFormat format;
|
|
|
|
|
void destroy(VkDevice device)
|
|
|
|
|
{
|
|
|
|
|
vkDestroyImage(device, image, nullptr);
|
|
|
|
|
vkDestroyImageView(device, view, nullptr);
|
|
|
|
|
vkFreeMemory(device, mem, nullptr);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
struct FrameBuffer {
|
|
|
|
|
int32_t width, height;
|
|
|
|
|
VkFramebuffer frameBuffer;
|
|
|
|
|
VkRenderPass renderPass;
|
|
|
|
|
void setSize(int32_t w, int32_t h)
|
|
|
|
|
{
|
|
|
|
|
this->width = w;
|
|
|
|
|
this->height = h;
|
|
|
|
|
}
|
|
|
|
|
void destroy(VkDevice device)
|
|
|
|
|
{
|
|
|
|
|
vkDestroyFramebuffer(device, frameBuffer, nullptr);
|
|
|
|
|
vkDestroyRenderPass(device, renderPass, nullptr);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct {
|
|
|
|
|
struct Offscreen : public FrameBuffer {
|
|
|
|
|
FrameBufferAttachment position, normal, albedo, depth;
|
|
|
|
|
} offscreen;
|
|
|
|
|
struct SSAO : public FrameBuffer {
|
|
|
|
|
FrameBufferAttachment color;
|
|
|
|
|
} ssao, ssaoBlur;
|
|
|
|
|
} frameBuffers;
|
|
|
|
|
|
|
|
|
|
// One sampler for the frame buffer color attachments
|
|
|
|
|
VkSampler colorSampler;
|
|
|
|
|
|
|
|
|
|
VkCommandBuffer offScreenCmdBuffer = VK_NULL_HANDLE;
|
|
|
|
|
|
|
|
|
|
// Semaphore used to synchronize between offscreen and final scene rendering
|
|
|
|
|
VkSemaphore offscreenSemaphore = VK_NULL_HANDLE;
|
|
|
|
|
|
|
|
|
|
VulkanExample() : VulkanExampleBase(ENABLE_VALIDATION)
|
|
|
|
|
{
|
|
|
|
|
zoom = -8.0f;
|
|
|
|
|
rotation = { 0.0f, 0.0f, 0.0f };
|
|
|
|
|
enableTextOverlay = true;
|
|
|
|
|
title = "Vulkan Example - Screen space ambient occlusion";
|
|
|
|
|
camera.type = Camera::CameraType::firstperson;
|
|
|
|
|
camera.movementSpeed = 5.0f;
|
|
|
|
|
#ifndef __ANDROID__
|
|
|
|
|
camera.rotationSpeed = 0.25f;
|
|
|
|
|
#endif
|
2016-10-29 13:18:20 +02:00
|
|
|
camera.position = { 7.5f, -6.75f, 0.0f };
|
|
|
|
|
camera.setRotation(glm::vec3(5.0f, 90.0f, 0.0f));
|
|
|
|
|
camera.setPerspective(60.0f, (float)width / (float)height, 0.1f, 64.0f);
|
2016-10-28 21:16:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
~VulkanExample()
|
|
|
|
|
{
|
|
|
|
|
vkDestroySampler(device, colorSampler, nullptr);
|
|
|
|
|
|
|
|
|
|
// Attachments
|
|
|
|
|
frameBuffers.offscreen.position.destroy(device);
|
|
|
|
|
frameBuffers.offscreen.normal.destroy(device);
|
|
|
|
|
frameBuffers.offscreen.albedo.destroy(device);
|
|
|
|
|
frameBuffers.offscreen.depth.destroy(device);
|
|
|
|
|
frameBuffers.ssao.color.destroy(device);
|
|
|
|
|
frameBuffers.ssaoBlur.color.destroy(device);
|
|
|
|
|
|
|
|
|
|
// Framebuffers
|
|
|
|
|
frameBuffers.offscreen.destroy(device);
|
|
|
|
|
frameBuffers.ssao.destroy(device);
|
|
|
|
|
frameBuffers.ssaoBlur.destroy(device);
|
|
|
|
|
|
|
|
|
|
vkDestroyPipeline(device, pipelines.offscreen, nullptr);
|
|
|
|
|
vkDestroyPipeline(device, pipelines.composition, nullptr);
|
|
|
|
|
vkDestroyPipeline(device, pipelines.ssao, nullptr);
|
|
|
|
|
vkDestroyPipeline(device, pipelines.ssaoBlur, nullptr);
|
|
|
|
|
|
|
|
|
|
vkDestroyPipelineLayout(device, pipelineLayouts.gBuffer, nullptr);
|
|
|
|
|
vkDestroyPipelineLayout(device, pipelineLayouts.ssao, nullptr);
|
|
|
|
|
vkDestroyPipelineLayout(device, pipelineLayouts.ssaoBlur, nullptr);
|
|
|
|
|
vkDestroyPipelineLayout(device, pipelineLayouts.composition, nullptr);
|
|
|
|
|
|
|
|
|
|
vkDestroyDescriptorSetLayout(device, descriptorSetLayouts.gBuffer, nullptr);
|
|
|
|
|
vkDestroyDescriptorSetLayout(device, descriptorSetLayouts.ssao, nullptr);
|
|
|
|
|
vkDestroyDescriptorSetLayout(device, descriptorSetLayouts.ssaoBlur, nullptr);
|
|
|
|
|
vkDestroyDescriptorSetLayout(device, descriptorSetLayouts.composition, nullptr);
|
|
|
|
|
|
|
|
|
|
// Meshes
|
2017-02-11 14:18:24 +01:00
|
|
|
models.scene.destroy();
|
2016-10-28 21:16:21 +02:00
|
|
|
|
|
|
|
|
// Uniform buffers
|
|
|
|
|
uniformBuffers.sceneMatrices.destroy();
|
|
|
|
|
uniformBuffers.ssaoKernel.destroy();
|
|
|
|
|
uniformBuffers.ssaoParams.destroy();
|
|
|
|
|
|
|
|
|
|
// Misc
|
|
|
|
|
vkFreeCommandBuffers(device, cmdPool, 1, &offScreenCmdBuffer);
|
|
|
|
|
vkDestroySemaphore(device, offscreenSemaphore, nullptr);
|
2017-02-09 21:55:35 +01:00
|
|
|
textures.ssaoNoise.destroy();
|
2016-10-28 21:16:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Create a frame buffer attachment
|
|
|
|
|
void createAttachment(
|
|
|
|
|
VkFormat format,
|
|
|
|
|
VkImageUsageFlagBits usage,
|
|
|
|
|
FrameBufferAttachment *attachment,
|
2016-10-30 13:49:30 +01:00
|
|
|
uint32_t width,
|
|
|
|
|
uint32_t height)
|
2016-10-28 21:16:21 +02:00
|
|
|
{
|
|
|
|
|
VkImageAspectFlags aspectMask = 0;
|
|
|
|
|
VkImageLayout imageLayout;
|
|
|
|
|
|
|
|
|
|
attachment->format = format;
|
|
|
|
|
|
|
|
|
|
if (usage & VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT)
|
|
|
|
|
{
|
|
|
|
|
aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
|
|
|
|
|
imageLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
|
|
|
|
|
}
|
|
|
|
|
if (usage & VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT)
|
|
|
|
|
{
|
|
|
|
|
aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
|
|
|
|
|
imageLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
assert(aspectMask > 0);
|
|
|
|
|
|
2017-02-12 11:12:42 +01:00
|
|
|
VkImageCreateInfo image = vks::initializers::imageCreateInfo();
|
2016-10-28 21:16:21 +02:00
|
|
|
image.imageType = VK_IMAGE_TYPE_2D;
|
|
|
|
|
image.format = format;
|
2016-10-29 13:18:20 +02:00
|
|
|
image.extent.width = width;
|
|
|
|
|
image.extent.height = height;
|
2016-10-28 21:16:21 +02:00
|
|
|
image.extent.depth = 1;
|
|
|
|
|
image.mipLevels = 1;
|
|
|
|
|
image.arrayLayers = 1;
|
|
|
|
|
image.samples = VK_SAMPLE_COUNT_1_BIT;
|
|
|
|
|
image.tiling = VK_IMAGE_TILING_OPTIMAL;
|
|
|
|
|
image.usage = usage | VK_IMAGE_USAGE_SAMPLED_BIT;
|
|
|
|
|
|
2017-02-12 11:12:42 +01:00
|
|
|
VkMemoryAllocateInfo memAlloc = vks::initializers::memoryAllocateInfo();
|
2016-10-28 21:16:21 +02:00
|
|
|
VkMemoryRequirements memReqs;
|
|
|
|
|
|
|
|
|
|
VK_CHECK_RESULT(vkCreateImage(device, &image, nullptr, &attachment->image));
|
|
|
|
|
vkGetImageMemoryRequirements(device, attachment->image, &memReqs);
|
|
|
|
|
memAlloc.allocationSize = memReqs.size;
|
|
|
|
|
memAlloc.memoryTypeIndex = vulkanDevice->getMemoryType(memReqs.memoryTypeBits, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT);
|
|
|
|
|
VK_CHECK_RESULT(vkAllocateMemory(device, &memAlloc, nullptr, &attachment->mem));
|
|
|
|
|
VK_CHECK_RESULT(vkBindImageMemory(device, attachment->image, attachment->mem, 0));
|
|
|
|
|
|
2017-02-12 11:12:42 +01:00
|
|
|
VkImageViewCreateInfo imageView = vks::initializers::imageViewCreateInfo();
|
2016-10-28 21:16:21 +02:00
|
|
|
imageView.viewType = VK_IMAGE_VIEW_TYPE_2D;
|
|
|
|
|
imageView.format = format;
|
|
|
|
|
imageView.subresourceRange = {};
|
|
|
|
|
imageView.subresourceRange.aspectMask = aspectMask;
|
|
|
|
|
imageView.subresourceRange.baseMipLevel = 0;
|
|
|
|
|
imageView.subresourceRange.levelCount = 1;
|
|
|
|
|
imageView.subresourceRange.baseArrayLayer = 0;
|
|
|
|
|
imageView.subresourceRange.layerCount = 1;
|
|
|
|
|
imageView.image = attachment->image;
|
|
|
|
|
VK_CHECK_RESULT(vkCreateImageView(device, &imageView, nullptr, &attachment->view));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void prepareOffscreenFramebuffers()
|
|
|
|
|
{
|
|
|
|
|
// Attachments
|
|
|
|
|
VkCommandBuffer layoutCmd = VulkanExampleBase::createCommandBuffer(VK_COMMAND_BUFFER_LEVEL_PRIMARY, true);
|
2016-10-30 13:49:30 +01:00
|
|
|
|
|
|
|
|
#if defined(__ANDROID__)
|
|
|
|
|
const uint32_t ssaoWidth = width / 2;
|
|
|
|
|
const uint32_t ssaoHeight = height / 2;
|
|
|
|
|
#else
|
|
|
|
|
const uint32_t ssaoWidth = width;
|
|
|
|
|
const uint32_t ssaoHeight = height;
|
|
|
|
|
#endif
|
|
|
|
|
|
2016-10-28 21:16:21 +02:00
|
|
|
frameBuffers.offscreen.setSize(width, height);
|
2016-10-30 13:49:30 +01:00
|
|
|
frameBuffers.ssao.setSize(ssaoWidth, ssaoHeight);
|
2016-10-28 21:16:21 +02:00
|
|
|
frameBuffers.ssaoBlur.setSize(width, height);
|
|
|
|
|
|
|
|
|
|
// Find a suitable depth format
|
|
|
|
|
VkFormat attDepthFormat;
|
|
|
|
|
VkBool32 validDepthFormat = vkTools::getSupportedDepthFormat(physicalDevice, &attDepthFormat);
|
|
|
|
|
assert(validDepthFormat);
|
|
|
|
|
|
|
|
|
|
// G-Buffer
|
2016-10-30 13:49:30 +01:00
|
|
|
createAttachment(VK_FORMAT_R32G32B32A32_SFLOAT, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, &frameBuffers.offscreen.position, width, height); // Position + Depth
|
|
|
|
|
createAttachment(VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, &frameBuffers.offscreen.normal, width, height); // Normals
|
|
|
|
|
createAttachment(VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, &frameBuffers.offscreen.albedo, width, height); // Albedo (color)
|
|
|
|
|
createAttachment(attDepthFormat, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT, &frameBuffers.offscreen.depth, width, height); // Depth
|
2016-10-28 21:16:21 +02:00
|
|
|
|
|
|
|
|
// SSAO
|
2016-10-30 13:49:30 +01:00
|
|
|
createAttachment(VK_FORMAT_R8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, &frameBuffers.ssao.color, ssaoWidth, ssaoHeight); // Color
|
2016-10-28 21:16:21 +02:00
|
|
|
|
|
|
|
|
// SSAO blur
|
2016-10-30 13:49:30 +01:00
|
|
|
createAttachment(VK_FORMAT_R8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, &frameBuffers.ssaoBlur.color, width, height); // Color
|
2016-10-28 21:16:21 +02:00
|
|
|
|
|
|
|
|
VulkanExampleBase::flushCommandBuffer(layoutCmd, queue, true);
|
|
|
|
|
|
|
|
|
|
// Render passes
|
|
|
|
|
|
|
|
|
|
// G-Buffer creation
|
|
|
|
|
{
|
|
|
|
|
std::array<VkAttachmentDescription, 4> attachmentDescs = {};
|
|
|
|
|
|
|
|
|
|
// Init attachment properties
|
|
|
|
|
for (uint32_t i = 0; i < static_cast<uint32_t>(attachmentDescs.size()); i++)
|
|
|
|
|
{
|
|
|
|
|
attachmentDescs[i].samples = VK_SAMPLE_COUNT_1_BIT;
|
|
|
|
|
attachmentDescs[i].loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
|
|
|
|
|
attachmentDescs[i].storeOp = VK_ATTACHMENT_STORE_OP_STORE;
|
|
|
|
|
attachmentDescs[i].stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
|
|
|
|
|
attachmentDescs[i].stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
|
|
|
|
|
attachmentDescs[i].finalLayout = (i == 3) ? VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL : VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Formats
|
|
|
|
|
attachmentDescs[0].format = frameBuffers.offscreen.position.format;
|
|
|
|
|
attachmentDescs[1].format = frameBuffers.offscreen.normal.format;
|
|
|
|
|
attachmentDescs[2].format = frameBuffers.offscreen.albedo.format;
|
|
|
|
|
attachmentDescs[3].format = frameBuffers.offscreen.depth.format;
|
|
|
|
|
|
|
|
|
|
std::vector<VkAttachmentReference> colorReferences;
|
|
|
|
|
colorReferences.push_back({ 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL });
|
|
|
|
|
colorReferences.push_back({ 1, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL });
|
|
|
|
|
colorReferences.push_back({ 2, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL });
|
|
|
|
|
|
|
|
|
|
VkAttachmentReference depthReference = {};
|
|
|
|
|
depthReference.attachment = 3;
|
|
|
|
|
depthReference.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
|
|
|
|
|
|
|
|
|
|
VkSubpassDescription subpass = {};
|
|
|
|
|
subpass.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS;
|
|
|
|
|
subpass.pColorAttachments = colorReferences.data();
|
|
|
|
|
subpass.colorAttachmentCount = static_cast<uint32_t>(colorReferences.size());
|
|
|
|
|
subpass.pDepthStencilAttachment = &depthReference;
|
|
|
|
|
|
|
|
|
|
// Use subpass dependencies for attachment layout transitions
|
|
|
|
|
std::array<VkSubpassDependency, 2> dependencies;
|
|
|
|
|
|
|
|
|
|
dependencies[0].srcSubpass = VK_SUBPASS_EXTERNAL;
|
|
|
|
|
dependencies[0].dstSubpass = 0;
|
|
|
|
|
dependencies[0].srcStageMask = VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT;
|
|
|
|
|
dependencies[0].dstStageMask = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT;
|
|
|
|
|
dependencies[0].srcAccessMask = VK_ACCESS_MEMORY_READ_BIT;
|
|
|
|
|
dependencies[0].dstAccessMask = VK_ACCESS_COLOR_ATTACHMENT_READ_BIT | VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT;
|
|
|
|
|
dependencies[0].dependencyFlags = VK_DEPENDENCY_BY_REGION_BIT;
|
|
|
|
|
|
|
|
|
|
dependencies[1].srcSubpass = 0;
|
|
|
|
|
dependencies[1].dstSubpass = VK_SUBPASS_EXTERNAL;
|
|
|
|
|
dependencies[1].srcStageMask = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT;
|
|
|
|
|
dependencies[1].dstStageMask = VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT;
|
|
|
|
|
dependencies[1].srcAccessMask = VK_ACCESS_COLOR_ATTACHMENT_READ_BIT | VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT;
|
|
|
|
|
dependencies[1].dstAccessMask = VK_ACCESS_MEMORY_READ_BIT;
|
|
|
|
|
dependencies[1].dependencyFlags = VK_DEPENDENCY_BY_REGION_BIT;
|
|
|
|
|
|
|
|
|
|
VkRenderPassCreateInfo renderPassInfo = {};
|
|
|
|
|
renderPassInfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
|
|
|
|
|
renderPassInfo.pAttachments = attachmentDescs.data();
|
|
|
|
|
renderPassInfo.attachmentCount = static_cast<uint32_t>(attachmentDescs.size());
|
|
|
|
|
renderPassInfo.subpassCount = 1;
|
|
|
|
|
renderPassInfo.pSubpasses = &subpass;
|
|
|
|
|
renderPassInfo.dependencyCount = 2;
|
|
|
|
|
renderPassInfo.pDependencies = dependencies.data();
|
|
|
|
|
VK_CHECK_RESULT(vkCreateRenderPass(device, &renderPassInfo, nullptr, &frameBuffers.offscreen.renderPass));
|
|
|
|
|
|
|
|
|
|
std::array<VkImageView, 4> attachments;
|
|
|
|
|
attachments[0] = frameBuffers.offscreen.position.view;
|
|
|
|
|
attachments[1] = frameBuffers.offscreen.normal.view;
|
|
|
|
|
attachments[2] = frameBuffers.offscreen.albedo.view;
|
|
|
|
|
attachments[3] = frameBuffers.offscreen.depth.view;
|
|
|
|
|
|
2017-02-12 11:12:42 +01:00
|
|
|
VkFramebufferCreateInfo fbufCreateInfo = vks::initializers::framebufferCreateInfo();
|
2016-10-28 21:16:21 +02:00
|
|
|
fbufCreateInfo.renderPass = frameBuffers.offscreen.renderPass;
|
|
|
|
|
fbufCreateInfo.pAttachments = attachments.data();
|
|
|
|
|
fbufCreateInfo.attachmentCount = static_cast<uint32_t>(attachments.size());
|
|
|
|
|
fbufCreateInfo.width = frameBuffers.offscreen.width;
|
|
|
|
|
fbufCreateInfo.height = frameBuffers.offscreen.height;
|
|
|
|
|
fbufCreateInfo.layers = 1;
|
|
|
|
|
VK_CHECK_RESULT(vkCreateFramebuffer(device, &fbufCreateInfo, nullptr, &frameBuffers.offscreen.frameBuffer));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// SSAO
|
|
|
|
|
{
|
|
|
|
|
VkAttachmentDescription attachmentDescription{};
|
|
|
|
|
attachmentDescription.format = frameBuffers.ssao.color.format;
|
|
|
|
|
attachmentDescription.samples = VK_SAMPLE_COUNT_1_BIT;
|
|
|
|
|
attachmentDescription.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
|
|
|
|
|
attachmentDescription.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
|
|
|
|
|
attachmentDescription.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
|
|
|
|
|
attachmentDescription.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
|
|
|
|
|
attachmentDescription.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
|
|
|
|
|
attachmentDescription.finalLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
|
|
|
|
|
|
|
|
|
|
VkAttachmentReference colorReference = { 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
|
|
|
|
|
|
|
|
|
|
VkSubpassDescription subpass = {};
|
|
|
|
|
subpass.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS;
|
|
|
|
|
subpass.pColorAttachments = &colorReference;
|
|
|
|
|
subpass.colorAttachmentCount = 1;
|
|
|
|
|
|
|
|
|
|
std::array<VkSubpassDependency, 2> dependencies;
|
|
|
|
|
|
|
|
|
|
dependencies[0].srcSubpass = VK_SUBPASS_EXTERNAL;
|
|
|
|
|
dependencies[0].dstSubpass = 0;
|
|
|
|
|
dependencies[0].srcStageMask = VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT;
|
|
|
|
|
dependencies[0].dstStageMask = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT;
|
|
|
|
|
dependencies[0].srcAccessMask = VK_ACCESS_MEMORY_READ_BIT;
|
|
|
|
|
dependencies[0].dstAccessMask = VK_ACCESS_COLOR_ATTACHMENT_READ_BIT | VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT;
|
|
|
|
|
dependencies[0].dependencyFlags = VK_DEPENDENCY_BY_REGION_BIT;
|
|
|
|
|
|
|
|
|
|
dependencies[1].srcSubpass = 0;
|
|
|
|
|
dependencies[1].dstSubpass = VK_SUBPASS_EXTERNAL;
|
|
|
|
|
dependencies[1].srcStageMask = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT;
|
|
|
|
|
dependencies[1].dstStageMask = VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT;
|
|
|
|
|
dependencies[1].srcAccessMask = VK_ACCESS_COLOR_ATTACHMENT_READ_BIT | VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT;
|
|
|
|
|
dependencies[1].dstAccessMask = VK_ACCESS_MEMORY_READ_BIT;
|
|
|
|
|
dependencies[1].dependencyFlags = VK_DEPENDENCY_BY_REGION_BIT;
|
|
|
|
|
|
|
|
|
|
VkRenderPassCreateInfo renderPassInfo = {};
|
|
|
|
|
renderPassInfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
|
|
|
|
|
renderPassInfo.pAttachments = &attachmentDescription;
|
|
|
|
|
renderPassInfo.attachmentCount = 1;
|
|
|
|
|
renderPassInfo.subpassCount = 1;
|
|
|
|
|
renderPassInfo.pSubpasses = &subpass;
|
|
|
|
|
renderPassInfo.dependencyCount = 2;
|
|
|
|
|
renderPassInfo.pDependencies = dependencies.data();
|
|
|
|
|
VK_CHECK_RESULT(vkCreateRenderPass(device, &renderPassInfo, nullptr, &frameBuffers.ssao.renderPass));
|
|
|
|
|
|
2017-02-12 11:12:42 +01:00
|
|
|
VkFramebufferCreateInfo fbufCreateInfo = vks::initializers::framebufferCreateInfo();
|
2016-10-28 21:16:21 +02:00
|
|
|
fbufCreateInfo.renderPass = frameBuffers.ssao.renderPass;
|
|
|
|
|
fbufCreateInfo.pAttachments = &frameBuffers.ssao.color.view;
|
|
|
|
|
fbufCreateInfo.attachmentCount = 1;
|
|
|
|
|
fbufCreateInfo.width = frameBuffers.ssao.width;
|
|
|
|
|
fbufCreateInfo.height = frameBuffers.ssao.height;
|
|
|
|
|
fbufCreateInfo.layers = 1;
|
|
|
|
|
VK_CHECK_RESULT(vkCreateFramebuffer(device, &fbufCreateInfo, nullptr, &frameBuffers.ssao.frameBuffer));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// SSAO Blur
|
|
|
|
|
{
|
|
|
|
|
VkAttachmentDescription attachmentDescription{};
|
|
|
|
|
attachmentDescription.format = frameBuffers.ssao.color.format;
|
|
|
|
|
attachmentDescription.samples = VK_SAMPLE_COUNT_1_BIT;
|
|
|
|
|
attachmentDescription.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
|
|
|
|
|
attachmentDescription.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
|
|
|
|
|
attachmentDescription.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
|
|
|
|
|
attachmentDescription.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
|
|
|
|
|
attachmentDescription.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
|
|
|
|
|
attachmentDescription.finalLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
|
|
|
|
|
|
|
|
|
|
VkAttachmentReference colorReference = { 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
|
|
|
|
|
|
|
|
|
|
VkSubpassDescription subpass = {};
|
|
|
|
|
subpass.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS;
|
|
|
|
|
subpass.pColorAttachments = &colorReference;
|
|
|
|
|
subpass.colorAttachmentCount = 1;
|
|
|
|
|
|
|
|
|
|
std::array<VkSubpassDependency, 2> dependencies;
|
|
|
|
|
|
|
|
|
|
dependencies[0].srcSubpass = VK_SUBPASS_EXTERNAL;
|
|
|
|
|
dependencies[0].dstSubpass = 0;
|
|
|
|
|
dependencies[0].srcStageMask = VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT;
|
|
|
|
|
dependencies[0].dstStageMask = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT;
|
|
|
|
|
dependencies[0].srcAccessMask = VK_ACCESS_MEMORY_READ_BIT;
|
|
|
|
|
dependencies[0].dstAccessMask = VK_ACCESS_COLOR_ATTACHMENT_READ_BIT | VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT;
|
|
|
|
|
dependencies[0].dependencyFlags = VK_DEPENDENCY_BY_REGION_BIT;
|
|
|
|
|
|
|
|
|
|
dependencies[1].srcSubpass = 0;
|
|
|
|
|
dependencies[1].dstSubpass = VK_SUBPASS_EXTERNAL;
|
|
|
|
|
dependencies[1].srcStageMask = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT;
|
|
|
|
|
dependencies[1].dstStageMask = VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT;
|
|
|
|
|
dependencies[1].srcAccessMask = VK_ACCESS_COLOR_ATTACHMENT_READ_BIT | VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT;
|
|
|
|
|
dependencies[1].dstAccessMask = VK_ACCESS_MEMORY_READ_BIT;
|
|
|
|
|
dependencies[1].dependencyFlags = VK_DEPENDENCY_BY_REGION_BIT;
|
|
|
|
|
|
|
|
|
|
VkRenderPassCreateInfo renderPassInfo = {};
|
|
|
|
|
renderPassInfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
|
|
|
|
|
renderPassInfo.pAttachments = &attachmentDescription;
|
|
|
|
|
renderPassInfo.attachmentCount = 1;
|
|
|
|
|
renderPassInfo.subpassCount = 1;
|
|
|
|
|
renderPassInfo.pSubpasses = &subpass;
|
|
|
|
|
renderPassInfo.dependencyCount = 2;
|
|
|
|
|
renderPassInfo.pDependencies = dependencies.data();
|
|
|
|
|
VK_CHECK_RESULT(vkCreateRenderPass(device, &renderPassInfo, nullptr, &frameBuffers.ssaoBlur.renderPass));
|
|
|
|
|
|
2017-02-12 11:12:42 +01:00
|
|
|
VkFramebufferCreateInfo fbufCreateInfo = vks::initializers::framebufferCreateInfo();
|
2016-10-28 21:16:21 +02:00
|
|
|
fbufCreateInfo.renderPass = frameBuffers.ssaoBlur.renderPass;
|
|
|
|
|
fbufCreateInfo.pAttachments = &frameBuffers.ssaoBlur.color.view;
|
|
|
|
|
fbufCreateInfo.attachmentCount = 1;
|
|
|
|
|
fbufCreateInfo.width = frameBuffers.ssaoBlur.width;
|
|
|
|
|
fbufCreateInfo.height = frameBuffers.ssaoBlur.height;
|
|
|
|
|
fbufCreateInfo.layers = 1;
|
|
|
|
|
VK_CHECK_RESULT(vkCreateFramebuffer(device, &fbufCreateInfo, nullptr, &frameBuffers.ssaoBlur.frameBuffer));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Shared sampler used for all color attachments
|
2017-02-12 11:12:42 +01:00
|
|
|
VkSamplerCreateInfo sampler = vks::initializers::samplerCreateInfo();
|
2016-10-28 21:16:21 +02:00
|
|
|
sampler.magFilter = VK_FILTER_NEAREST;
|
|
|
|
|
sampler.minFilter = VK_FILTER_NEAREST;
|
|
|
|
|
sampler.mipmapMode = VK_SAMPLER_MIPMAP_MODE_LINEAR;
|
|
|
|
|
sampler.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
|
|
|
|
|
sampler.addressModeV = sampler.addressModeU;
|
|
|
|
|
sampler.addressModeW = sampler.addressModeU;
|
|
|
|
|
sampler.mipLodBias = 0.0f;
|
|
|
|
|
sampler.maxAnisotropy = 0;
|
|
|
|
|
sampler.minLod = 0.0f;
|
|
|
|
|
sampler.maxLod = 1.0f;
|
|
|
|
|
sampler.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
|
|
|
|
|
VK_CHECK_RESULT(vkCreateSampler(device, &sampler, nullptr, &colorSampler));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Build command buffer for rendering the scene to the offscreen frame buffer attachments
|
|
|
|
|
void buildDeferredCommandBuffer()
|
|
|
|
|
{
|
|
|
|
|
VkDeviceSize offsets[1] = { 0 };
|
|
|
|
|
|
|
|
|
|
if (offScreenCmdBuffer == VK_NULL_HANDLE)
|
|
|
|
|
{
|
|
|
|
|
offScreenCmdBuffer = VulkanExampleBase::createCommandBuffer(VK_COMMAND_BUFFER_LEVEL_PRIMARY, false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Create a semaphore used to synchronize offscreen rendering and usage
|
2017-02-12 11:12:42 +01:00
|
|
|
VkSemaphoreCreateInfo semaphoreCreateInfo = vks::initializers::semaphoreCreateInfo();
|
2016-10-28 21:16:21 +02:00
|
|
|
VK_CHECK_RESULT(vkCreateSemaphore(device, &semaphoreCreateInfo, nullptr, &offscreenSemaphore));
|
|
|
|
|
|
2017-02-12 11:12:42 +01:00
|
|
|
VkCommandBufferBeginInfo cmdBufInfo = vks::initializers::commandBufferBeginInfo();
|
2016-10-28 21:16:21 +02:00
|
|
|
|
|
|
|
|
// Clear values for all attachments written in the fragment sahder
|
|
|
|
|
std::vector<VkClearValue> clearValues(4);
|
|
|
|
|
clearValues[0].color = { { 0.0f, 0.0f, 0.0f, 1.0f } };
|
|
|
|
|
clearValues[1].color = { { 0.0f, 0.0f, 0.0f, 1.0f } };
|
|
|
|
|
clearValues[2].color = { { 0.0f, 0.0f, 0.0f, 1.0f } };
|
|
|
|
|
clearValues[3].depthStencil = { 1.0f, 0 };
|
|
|
|
|
|
2017-02-12 11:12:42 +01:00
|
|
|
VkRenderPassBeginInfo renderPassBeginInfo = vks::initializers::renderPassBeginInfo();
|
2016-10-28 21:16:21 +02:00
|
|
|
renderPassBeginInfo.renderPass = frameBuffers.offscreen.renderPass;
|
|
|
|
|
renderPassBeginInfo.framebuffer = frameBuffers.offscreen.frameBuffer;
|
|
|
|
|
renderPassBeginInfo.renderArea.extent.width = frameBuffers.offscreen.width;
|
|
|
|
|
renderPassBeginInfo.renderArea.extent.height = frameBuffers.offscreen.height;
|
|
|
|
|
renderPassBeginInfo.clearValueCount = static_cast<uint32_t>(clearValues.size());
|
|
|
|
|
renderPassBeginInfo.pClearValues = clearValues.data();
|
|
|
|
|
|
|
|
|
|
VK_CHECK_RESULT(vkBeginCommandBuffer(offScreenCmdBuffer, &cmdBufInfo));
|
|
|
|
|
|
|
|
|
|
// First pass: Fill G-Buffer components (positions+depth, normals, albedo) using MRT
|
|
|
|
|
// -------------------------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
vkCmdBeginRenderPass(offScreenCmdBuffer, &renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
|
|
|
|
|
|
2017-02-12 11:12:42 +01:00
|
|
|
VkViewport viewport = vks::initializers::viewport((float)frameBuffers.offscreen.width, (float)frameBuffers.offscreen.height, 0.0f, 1.0f);
|
2016-10-28 21:16:21 +02:00
|
|
|
vkCmdSetViewport(offScreenCmdBuffer, 0, 1, &viewport);
|
|
|
|
|
|
2017-02-12 11:12:42 +01:00
|
|
|
VkRect2D scissor = vks::initializers::rect2D(frameBuffers.offscreen.width, frameBuffers.offscreen.height, 0, 0);
|
2016-10-28 21:16:21 +02:00
|
|
|
vkCmdSetScissor(offScreenCmdBuffer, 0, 1, &scissor);
|
|
|
|
|
|
|
|
|
|
vkCmdBindPipeline(offScreenCmdBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, pipelines.offscreen);
|
|
|
|
|
|
|
|
|
|
vkCmdBindDescriptorSets(offScreenCmdBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, pipelineLayouts.gBuffer, 0, 1, &descriptorSets.floor, 0, NULL);
|
2017-02-11 14:18:24 +01:00
|
|
|
vkCmdBindVertexBuffers(offScreenCmdBuffer, VERTEX_BUFFER_BIND_ID, 1, &models.scene.vertices.buffer, offsets);
|
|
|
|
|
vkCmdBindIndexBuffer(offScreenCmdBuffer, models.scene.indices.buffer, 0, VK_INDEX_TYPE_UINT32);
|
|
|
|
|
vkCmdDrawIndexed(offScreenCmdBuffer, models.scene.indexCount, 1, 0, 0, 0);
|
2016-10-28 21:16:21 +02:00
|
|
|
|
|
|
|
|
vkCmdEndRenderPass(offScreenCmdBuffer);
|
|
|
|
|
|
|
|
|
|
// Second pass: SSAO generation
|
|
|
|
|
// -------------------------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
clearValues[0].color = { { 0.0f, 0.0f, 0.0f, 1.0f } };
|
|
|
|
|
clearValues[1].depthStencil = { 1.0f, 0 };
|
|
|
|
|
|
|
|
|
|
renderPassBeginInfo.framebuffer = frameBuffers.ssao.frameBuffer;
|
|
|
|
|
renderPassBeginInfo.renderPass = frameBuffers.ssao.renderPass;
|
|
|
|
|
renderPassBeginInfo.renderArea.extent.width = frameBuffers.ssao.width;
|
|
|
|
|
renderPassBeginInfo.renderArea.extent.height = frameBuffers.ssao.height;
|
|
|
|
|
renderPassBeginInfo.clearValueCount = 2;
|
|
|
|
|
renderPassBeginInfo.pClearValues = clearValues.data();
|
|
|
|
|
|
|
|
|
|
vkCmdBeginRenderPass(offScreenCmdBuffer, &renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
|
|
|
|
|
|
2017-02-12 11:12:42 +01:00
|
|
|
viewport = vks::initializers::viewport((float)frameBuffers.ssao.width, (float)frameBuffers.ssao.height, 0.0f, 1.0f);
|
2016-10-28 21:16:21 +02:00
|
|
|
vkCmdSetViewport(offScreenCmdBuffer, 0, 1, &viewport);
|
2017-02-12 11:12:42 +01:00
|
|
|
scissor = vks::initializers::rect2D(frameBuffers.ssao.width, frameBuffers.ssao.height, 0, 0);
|
2016-10-28 21:16:21 +02:00
|
|
|
vkCmdSetScissor(offScreenCmdBuffer, 0, 1, &scissor);
|
|
|
|
|
|
|
|
|
|
vkCmdBindDescriptorSets(offScreenCmdBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, pipelineLayouts.ssao, 0, 1, &descriptorSets.ssao, 0, NULL);
|
|
|
|
|
vkCmdBindPipeline(offScreenCmdBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, pipelines.ssao);
|
|
|
|
|
vkCmdDraw(offScreenCmdBuffer, 3, 1, 0, 0);
|
|
|
|
|
|
|
|
|
|
vkCmdEndRenderPass(offScreenCmdBuffer);
|
|
|
|
|
|
|
|
|
|
// Third pass: SSAO blur
|
|
|
|
|
// -------------------------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
renderPassBeginInfo.framebuffer = frameBuffers.ssaoBlur.frameBuffer;
|
|
|
|
|
renderPassBeginInfo.renderPass = frameBuffers.ssaoBlur.renderPass;
|
|
|
|
|
renderPassBeginInfo.renderArea.extent.width = frameBuffers.ssaoBlur.width;
|
|
|
|
|
renderPassBeginInfo.renderArea.extent.height = frameBuffers.ssaoBlur.height;
|
|
|
|
|
|
|
|
|
|
vkCmdBeginRenderPass(offScreenCmdBuffer, &renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
|
|
|
|
|
|
2017-02-12 11:12:42 +01:00
|
|
|
viewport = vks::initializers::viewport((float)frameBuffers.ssaoBlur.width, (float)frameBuffers.ssaoBlur.height, 0.0f, 1.0f);
|
2016-10-28 21:16:21 +02:00
|
|
|
vkCmdSetViewport(offScreenCmdBuffer, 0, 1, &viewport);
|
2017-02-12 11:12:42 +01:00
|
|
|
scissor = vks::initializers::rect2D(frameBuffers.ssaoBlur.width, frameBuffers.ssaoBlur.height, 0, 0);
|
2016-10-28 21:16:21 +02:00
|
|
|
vkCmdSetScissor(offScreenCmdBuffer, 0, 1, &scissor);
|
|
|
|
|
|
|
|
|
|
vkCmdBindDescriptorSets(offScreenCmdBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, pipelineLayouts.ssaoBlur, 0, 1, &descriptorSets.ssaoBlur, 0, NULL);
|
|
|
|
|
vkCmdBindPipeline(offScreenCmdBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, pipelines.ssaoBlur);
|
|
|
|
|
vkCmdDraw(offScreenCmdBuffer, 3, 1, 0, 0);
|
|
|
|
|
|
|
|
|
|
vkCmdEndRenderPass(offScreenCmdBuffer);
|
|
|
|
|
|
|
|
|
|
VK_CHECK_RESULT(vkEndCommandBuffer(offScreenCmdBuffer));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void loadAssets()
|
|
|
|
|
{
|
2017-02-11 14:18:24 +01:00
|
|
|
vks::ModelCreateInfo modelCreateInfo;
|
|
|
|
|
modelCreateInfo.scale = glm::vec3(0.5f);
|
|
|
|
|
modelCreateInfo.uvscale = glm::vec2(1.0f);
|
|
|
|
|
modelCreateInfo.center = glm::vec3(0.0f, 0.0f, 0.0f);
|
|
|
|
|
models.scene.loadFromFile(getAssetPath() + "models/sibenik/sibenik.dae", vertexLayout, &modelCreateInfo, vulkanDevice, queue);
|
2016-10-28 21:16:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void reBuildCommandBuffers()
|
|
|
|
|
{
|
|
|
|
|
if (!checkCommandBuffers())
|
|
|
|
|
{
|
|
|
|
|
destroyCommandBuffers();
|
|
|
|
|
createCommandBuffers();
|
|
|
|
|
}
|
|
|
|
|
buildCommandBuffers();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void buildCommandBuffers()
|
|
|
|
|
{
|
2017-02-12 11:12:42 +01:00
|
|
|
VkCommandBufferBeginInfo cmdBufInfo = vks::initializers::commandBufferBeginInfo();
|
2016-10-28 21:16:21 +02:00
|
|
|
|
|
|
|
|
VkClearValue clearValues[2];
|
|
|
|
|
clearValues[0].color = { { 0.0f, 0.0f, 0.0f, 0.0f } };
|
|
|
|
|
clearValues[1].depthStencil = { 1.0f, 0 };
|
|
|
|
|
|
2017-02-12 11:12:42 +01:00
|
|
|
VkRenderPassBeginInfo renderPassBeginInfo = vks::initializers::renderPassBeginInfo();
|
2016-10-28 21:16:21 +02:00
|
|
|
renderPassBeginInfo.renderPass = renderPass;
|
|
|
|
|
renderPassBeginInfo.renderArea.offset.x = 0;
|
|
|
|
|
renderPassBeginInfo.renderArea.offset.y = 0;
|
|
|
|
|
renderPassBeginInfo.renderArea.extent.width = width;
|
|
|
|
|
renderPassBeginInfo.renderArea.extent.height = height;
|
|
|
|
|
renderPassBeginInfo.clearValueCount = 2;
|
|
|
|
|
renderPassBeginInfo.pClearValues = clearValues;
|
|
|
|
|
|
|
|
|
|
for (int32_t i = 0; i < drawCmdBuffers.size(); ++i)
|
|
|
|
|
{
|
|
|
|
|
// Set target frame buffer
|
|
|
|
|
renderPassBeginInfo.framebuffer = VulkanExampleBase::frameBuffers[i];
|
|
|
|
|
|
|
|
|
|
VK_CHECK_RESULT(vkBeginCommandBuffer(drawCmdBuffers[i], &cmdBufInfo));
|
|
|
|
|
|
|
|
|
|
vkCmdBeginRenderPass(drawCmdBuffers[i], &renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
|
|
|
|
|
|
2017-02-12 11:12:42 +01:00
|
|
|
VkViewport viewport = vks::initializers::viewport((float)width, (float)height, 0.0f, 1.0f);
|
2016-10-28 21:16:21 +02:00
|
|
|
vkCmdSetViewport(drawCmdBuffers[i], 0, 1, &viewport);
|
|
|
|
|
|
2017-02-12 11:12:42 +01:00
|
|
|
VkRect2D scissor = vks::initializers::rect2D(width, height, 0, 0);
|
2016-10-28 21:16:21 +02:00
|
|
|
vkCmdSetScissor(drawCmdBuffers[i], 0, 1, &scissor);
|
|
|
|
|
|
|
|
|
|
VkDeviceSize offsets[1] = { 0 };
|
|
|
|
|
vkCmdBindDescriptorSets(drawCmdBuffers[i], VK_PIPELINE_BIND_POINT_GRAPHICS, pipelineLayouts.composition, 0, 1, &descriptorSets.composition, 0, NULL);
|
|
|
|
|
|
|
|
|
|
// Final composition pass
|
|
|
|
|
vkCmdBindPipeline(drawCmdBuffers[i], VK_PIPELINE_BIND_POINT_GRAPHICS, pipelines.composition);
|
|
|
|
|
vkCmdDraw(drawCmdBuffers[i], 3, 1, 0, 0);
|
|
|
|
|
|
|
|
|
|
vkCmdEndRenderPass(drawCmdBuffers[i]);
|
|
|
|
|
|
|
|
|
|
VK_CHECK_RESULT(vkEndCommandBuffer(drawCmdBuffers[i]));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void setupVertexDescriptions()
|
|
|
|
|
{
|
|
|
|
|
// Binding description
|
|
|
|
|
vertices.bindingDescriptions.resize(1);
|
|
|
|
|
vertices.bindingDescriptions[0] =
|
2017-02-12 11:12:42 +01:00
|
|
|
vks::initializers::vertexInputBindingDescription(
|
2016-10-28 21:16:21 +02:00
|
|
|
VERTEX_BUFFER_BIND_ID,
|
2017-02-11 14:18:24 +01:00
|
|
|
vertexLayout.stride(),
|
2016-10-28 21:16:21 +02:00
|
|
|
VK_VERTEX_INPUT_RATE_VERTEX);
|
|
|
|
|
|
|
|
|
|
// Attribute descriptions
|
|
|
|
|
vertices.attributeDescriptions.resize(4);
|
|
|
|
|
// Location 0: Position
|
|
|
|
|
vertices.attributeDescriptions[0] =
|
2017-02-12 11:12:42 +01:00
|
|
|
vks::initializers::vertexInputAttributeDescription(
|
2016-10-28 21:16:21 +02:00
|
|
|
VERTEX_BUFFER_BIND_ID,
|
|
|
|
|
0,
|
|
|
|
|
VK_FORMAT_R32G32B32_SFLOAT,
|
|
|
|
|
0);
|
|
|
|
|
// Location 1: Texture coordinates
|
|
|
|
|
vertices.attributeDescriptions[1] =
|
2017-02-12 11:12:42 +01:00
|
|
|
vks::initializers::vertexInputAttributeDescription(
|
2016-10-28 21:16:21 +02:00
|
|
|
VERTEX_BUFFER_BIND_ID,
|
|
|
|
|
1,
|
|
|
|
|
VK_FORMAT_R32G32_SFLOAT,
|
|
|
|
|
sizeof(float) * 3);
|
|
|
|
|
// Location 2: Color
|
|
|
|
|
vertices.attributeDescriptions[2] =
|
2017-02-12 11:12:42 +01:00
|
|
|
vks::initializers::vertexInputAttributeDescription(
|
2016-10-28 21:16:21 +02:00
|
|
|
VERTEX_BUFFER_BIND_ID,
|
|
|
|
|
2,
|
|
|
|
|
VK_FORMAT_R32G32B32_SFLOAT,
|
|
|
|
|
sizeof(float) * 5);
|
|
|
|
|
// Location 3: Normal
|
|
|
|
|
vertices.attributeDescriptions[3] =
|
2017-02-12 11:12:42 +01:00
|
|
|
vks::initializers::vertexInputAttributeDescription(
|
2016-10-28 21:16:21 +02:00
|
|
|
VERTEX_BUFFER_BIND_ID,
|
|
|
|
|
3,
|
|
|
|
|
VK_FORMAT_R32G32B32_SFLOAT,
|
|
|
|
|
sizeof(float) * 8);
|
|
|
|
|
|
2017-02-12 11:12:42 +01:00
|
|
|
vertices.inputState = vks::initializers::pipelineVertexInputStateCreateInfo();
|
2016-10-28 21:16:21 +02:00
|
|
|
vertices.inputState.vertexBindingDescriptionCount = static_cast<uint32_t>(vertices.bindingDescriptions.size());
|
|
|
|
|
vertices.inputState.pVertexBindingDescriptions = vertices.bindingDescriptions.data();
|
|
|
|
|
vertices.inputState.vertexAttributeDescriptionCount = static_cast<uint32_t>(vertices.attributeDescriptions.size());
|
|
|
|
|
vertices.inputState.pVertexAttributeDescriptions = vertices.attributeDescriptions.data();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void setupDescriptorPool()
|
|
|
|
|
{
|
|
|
|
|
std::vector<VkDescriptorPoolSize> poolSizes =
|
|
|
|
|
{
|
2017-02-12 11:12:42 +01:00
|
|
|
vks::initializers::descriptorPoolSize(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, 10),
|
|
|
|
|
vks::initializers::descriptorPoolSize(VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 12)
|
2016-10-28 21:16:21 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
VkDescriptorPoolCreateInfo descriptorPoolInfo =
|
2017-02-12 11:12:42 +01:00
|
|
|
vks::initializers::descriptorPoolCreateInfo(
|
2016-10-28 21:16:21 +02:00
|
|
|
static_cast<uint32_t>(poolSizes.size()),
|
|
|
|
|
poolSizes.data(),
|
|
|
|
|
descriptorSets.count);
|
|
|
|
|
|
|
|
|
|
VK_CHECK_RESULT(vkCreateDescriptorPool(device, &descriptorPoolInfo, nullptr, &descriptorPool));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void setupLayoutsAndDescriptors()
|
|
|
|
|
{
|
|
|
|
|
std::vector<VkDescriptorSetLayoutBinding> setLayoutBindings;
|
|
|
|
|
VkDescriptorSetLayoutCreateInfo setLayoutCreateInfo;
|
2017-02-12 11:12:42 +01:00
|
|
|
VkPipelineLayoutCreateInfo pipelineLayoutCreateInfo = vks::initializers::pipelineLayoutCreateInfo();
|
|
|
|
|
VkDescriptorSetAllocateInfo descriptorAllocInfo = vks::initializers::descriptorSetAllocateInfo(descriptorPool, nullptr, 1);
|
2016-10-28 21:16:21 +02:00
|
|
|
std::vector<VkWriteDescriptorSet> writeDescriptorSets;
|
|
|
|
|
std::vector<VkDescriptorImageInfo> imageDescriptors;
|
|
|
|
|
|
|
|
|
|
// G-Buffer creation (offscreen scene rendering)
|
|
|
|
|
setLayoutBindings = {
|
2017-02-12 11:12:42 +01:00
|
|
|
vks::initializers::descriptorSetLayoutBinding(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, VK_SHADER_STAGE_VERTEX_BIT, 0), // VS UBO
|
|
|
|
|
vks::initializers::descriptorSetLayoutBinding(VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, VK_SHADER_STAGE_FRAGMENT_BIT, 1), // FS Color
|
2016-10-28 21:16:21 +02:00
|
|
|
};
|
2017-02-12 11:12:42 +01:00
|
|
|
setLayoutCreateInfo = vks::initializers::descriptorSetLayoutCreateInfo(setLayoutBindings.data(), static_cast<uint32_t>(setLayoutBindings.size()));
|
2016-10-28 21:16:21 +02:00
|
|
|
VK_CHECK_RESULT(vkCreateDescriptorSetLayout(device, &setLayoutCreateInfo, nullptr, &descriptorSetLayouts.gBuffer));
|
|
|
|
|
pipelineLayoutCreateInfo.pSetLayouts = &descriptorSetLayouts.gBuffer;
|
|
|
|
|
VK_CHECK_RESULT(vkCreatePipelineLayout(device, &pipelineLayoutCreateInfo, nullptr, &pipelineLayouts.gBuffer));
|
|
|
|
|
descriptorAllocInfo.pSetLayouts = &descriptorSetLayouts.gBuffer;
|
|
|
|
|
VK_CHECK_RESULT(vkAllocateDescriptorSets(device, &descriptorAllocInfo, &descriptorSets.floor));
|
|
|
|
|
writeDescriptorSets = {
|
2017-02-12 11:12:42 +01:00
|
|
|
vks::initializers::writeDescriptorSet(descriptorSets.floor, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, 0, &uniformBuffers.sceneMatrices.descriptor),
|
2016-10-28 21:16:21 +02:00
|
|
|
};
|
|
|
|
|
vkUpdateDescriptorSets(device, static_cast<uint32_t>(writeDescriptorSets.size()), writeDescriptorSets.data(), 0, NULL);
|
|
|
|
|
|
|
|
|
|
// SSAO Generation
|
|
|
|
|
setLayoutBindings = {
|
2017-02-12 11:12:42 +01:00
|
|
|
vks::initializers::descriptorSetLayoutBinding(VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, VK_SHADER_STAGE_FRAGMENT_BIT, 0), // FS Position+Depth
|
|
|
|
|
vks::initializers::descriptorSetLayoutBinding(VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, VK_SHADER_STAGE_FRAGMENT_BIT, 1), // FS Normals
|
|
|
|
|
vks::initializers::descriptorSetLayoutBinding(VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, VK_SHADER_STAGE_FRAGMENT_BIT, 2), // FS SSAO Noise
|
|
|
|
|
vks::initializers::descriptorSetLayoutBinding(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, VK_SHADER_STAGE_FRAGMENT_BIT, 3), // FS SSAO Kernel UBO
|
|
|
|
|
vks::initializers::descriptorSetLayoutBinding(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, VK_SHADER_STAGE_FRAGMENT_BIT, 4), // FS Params UBO
|
2016-10-28 21:16:21 +02:00
|
|
|
};
|
2017-02-12 11:12:42 +01:00
|
|
|
setLayoutCreateInfo = vks::initializers::descriptorSetLayoutCreateInfo(setLayoutBindings.data(), static_cast<uint32_t>(setLayoutBindings.size()));
|
2016-10-28 21:16:21 +02:00
|
|
|
VK_CHECK_RESULT(vkCreateDescriptorSetLayout(device, &setLayoutCreateInfo, nullptr, &descriptorSetLayouts.ssao));
|
|
|
|
|
pipelineLayoutCreateInfo.pSetLayouts = &descriptorSetLayouts.ssao;
|
|
|
|
|
VK_CHECK_RESULT(vkCreatePipelineLayout(device, &pipelineLayoutCreateInfo, nullptr, &pipelineLayouts.ssao));
|
|
|
|
|
descriptorAllocInfo.pSetLayouts = &descriptorSetLayouts.ssao;
|
|
|
|
|
VK_CHECK_RESULT(vkAllocateDescriptorSets(device, &descriptorAllocInfo, &descriptorSets.ssao));
|
|
|
|
|
imageDescriptors = {
|
2017-02-12 11:12:42 +01:00
|
|
|
vks::initializers::descriptorImageInfo(colorSampler, frameBuffers.offscreen.position.view, VK_IMAGE_LAYOUT_GENERAL),
|
|
|
|
|
vks::initializers::descriptorImageInfo(colorSampler, frameBuffers.offscreen.normal.view, VK_IMAGE_LAYOUT_GENERAL),
|
2016-10-28 21:16:21 +02:00
|
|
|
};
|
|
|
|
|
writeDescriptorSets = {
|
2017-02-12 11:12:42 +01:00
|
|
|
vks::initializers::writeDescriptorSet(descriptorSets.ssao, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 0, &imageDescriptors[0]), // FS Position+Depth
|
|
|
|
|
vks::initializers::writeDescriptorSet(descriptorSets.ssao, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, &imageDescriptors[1]), // FS Normals
|
|
|
|
|
vks::initializers::writeDescriptorSet(descriptorSets.ssao, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 2, &textures.ssaoNoise.descriptor), // FS SSAO Noise
|
|
|
|
|
vks::initializers::writeDescriptorSet(descriptorSets.ssao, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, 3, &uniformBuffers.ssaoKernel.descriptor), // FS SSAO Kernel UBO
|
|
|
|
|
vks::initializers::writeDescriptorSet(descriptorSets.ssao, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, 4, &uniformBuffers.ssaoParams.descriptor), // FS SSAO Params UBO
|
2016-10-28 21:16:21 +02:00
|
|
|
};
|
|
|
|
|
vkUpdateDescriptorSets(device, static_cast<uint32_t>(writeDescriptorSets.size()), writeDescriptorSets.data(), 0, NULL);
|
|
|
|
|
|
|
|
|
|
// SSAO Blur
|
|
|
|
|
setLayoutBindings = {
|
2017-02-12 11:12:42 +01:00
|
|
|
vks::initializers::descriptorSetLayoutBinding(VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, VK_SHADER_STAGE_FRAGMENT_BIT, 0), // FS Sampler SSAO
|
2016-10-28 21:16:21 +02:00
|
|
|
};
|
2017-02-12 11:12:42 +01:00
|
|
|
setLayoutCreateInfo = vks::initializers::descriptorSetLayoutCreateInfo(setLayoutBindings.data(), static_cast<uint32_t>(setLayoutBindings.size()));
|
2016-10-28 21:16:21 +02:00
|
|
|
VK_CHECK_RESULT(vkCreateDescriptorSetLayout(device, &setLayoutCreateInfo, nullptr, &descriptorSetLayouts.ssaoBlur));
|
|
|
|
|
pipelineLayoutCreateInfo.pSetLayouts = &descriptorSetLayouts.ssaoBlur;
|
|
|
|
|
VK_CHECK_RESULT(vkCreatePipelineLayout(device, &pipelineLayoutCreateInfo, nullptr, &pipelineLayouts.ssaoBlur));
|
|
|
|
|
descriptorAllocInfo.pSetLayouts = &descriptorSetLayouts.ssaoBlur;
|
|
|
|
|
VK_CHECK_RESULT(vkAllocateDescriptorSets(device, &descriptorAllocInfo, &descriptorSets.ssaoBlur));
|
|
|
|
|
// todo
|
|
|
|
|
imageDescriptors = {
|
2017-02-12 11:12:42 +01:00
|
|
|
vks::initializers::descriptorImageInfo(colorSampler, frameBuffers.ssao.color.view, VK_IMAGE_LAYOUT_GENERAL),
|
2016-10-28 21:16:21 +02:00
|
|
|
};
|
|
|
|
|
writeDescriptorSets = {
|
2017-02-12 11:12:42 +01:00
|
|
|
vks::initializers::writeDescriptorSet(descriptorSets.ssaoBlur, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 0, &imageDescriptors[0]),
|
2016-10-28 21:16:21 +02:00
|
|
|
};
|
|
|
|
|
vkUpdateDescriptorSets(device, static_cast<uint32_t>(writeDescriptorSets.size()), writeDescriptorSets.data(), 0, NULL);
|
|
|
|
|
|
|
|
|
|
// Composition
|
|
|
|
|
setLayoutBindings = {
|
2017-02-12 11:12:42 +01:00
|
|
|
vks::initializers::descriptorSetLayoutBinding(VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, VK_SHADER_STAGE_FRAGMENT_BIT, 0), // FS Position+Depth
|
|
|
|
|
vks::initializers::descriptorSetLayoutBinding(VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, VK_SHADER_STAGE_FRAGMENT_BIT, 1), // FS Normals
|
|
|
|
|
vks::initializers::descriptorSetLayoutBinding(VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, VK_SHADER_STAGE_FRAGMENT_BIT, 2), // FS Albedo
|
|
|
|
|
vks::initializers::descriptorSetLayoutBinding(VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, VK_SHADER_STAGE_FRAGMENT_BIT, 3), // FS SSAO
|
|
|
|
|
vks::initializers::descriptorSetLayoutBinding(VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, VK_SHADER_STAGE_FRAGMENT_BIT, 4), // FS SSAO blurred
|
|
|
|
|
vks::initializers::descriptorSetLayoutBinding(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, VK_SHADER_STAGE_FRAGMENT_BIT, 5), // FS Lights UBO
|
2016-10-28 21:16:21 +02:00
|
|
|
};
|
2017-02-12 11:12:42 +01:00
|
|
|
setLayoutCreateInfo = vks::initializers::descriptorSetLayoutCreateInfo(setLayoutBindings.data(), static_cast<uint32_t>(setLayoutBindings.size()));
|
2016-10-28 21:16:21 +02:00
|
|
|
VK_CHECK_RESULT(vkCreateDescriptorSetLayout(device, &setLayoutCreateInfo, nullptr, &descriptorSetLayouts.composition));
|
|
|
|
|
pipelineLayoutCreateInfo.pSetLayouts = &descriptorSetLayouts.composition;
|
|
|
|
|
VK_CHECK_RESULT(vkCreatePipelineLayout(device, &pipelineLayoutCreateInfo, nullptr, &pipelineLayouts.composition));
|
|
|
|
|
descriptorAllocInfo.pSetLayouts = &descriptorSetLayouts.composition;
|
|
|
|
|
VK_CHECK_RESULT(vkAllocateDescriptorSets(device, &descriptorAllocInfo, &descriptorSets.composition));
|
|
|
|
|
imageDescriptors = {
|
2017-02-12 11:12:42 +01:00
|
|
|
vks::initializers::descriptorImageInfo(colorSampler, frameBuffers.offscreen.position.view, VK_IMAGE_LAYOUT_GENERAL),
|
|
|
|
|
vks::initializers::descriptorImageInfo(colorSampler, frameBuffers.offscreen.normal.view, VK_IMAGE_LAYOUT_GENERAL),
|
|
|
|
|
vks::initializers::descriptorImageInfo(colorSampler, frameBuffers.offscreen.albedo.view, VK_IMAGE_LAYOUT_GENERAL),
|
|
|
|
|
vks::initializers::descriptorImageInfo(colorSampler, frameBuffers.ssao.color.view, VK_IMAGE_LAYOUT_GENERAL),
|
|
|
|
|
vks::initializers::descriptorImageInfo(colorSampler, frameBuffers.ssaoBlur.color.view, VK_IMAGE_LAYOUT_GENERAL),
|
2016-10-28 21:16:21 +02:00
|
|
|
};
|
|
|
|
|
writeDescriptorSets = {
|
2017-02-12 11:12:42 +01:00
|
|
|
vks::initializers::writeDescriptorSet(descriptorSets.composition, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 0, &imageDescriptors[0]), // FS Sampler Position+Depth
|
|
|
|
|
vks::initializers::writeDescriptorSet(descriptorSets.composition, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, &imageDescriptors[1]), // FS Sampler Normals
|
|
|
|
|
vks::initializers::writeDescriptorSet(descriptorSets.composition, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 2, &imageDescriptors[2]), // FS Sampler Albedo
|
|
|
|
|
vks::initializers::writeDescriptorSet(descriptorSets.composition, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 3, &imageDescriptors[3]), // FS Sampler SSAO
|
|
|
|
|
vks::initializers::writeDescriptorSet(descriptorSets.composition, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 4, &imageDescriptors[4]), // FS Sampler SSAO blurred
|
|
|
|
|
vks::initializers::writeDescriptorSet(descriptorSets.composition, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, 5, &uniformBuffers.ssaoParams.descriptor), // FS SSAO Params UBO
|
2016-10-28 21:16:21 +02:00
|
|
|
};
|
|
|
|
|
vkUpdateDescriptorSets(device, static_cast<uint32_t>(writeDescriptorSets.size()), writeDescriptorSets.data(), 0, NULL);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void preparePipelines()
|
|
|
|
|
{
|
|
|
|
|
VkPipelineInputAssemblyStateCreateInfo inputAssemblyState =
|
2017-02-12 11:12:42 +01:00
|
|
|
vks::initializers::pipelineInputAssemblyStateCreateInfo(
|
2016-10-28 21:16:21 +02:00
|
|
|
VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST,
|
|
|
|
|
0,
|
|
|
|
|
VK_FALSE);
|
|
|
|
|
|
|
|
|
|
VkPipelineRasterizationStateCreateInfo rasterizationState =
|
2017-02-12 11:12:42 +01:00
|
|
|
vks::initializers::pipelineRasterizationStateCreateInfo(
|
2016-10-28 21:16:21 +02:00
|
|
|
VK_POLYGON_MODE_FILL,
|
|
|
|
|
VK_CULL_MODE_BACK_BIT,
|
|
|
|
|
VK_FRONT_FACE_CLOCKWISE,
|
|
|
|
|
0);
|
|
|
|
|
|
|
|
|
|
VkPipelineColorBlendAttachmentState blendAttachmentState =
|
2017-02-12 11:12:42 +01:00
|
|
|
vks::initializers::pipelineColorBlendAttachmentState(
|
2016-10-28 21:16:21 +02:00
|
|
|
0xf,
|
|
|
|
|
VK_FALSE);
|
|
|
|
|
|
|
|
|
|
VkPipelineColorBlendStateCreateInfo colorBlendState =
|
2017-02-12 11:12:42 +01:00
|
|
|
vks::initializers::pipelineColorBlendStateCreateInfo(
|
2016-10-28 21:16:21 +02:00
|
|
|
1,
|
|
|
|
|
&blendAttachmentState);
|
|
|
|
|
|
|
|
|
|
VkPipelineDepthStencilStateCreateInfo depthStencilState =
|
2017-02-12 11:12:42 +01:00
|
|
|
vks::initializers::pipelineDepthStencilStateCreateInfo(
|
2016-10-28 21:16:21 +02:00
|
|
|
VK_TRUE,
|
|
|
|
|
VK_TRUE,
|
|
|
|
|
VK_COMPARE_OP_LESS_OR_EQUAL);
|
|
|
|
|
|
|
|
|
|
VkPipelineViewportStateCreateInfo viewportState =
|
2017-02-12 11:12:42 +01:00
|
|
|
vks::initializers::pipelineViewportStateCreateInfo(1, 1, 0);
|
2016-10-28 21:16:21 +02:00
|
|
|
|
|
|
|
|
VkPipelineMultisampleStateCreateInfo multisampleState =
|
2017-02-12 11:12:42 +01:00
|
|
|
vks::initializers::pipelineMultisampleStateCreateInfo(
|
2016-10-28 21:16:21 +02:00
|
|
|
VK_SAMPLE_COUNT_1_BIT,
|
|
|
|
|
0);
|
|
|
|
|
|
|
|
|
|
std::vector<VkDynamicState> dynamicStateEnables = {
|
|
|
|
|
VK_DYNAMIC_STATE_VIEWPORT,
|
|
|
|
|
VK_DYNAMIC_STATE_SCISSOR
|
|
|
|
|
};
|
|
|
|
|
VkPipelineDynamicStateCreateInfo dynamicState =
|
2017-02-12 11:12:42 +01:00
|
|
|
vks::initializers::pipelineDynamicStateCreateInfo(
|
2016-10-28 21:16:21 +02:00
|
|
|
dynamicStateEnables.data(),
|
|
|
|
|
static_cast<uint32_t>(dynamicStateEnables.size()),
|
|
|
|
|
0);
|
|
|
|
|
|
|
|
|
|
// Final composition pass pipeline
|
|
|
|
|
std::array<VkPipelineShaderStageCreateInfo, 2> shaderStages;
|
|
|
|
|
|
|
|
|
|
shaderStages[0] = loadShader(getAssetPath() + "shaders/ssao/fullscreen.vert.spv", VK_SHADER_STAGE_VERTEX_BIT);
|
|
|
|
|
shaderStages[1] = loadShader(getAssetPath() + "shaders/ssao/composition.frag.spv", VK_SHADER_STAGE_FRAGMENT_BIT);
|
|
|
|
|
|
|
|
|
|
VkGraphicsPipelineCreateInfo pipelineCreateInfo =
|
2017-02-12 11:12:42 +01:00
|
|
|
vks::initializers::pipelineCreateInfo(
|
2016-10-28 21:16:21 +02:00
|
|
|
pipelineLayouts.composition,
|
|
|
|
|
renderPass,
|
|
|
|
|
0);
|
|
|
|
|
|
|
|
|
|
pipelineCreateInfo.pVertexInputState = &vertices.inputState;
|
|
|
|
|
pipelineCreateInfo.pInputAssemblyState = &inputAssemblyState;
|
|
|
|
|
pipelineCreateInfo.pRasterizationState = &rasterizationState;
|
|
|
|
|
pipelineCreateInfo.pColorBlendState = &colorBlendState;
|
|
|
|
|
pipelineCreateInfo.pMultisampleState = &multisampleState;
|
|
|
|
|
pipelineCreateInfo.pViewportState = &viewportState;
|
|
|
|
|
pipelineCreateInfo.pDepthStencilState = &depthStencilState;
|
|
|
|
|
pipelineCreateInfo.pDynamicState = &dynamicState;
|
|
|
|
|
pipelineCreateInfo.stageCount = static_cast<uint32_t>(shaderStages.size());
|
|
|
|
|
pipelineCreateInfo.pStages = shaderStages.data();
|
|
|
|
|
|
|
|
|
|
VkPipelineVertexInputStateCreateInfo emptyInputState{};
|
|
|
|
|
emptyInputState.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
|
|
|
|
|
emptyInputState.vertexAttributeDescriptionCount = 0;
|
|
|
|
|
emptyInputState.pVertexAttributeDescriptions = nullptr;
|
|
|
|
|
emptyInputState.vertexBindingDescriptionCount = 0;
|
|
|
|
|
emptyInputState.pVertexBindingDescriptions = nullptr;
|
|
|
|
|
pipelineCreateInfo.pVertexInputState = &emptyInputState;
|
|
|
|
|
|
|
|
|
|
VK_CHECK_RESULT(vkCreateGraphicsPipelines(device, pipelineCache, 1, &pipelineCreateInfo, nullptr, &pipelines.composition));
|
|
|
|
|
|
|
|
|
|
pipelineCreateInfo.pVertexInputState = &emptyInputState;
|
|
|
|
|
|
|
|
|
|
// SSAO Pass
|
|
|
|
|
shaderStages[0] = loadShader(getAssetPath() + "shaders/ssao/fullscreen.vert.spv", VK_SHADER_STAGE_VERTEX_BIT);
|
|
|
|
|
shaderStages[1] = loadShader(getAssetPath() + "shaders/ssao/ssao.frag.spv", VK_SHADER_STAGE_FRAGMENT_BIT);
|
2016-11-01 15:39:54 +01:00
|
|
|
{
|
|
|
|
|
// Set constant parameters via specialization constants
|
|
|
|
|
std::array<VkSpecializationMapEntry, 2> specializationMapEntries;
|
2017-02-12 11:12:42 +01:00
|
|
|
specializationMapEntries[0] = vks::initializers::specializationMapEntry(0, 0, sizeof(uint32_t)); // SSAO Kernel size
|
|
|
|
|
specializationMapEntries[1] = vks::initializers::specializationMapEntry(1, sizeof(uint32_t), sizeof(float)); // SSAO radius
|
2016-11-01 15:39:54 +01:00
|
|
|
struct {
|
|
|
|
|
uint32_t kernelSize = SSAO_KERNEL_SIZE;
|
|
|
|
|
float radius = SSAO_RADIUS;
|
|
|
|
|
} specializationData;
|
2017-02-12 11:12:42 +01:00
|
|
|
VkSpecializationInfo specializationInfo = vks::initializers::specializationInfo(2, specializationMapEntries.data(), sizeof(specializationData), &specializationData);
|
2016-11-01 15:39:54 +01:00
|
|
|
shaderStages[1].pSpecializationInfo = &specializationInfo;
|
|
|
|
|
pipelineCreateInfo.renderPass = frameBuffers.ssao.renderPass;
|
|
|
|
|
pipelineCreateInfo.layout = pipelineLayouts.ssao;
|
|
|
|
|
VK_CHECK_RESULT(vkCreateGraphicsPipelines(device, pipelineCache, 1, &pipelineCreateInfo, nullptr, &pipelines.ssao));
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-28 21:16:21 +02:00
|
|
|
|
|
|
|
|
// SSAO blur pass
|
|
|
|
|
shaderStages[0] = loadShader(getAssetPath() + "shaders/ssao/fullscreen.vert.spv", VK_SHADER_STAGE_VERTEX_BIT);
|
|
|
|
|
shaderStages[1] = loadShader(getAssetPath() + "shaders/ssao/blur.frag.spv", VK_SHADER_STAGE_FRAGMENT_BIT);
|
|
|
|
|
pipelineCreateInfo.renderPass = frameBuffers.ssaoBlur.renderPass;
|
|
|
|
|
pipelineCreateInfo.layout = pipelineLayouts.ssaoBlur;
|
|
|
|
|
VK_CHECK_RESULT(vkCreateGraphicsPipelines(device, pipelineCache, 1, &pipelineCreateInfo, nullptr, &pipelines.ssaoBlur));
|
|
|
|
|
|
|
|
|
|
// Fill G-Buffer
|
|
|
|
|
shaderStages[0] = loadShader(getAssetPath() + "shaders/ssao/gbuffer.vert.spv", VK_SHADER_STAGE_VERTEX_BIT);
|
|
|
|
|
shaderStages[1] = loadShader(getAssetPath() + "shaders/ssao/gbuffer.frag.spv", VK_SHADER_STAGE_FRAGMENT_BIT);
|
|
|
|
|
pipelineCreateInfo.pVertexInputState = &vertices.inputState;
|
|
|
|
|
pipelineCreateInfo.renderPass = frameBuffers.offscreen.renderPass;
|
|
|
|
|
pipelineCreateInfo.layout = pipelineLayouts.gBuffer;
|
|
|
|
|
// Blend attachment states required for all color attachments
|
|
|
|
|
// This is important, as color write mask will otherwise be 0x0 and you
|
|
|
|
|
// won't see anything rendered to the attachment
|
|
|
|
|
std::array<VkPipelineColorBlendAttachmentState, 3> blendAttachmentStates = {
|
2017-02-12 11:12:42 +01:00
|
|
|
vks::initializers::pipelineColorBlendAttachmentState(0xf, VK_FALSE),
|
|
|
|
|
vks::initializers::pipelineColorBlendAttachmentState(0xf, VK_FALSE),
|
|
|
|
|
vks::initializers::pipelineColorBlendAttachmentState(0xf, VK_FALSE)
|
2016-10-28 21:16:21 +02:00
|
|
|
};
|
|
|
|
|
colorBlendState.attachmentCount = static_cast<uint32_t>(blendAttachmentStates.size());
|
|
|
|
|
colorBlendState.pAttachments = blendAttachmentStates.data();
|
|
|
|
|
VK_CHECK_RESULT(vkCreateGraphicsPipelines(device, pipelineCache, 1, &pipelineCreateInfo, nullptr, &pipelines.offscreen));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
float lerp(float a, float b, float f)
|
|
|
|
|
{
|
|
|
|
|
return a + f * (b - a);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Prepare and initialize uniform buffer containing shader uniforms
|
|
|
|
|
void prepareUniformBuffers()
|
|
|
|
|
{
|
|
|
|
|
// Scene matrices
|
|
|
|
|
vulkanDevice->createBuffer(
|
|
|
|
|
VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT,
|
|
|
|
|
VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT,
|
|
|
|
|
&uniformBuffers.sceneMatrices,
|
|
|
|
|
sizeof(uboSceneMatrices));
|
|
|
|
|
|
|
|
|
|
// SSAO parameters
|
|
|
|
|
vulkanDevice->createBuffer(
|
|
|
|
|
VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT,
|
|
|
|
|
VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT,
|
|
|
|
|
&uniformBuffers.ssaoParams,
|
|
|
|
|
sizeof(uboSSAOParams));
|
|
|
|
|
|
|
|
|
|
// Update
|
|
|
|
|
updateUniformBufferMatrices();
|
|
|
|
|
updateUniformBufferSSAOParams();
|
|
|
|
|
|
|
|
|
|
// SSAO
|
|
|
|
|
std::uniform_real_distribution<float> rndDist(0.0f, 1.0f);
|
|
|
|
|
std::random_device rndDev;
|
2016-10-29 13:18:20 +02:00
|
|
|
std::default_random_engine rndGen;
|
2016-10-28 21:16:21 +02:00
|
|
|
|
|
|
|
|
// Sample kernel
|
|
|
|
|
std::vector<glm::vec4> ssaoKernel(SSAO_KERNEL_SIZE);
|
|
|
|
|
for (uint32_t i = 0; i < SSAO_KERNEL_SIZE; ++i)
|
|
|
|
|
{
|
|
|
|
|
glm::vec3 sample(rndDist(rndGen) * 2.0 - 1.0, rndDist(rndGen) * 2.0 - 1.0, rndDist(rndGen));
|
|
|
|
|
sample = glm::normalize(sample);
|
|
|
|
|
sample *= rndDist(rndGen);
|
|
|
|
|
float scale = float(i) / float(SSAO_KERNEL_SIZE);
|
|
|
|
|
scale = lerp(0.1f, 1.0f, scale * scale);
|
|
|
|
|
ssaoKernel[i] = glm::vec4(sample * scale, 0.0f);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Upload as UBO
|
|
|
|
|
vulkanDevice->createBuffer(
|
|
|
|
|
VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT,
|
|
|
|
|
VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT,
|
|
|
|
|
&uniformBuffers.ssaoKernel,
|
|
|
|
|
ssaoKernel.size() * sizeof(glm::vec4),
|
|
|
|
|
ssaoKernel.data());
|
|
|
|
|
|
|
|
|
|
// Random noise
|
|
|
|
|
std::vector<glm::vec4> ssaoNoise(SSAO_NOISE_DIM * SSAO_NOISE_DIM);
|
|
|
|
|
for (uint32_t i = 0; i < static_cast<uint32_t>(ssaoNoise.size()); i++)
|
|
|
|
|
{
|
|
|
|
|
ssaoNoise[i] = glm::vec4(rndDist(rndGen) * 2.0f - 1.0f, rndDist(rndGen) * 2.0f - 1.0f, 0.0f, 0.0f);
|
|
|
|
|
}
|
|
|
|
|
// Upload as texture
|
2017-02-09 21:55:35 +01:00
|
|
|
textures.ssaoNoise.fromBuffer(ssaoNoise.data(), ssaoNoise.size() * sizeof(glm::vec4), VK_FORMAT_R32G32B32A32_SFLOAT, SSAO_NOISE_DIM, SSAO_NOISE_DIM, vulkanDevice, queue, VK_FILTER_NEAREST);
|
2016-10-28 21:16:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void updateUniformBufferMatrices()
|
|
|
|
|
{
|
|
|
|
|
uboSceneMatrices.projection = camera.matrices.perspective;
|
|
|
|
|
uboSceneMatrices.view = camera.matrices.view;
|
|
|
|
|
uboSceneMatrices.model = glm::mat4();
|
|
|
|
|
|
|
|
|
|
VK_CHECK_RESULT(uniformBuffers.sceneMatrices.map());
|
|
|
|
|
uniformBuffers.sceneMatrices.copyTo(&uboSceneMatrices, sizeof(uboSceneMatrices));
|
|
|
|
|
uniformBuffers.sceneMatrices.unmap();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void updateUniformBufferSSAOParams()
|
|
|
|
|
{
|
|
|
|
|
uboSSAOParams.projection = camera.matrices.perspective;
|
|
|
|
|
|
|
|
|
|
VK_CHECK_RESULT(uniformBuffers.ssaoParams.map());
|
|
|
|
|
uniformBuffers.ssaoParams.copyTo(&uboSSAOParams, sizeof(uboSSAOParams));
|
|
|
|
|
uniformBuffers.ssaoParams.unmap();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void draw()
|
|
|
|
|
{
|
|
|
|
|
VulkanExampleBase::prepareFrame();
|
|
|
|
|
|
|
|
|
|
// Offscreen rendering
|
|
|
|
|
submitInfo.pWaitSemaphores = &semaphores.presentComplete;
|
|
|
|
|
submitInfo.pSignalSemaphores = &offscreenSemaphore;
|
|
|
|
|
submitInfo.commandBufferCount = 1;
|
|
|
|
|
submitInfo.pCommandBuffers = &offScreenCmdBuffer;
|
|
|
|
|
VK_CHECK_RESULT(vkQueueSubmit(queue, 1, &submitInfo, VK_NULL_HANDLE));
|
|
|
|
|
|
|
|
|
|
// Scene rendering
|
|
|
|
|
submitInfo.pWaitSemaphores = &offscreenSemaphore;
|
|
|
|
|
submitInfo.pSignalSemaphores = &semaphores.renderComplete;
|
|
|
|
|
submitInfo.pCommandBuffers = &drawCmdBuffers[currentBuffer];
|
|
|
|
|
VK_CHECK_RESULT(vkQueueSubmit(queue, 1, &submitInfo, VK_NULL_HANDLE));
|
|
|
|
|
|
|
|
|
|
VulkanExampleBase::submitFrame();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void prepare()
|
|
|
|
|
{
|
|
|
|
|
VulkanExampleBase::prepare();
|
|
|
|
|
loadAssets();
|
|
|
|
|
setupVertexDescriptions();
|
|
|
|
|
prepareOffscreenFramebuffers();
|
|
|
|
|
prepareUniformBuffers();
|
|
|
|
|
setupDescriptorPool();
|
|
|
|
|
setupLayoutsAndDescriptors();
|
|
|
|
|
preparePipelines();
|
|
|
|
|
buildCommandBuffers();
|
|
|
|
|
buildDeferredCommandBuffer();
|
|
|
|
|
prepared = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
virtual void render()
|
|
|
|
|
{
|
|
|
|
|
if (!prepared)
|
|
|
|
|
return;
|
|
|
|
|
draw();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
virtual void viewChanged()
|
|
|
|
|
{
|
|
|
|
|
updateUniformBufferMatrices();
|
|
|
|
|
updateUniformBufferSSAOParams();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void toggleSSAO()
|
|
|
|
|
{
|
|
|
|
|
uboSSAOParams.ssao = !uboSSAOParams.ssao;
|
|
|
|
|
updateUniformBufferSSAOParams();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void toggleSSAOBlur()
|
|
|
|
|
{
|
|
|
|
|
uboSSAOParams.ssaoBlur = !uboSSAOParams.ssaoBlur;
|
|
|
|
|
updateUniformBufferSSAOParams();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void toggleSSAOOnly()
|
|
|
|
|
{
|
|
|
|
|
uboSSAOParams.ssaoOnly = !uboSSAOParams.ssaoOnly;
|
|
|
|
|
updateUniformBufferSSAOParams();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
virtual void keyPressed(uint32_t keyCode)
|
|
|
|
|
{
|
|
|
|
|
switch (keyCode)
|
|
|
|
|
{
|
|
|
|
|
case KEY_F2:
|
|
|
|
|
case GAMEPAD_BUTTON_A:
|
|
|
|
|
toggleSSAO();
|
|
|
|
|
break;
|
|
|
|
|
case KEY_F3:
|
2016-10-30 13:49:30 +01:00
|
|
|
case GAMEPAD_BUTTON_X:
|
2016-10-28 21:16:21 +02:00
|
|
|
toggleSSAOBlur();
|
|
|
|
|
break;
|
|
|
|
|
case KEY_F4:
|
|
|
|
|
case GAMEPAD_BUTTON_Y:
|
|
|
|
|
toggleSSAOOnly();
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
virtual void getOverlayText(VulkanTextOverlay *textOverlay)
|
|
|
|
|
{
|
|
|
|
|
#if defined(__ANDROID__)
|
|
|
|
|
textOverlay->addText("\"Button A\" to toggle SSAO", 5.0f, 85.0f, VulkanTextOverlay::alignLeft);
|
2016-10-30 13:49:30 +01:00
|
|
|
textOverlay->addText("\"Button X\" to toggle SSAO blur", 5.0f, 100.0f, VulkanTextOverlay::alignLeft);
|
2016-10-28 21:16:21 +02:00
|
|
|
textOverlay->addText("\"Button Y\" to toggle SSAO display", 5.0f, 115.0f, VulkanTextOverlay::alignLeft);
|
|
|
|
|
#else
|
|
|
|
|
textOverlay->addText("\"F2\" to toggle SSAO", 5.0f, 85.0f, VulkanTextOverlay::alignLeft);
|
|
|
|
|
textOverlay->addText("\"F3\" to toggle SSAO blur", 5.0f, 100.0f, VulkanTextOverlay::alignLeft);
|
|
|
|
|
textOverlay->addText("\"F4\" to toggle SSAO display", 5.0f, 115.0f, VulkanTextOverlay::alignLeft);
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
VULKAN_EXAMPLE_MAIN()
|