152 lines
3.5 KiB
C++
152 lines
3.5 KiB
C++
|
#pragma once
|
||
|
|
||
|
#include <pipeline.hpp>
|
||
|
#define GLM_DEPTH_CLIP_SPACE GLM_DEPTH_NEGATIVE_ONE_TO_ONE
|
||
|
#include <glm/glm.hpp>
|
||
|
#include <renderer.hpp>
|
||
|
|
||
|
class Material;
|
||
|
|
||
|
|
||
|
struct StaticDrawCommand
|
||
|
{
|
||
|
VkBuffer indirectStateBuffer;
|
||
|
VkDeviceMemory indirectStateBufferMemory;
|
||
|
|
||
|
VkBuffer vertexBuffer;
|
||
|
VkDeviceMemory vertexBufferMemory;
|
||
|
|
||
|
VkBuffer indexBuffer;
|
||
|
VkDeviceMemory indexBufferMemory;
|
||
|
|
||
|
VkBuffer modelBuffer;
|
||
|
VkDeviceMemory modelBufferMemory;
|
||
|
|
||
|
Material* material;
|
||
|
uint32_t numGeometry;
|
||
|
};
|
||
|
|
||
|
struct Attachment
|
||
|
{
|
||
|
VkImage image;
|
||
|
VkDeviceMemory memory;
|
||
|
VkImageView view;
|
||
|
VkFormat format;
|
||
|
};
|
||
|
|
||
|
class DeferredPipeline : public Pipeline
|
||
|
{
|
||
|
public:
|
||
|
DeferredPipeline(Renderer* renderer);
|
||
|
~DeferredPipeline() override ;
|
||
|
|
||
|
void Record(VkCommandBuffer commandBuffer, uint32_t index) override;
|
||
|
void Submit(SubmitInfo si) override;
|
||
|
|
||
|
private:
|
||
|
void SetupVertexDescriptions();
|
||
|
void PrepareGBuffer();
|
||
|
void PrepareLighting();
|
||
|
void PreparePresentation();
|
||
|
void SetupDescriptorLayout();
|
||
|
void PreparePipelines();
|
||
|
void SetupDescriptorPool();
|
||
|
void SetupDescriptorSets();
|
||
|
|
||
|
void CreateSet(Material* material);
|
||
|
|
||
|
void CreateAttachment(VkFormat format, VkImageUsageFlagBits usage, Attachment& attachment);
|
||
|
void DestroyAttachment(Attachment& attachment);
|
||
|
|
||
|
void ClearStaticGeometryBuffers();
|
||
|
|
||
|
void RecordGBuffer();
|
||
|
void RecordLighting();
|
||
|
|
||
|
struct
|
||
|
{
|
||
|
VkImage image;
|
||
|
VkDeviceMemory memory;
|
||
|
VkSampler sampler;
|
||
|
VkImageView view;
|
||
|
} m_placeholderImage;
|
||
|
|
||
|
//uniform structs
|
||
|
struct UniformObjectData
|
||
|
{
|
||
|
glm::mat4 projection, view, model;
|
||
|
glm::vec4 albedoTint;
|
||
|
glm::vec4 emission;
|
||
|
float metallic, roughness;
|
||
|
};
|
||
|
|
||
|
struct UniformLightData
|
||
|
{
|
||
|
glm::mat4 projection, view, model;
|
||
|
glm::vec4 cameraPosition, lightPosition;
|
||
|
glm::vec3 color;
|
||
|
float radius;
|
||
|
glm::vec2 viewport;
|
||
|
};
|
||
|
|
||
|
struct UniformPostData
|
||
|
{
|
||
|
float exposure = 1.0f, gamma = 2.2f;
|
||
|
};
|
||
|
|
||
|
VkBuffer m_uniformObjectBuffer, m_uniformLightBuffer, m_uniformPostBuffer;
|
||
|
VkDeviceMemory m_uniformObjectBufferMemory, m_uniformLightBufferMemory, m_uniformPostBufferMemory;
|
||
|
|
||
|
VkDescriptorPool m_descriptorPool;
|
||
|
VkDescriptorSet m_ambientDescriptorSet, m_lightingDescriptorSet, m_postDescriptorSet;
|
||
|
|
||
|
struct
|
||
|
{
|
||
|
VkFramebuffer framebuffer;
|
||
|
Attachment position, normal, albedo, material, depth;
|
||
|
|
||
|
VkSampler colorSampler;
|
||
|
} m_gBuffer;
|
||
|
|
||
|
struct
|
||
|
{
|
||
|
VkFramebuffer framebuffer;
|
||
|
Attachment color;
|
||
|
|
||
|
VkSampler colorSampler;
|
||
|
} m_finalResult;
|
||
|
|
||
|
struct
|
||
|
{
|
||
|
VkRenderPass gBuffer, lighting, presentation;
|
||
|
} m_renderPasses;
|
||
|
|
||
|
struct
|
||
|
{
|
||
|
VkDescriptorSetLayout gBuffer, ambientLighting, pointLighting, postProcessing;
|
||
|
} m_descriptorLayouts;
|
||
|
|
||
|
struct
|
||
|
{
|
||
|
VkPipelineLayout gBuffer, ambientLighting, pointLighting, postProcessing;
|
||
|
} m_pipelineLayouts;
|
||
|
|
||
|
struct
|
||
|
{
|
||
|
VkPipeline geometryDynamic, geometryStatic, ambientLighting, pointLighting, postProcessing;
|
||
|
} m_pipelines;
|
||
|
|
||
|
struct
|
||
|
{
|
||
|
VkPipelineVertexInputStateCreateInfo geometryDynamic, geometryStatic, quad;
|
||
|
} m_inputStates;
|
||
|
|
||
|
VkCommandBuffer m_gBufferCommandBuffer, m_lightingCommandBuffer;
|
||
|
VkSemaphore m_gbufferFinishedSemaphore, m_lightingFinishedSemaphore;
|
||
|
|
||
|
std::vector<VkFramebuffer> m_swapchainFramebuffers;
|
||
|
std::map<Material*, VkDescriptorSet> m_samplerSets;
|
||
|
std::vector<StaticDrawCommand> m_staticDrawCommands;
|
||
|
|
||
|
Renderer* m_renderer;
|
||
|
};
|