Added KRRenderGraphDeferred and KRRenderGraphForward
This commit is contained in:
@@ -83,6 +83,8 @@ add_source_and_header(KROctreeNode)
|
||||
add_source_and_header(KRPresentationThread)
|
||||
add_source_and_header(KRRenderGraph)
|
||||
add_source_and_header(KRRenderGraphBlackFrame)
|
||||
add_source_and_header(KRRenderGraphDeferred)
|
||||
add_source_and_header(KRRenderGraphForward)
|
||||
add_source_and_header(KRRenderSettings)
|
||||
add_source_and_header(KRPipeline)
|
||||
add_source_and_header(KRPipelineManager)
|
||||
|
||||
154
kraken/KRRenderGraphDeferred.cpp
Normal file
154
kraken/KRRenderGraphDeferred.cpp
Normal file
@@ -0,0 +1,154 @@
|
||||
//
|
||||
// KRRenderGraphDeferred.cpp
|
||||
// Kraken Engine
|
||||
//
|
||||
// Copyright 2024 Kearwood Gilbert. All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification, are
|
||||
// permitted provided that the following conditions are met:
|
||||
//
|
||||
// 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
// conditions and the following disclaimer.
|
||||
//
|
||||
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
// of conditions and the following disclaimer in the documentation and/or other materials
|
||||
// provided with the distribution.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY KEARWOOD GILBERT ''AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||
// FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL KEARWOOD GILBERT OR
|
||||
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
// The views and conclusions contained in the software and documentation are those of the
|
||||
// authors and should not be interpreted as representing official policies, either expressed
|
||||
// or implied, of Kearwood Gilbert.
|
||||
//
|
||||
|
||||
#include "KRREnderGraphDeferred.h"
|
||||
#include "KRRenderPass.h"
|
||||
#include "KRSurface.h"
|
||||
#include "KRDevice.h"
|
||||
|
||||
KRRenderGraphDeferred::KRRenderGraphDeferred(KRContext& context)
|
||||
: KRRenderGraph(context)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
KRRenderGraphDeferred::~KRRenderGraphDeferred()
|
||||
{
|
||||
}
|
||||
|
||||
KrResult KRRenderGraphDeferred::initialize(KRSurface &surface)
|
||||
{
|
||||
VkFormat depthImageFormat = VK_FORMAT_UNDEFINED;
|
||||
KrResult res = KR_SUCCESS;
|
||||
res = surface.getDevice()->selectDepthFormat(depthImageFormat);
|
||||
if (res != KR_SUCCESS) {
|
||||
return res;
|
||||
}
|
||||
|
||||
// ----- Configuration -----
|
||||
int shadow_buffer_count = 0;
|
||||
bool enable_deferred_lighting = true;
|
||||
// -------------------------
|
||||
|
||||
int attachment_compositeDepth = addAttachment("Composite Depth", depthImageFormat);
|
||||
int attachment_compositeColor = addAttachment("Composite Color", surface.getSurfaceFormat());
|
||||
int attachment_lightAccumulation = addAttachment("Light Accumulation", VK_FORMAT_B8G8R8A8_UINT);
|
||||
int attachment_gbuffer = addAttachment("GBuffer", VK_FORMAT_B8G8R8A8_UINT);
|
||||
int attachment_shadow_cascades[3];
|
||||
attachment_shadow_cascades[0] = addAttachment("Shadow Cascade 0", VK_FORMAT_D32_SFLOAT);
|
||||
attachment_shadow_cascades[1] = addAttachment("Shadow Cascade 1", VK_FORMAT_D32_SFLOAT);
|
||||
attachment_shadow_cascades[2] = addAttachment("Shadow Cascade 2", VK_FORMAT_D32_SFLOAT);
|
||||
|
||||
RenderPassInfo info{};
|
||||
info.finalPass = false;
|
||||
|
||||
info.type = RenderPassType::RENDER_PASS_PRESTREAM;
|
||||
addRenderPass(*surface.getDevice(), info);
|
||||
|
||||
for (int shadow_index = 0; shadow_index < shadow_buffer_count; shadow_index++) {
|
||||
info.depthAttachment.id = attachment_shadow_cascades[shadow_index];
|
||||
info.depthAttachment.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
|
||||
info.depthAttachment.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
|
||||
info.depthAttachment.clearVaue.depthStencil.depth = 1.0f;
|
||||
info.depthAttachment.clearVaue.depthStencil.stencil = 0;
|
||||
info.type = RenderPassType::RENDER_PASS_SHADOWMAP;
|
||||
addRenderPass(*surface.getDevice(), info);
|
||||
}
|
||||
|
||||
|
||||
// ----====---- Opaque Geometry, Deferred rendering Pass 1 ----====----
|
||||
|
||||
info.depthAttachment.id = attachment_compositeDepth;
|
||||
info.depthAttachment.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
|
||||
info.depthAttachment.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
|
||||
info.depthAttachment.clearVaue.depthStencil.depth = 1.0f;
|
||||
info.depthAttachment.clearVaue.depthStencil.stencil = 0;
|
||||
|
||||
info.colorAttachments[0].id = attachment_compositeColor;
|
||||
info.colorAttachments[0].clearVaue.color.float32[0] = 0.0f;
|
||||
info.colorAttachments[0].clearVaue.color.float32[1] = 0.0f;
|
||||
info.colorAttachments[0].clearVaue.color.float32[2] = 0.0f;
|
||||
info.colorAttachments[0].clearVaue.color.float32[3] = 0.0f;
|
||||
info.colorAttachments[0].loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
|
||||
info.colorAttachments[0].stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
|
||||
info.type = RenderPassType::RENDER_PASS_DEFERRED_GBUFFER;
|
||||
addRenderPass(*surface.getDevice(), info);
|
||||
|
||||
// ----====---- Opaque Geometry, Deferred rendering Pass 2 ----====----
|
||||
|
||||
info.depthAttachment.loadOp = VK_ATTACHMENT_LOAD_OP_LOAD;
|
||||
info.colorAttachments[0].loadOp = VK_ATTACHMENT_LOAD_OP_LOAD;
|
||||
|
||||
info.colorAttachments[1].id = attachment_lightAccumulation;
|
||||
info.colorAttachments[1].clearVaue.color.float32[0] = 0.0f;
|
||||
info.colorAttachments[1].clearVaue.color.float32[1] = 0.0f;
|
||||
info.colorAttachments[1].clearVaue.color.float32[2] = 0.0f;
|
||||
info.colorAttachments[1].clearVaue.color.float32[3] = 0.0f;
|
||||
info.colorAttachments[1].loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
|
||||
info.colorAttachments[1].stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
|
||||
info.type = RenderPassType::RENDER_PASS_DEFERRED_LIGHTS;
|
||||
addRenderPass(*surface.getDevice(), info);
|
||||
|
||||
// ----====---- Opaque Geometry, Deferred rendering Pass 3 ----====----
|
||||
info.colorAttachments[0].loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
|
||||
info.colorAttachments[1].loadOp = VK_ATTACHMENT_LOAD_OP_LOAD;
|
||||
info.type = RenderPassType::RENDER_PASS_DEFERRED_OPAQUE;
|
||||
addRenderPass(*surface.getDevice(), info);
|
||||
|
||||
info.colorAttachments[1] = {};
|
||||
|
||||
// ----====---- Transparent Geometry, Forward Rendering ----====----
|
||||
info.depthAttachment.id = attachment_compositeDepth;
|
||||
info.depthAttachment.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
|
||||
info.depthAttachment.loadOp = VK_ATTACHMENT_LOAD_OP_LOAD;
|
||||
info.depthAttachment.clearVaue.depthStencil.depth = 1.0f;
|
||||
info.depthAttachment.clearVaue.depthStencil.stencil = 0;
|
||||
|
||||
info.colorAttachments[0].id = attachment_compositeColor;
|
||||
info.colorAttachments[0].clearVaue.color.float32[0] = 0.0f;
|
||||
info.colorAttachments[0].clearVaue.color.float32[1] = 0.0f;
|
||||
info.colorAttachments[0].clearVaue.color.float32[2] = 0.0f;
|
||||
info.colorAttachments[0].clearVaue.color.float32[3] = 0.0f;
|
||||
info.colorAttachments[0].loadOp = VK_ATTACHMENT_LOAD_OP_LOAD;
|
||||
info.colorAttachments[0].stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
|
||||
|
||||
info.type = RenderPassType::RENDER_PASS_FORWARD_TRANSPARENT;
|
||||
addRenderPass(*surface.getDevice(), info);
|
||||
|
||||
info.type = RenderPassType::RENDER_PASS_DEBUG_OVERLAYS;
|
||||
addRenderPass(*surface.getDevice(), info);
|
||||
|
||||
info.finalPass = true;
|
||||
info.type = RenderPassType::RENDER_PASS_POST_COMPOSITE;
|
||||
addRenderPass(*surface.getDevice(), info);
|
||||
|
||||
return KR_SUCCESS;
|
||||
}
|
||||
44
kraken/KRRenderGraphDeferred.h
Normal file
44
kraken/KRRenderGraphDeferred.h
Normal file
@@ -0,0 +1,44 @@
|
||||
//
|
||||
// KRRenderGraphDeferred.h
|
||||
// Kraken Engine
|
||||
//
|
||||
// Copyright 2024 Kearwood Gilbert. All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification, are
|
||||
// permitted provided that the following conditions are met:
|
||||
//
|
||||
// 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
// conditions and the following disclaimer.
|
||||
//
|
||||
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
// of conditions and the following disclaimer in the documentation and/or other materials
|
||||
// provided with the distribution.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY KEARWOOD GILBERT ''AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||
// FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL KEARWOOD GILBERT OR
|
||||
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
// The views and conclusions contained in the software and documentation are those of the
|
||||
// authors and should not be interpreted as representing official policies, either expressed
|
||||
// or implied, of Kearwood Gilbert.
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "KRRenderGraph.h"
|
||||
|
||||
class KRRenderGraphDeferred : public KRRenderGraph
|
||||
{
|
||||
public:
|
||||
KRRenderGraphDeferred(KRContext& context);
|
||||
~KRRenderGraphDeferred();
|
||||
|
||||
KrResult initialize(KRSurface& surface);
|
||||
|
||||
};
|
||||
129
kraken/KRRenderGraphForward.cpp
Normal file
129
kraken/KRRenderGraphForward.cpp
Normal file
@@ -0,0 +1,129 @@
|
||||
//
|
||||
// KRRenderGraphForward.cpp
|
||||
// Kraken Engine
|
||||
//
|
||||
// Copyright 2024 Kearwood Gilbert. All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification, are
|
||||
// permitted provided that the following conditions are met:
|
||||
//
|
||||
// 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
// conditions and the following disclaimer.
|
||||
//
|
||||
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
// of conditions and the following disclaimer in the documentation and/or other materials
|
||||
// provided with the distribution.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY KEARWOOD GILBERT ''AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||
// FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL KEARWOOD GILBERT OR
|
||||
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
// The views and conclusions contained in the software and documentation are those of the
|
||||
// authors and should not be interpreted as representing official policies, either expressed
|
||||
// or implied, of Kearwood Gilbert.
|
||||
//
|
||||
|
||||
#include "KRREnderGraphForward.h"
|
||||
#include "KRRenderPass.h"
|
||||
#include "KRSurface.h"
|
||||
#include "KRDevice.h"
|
||||
|
||||
KRRenderGraphForward::KRRenderGraphForward(KRContext& context)
|
||||
: KRRenderGraph(context)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
KRRenderGraphForward::~KRRenderGraphForward()
|
||||
{
|
||||
}
|
||||
|
||||
KrResult KRRenderGraphForward::initialize(KRSurface &surface)
|
||||
{
|
||||
VkFormat depthImageFormat = VK_FORMAT_UNDEFINED;
|
||||
KrResult res = KR_SUCCESS;
|
||||
res = surface.getDevice()->selectDepthFormat(depthImageFormat);
|
||||
if (res != KR_SUCCESS) {
|
||||
return res;
|
||||
}
|
||||
|
||||
// ----- Configuration -----
|
||||
int shadow_buffer_count = 0;
|
||||
// -------------------------
|
||||
|
||||
int attachment_compositeDepth = addAttachment("Composite Depth", depthImageFormat);
|
||||
int attachment_compositeColor = addAttachment("Composite Color", surface.getSurfaceFormat());
|
||||
int attachment_lightAccumulation = addAttachment("Light Accumulation", VK_FORMAT_B8G8R8A8_UINT);
|
||||
int attachment_gbuffer = addAttachment("GBuffer", VK_FORMAT_B8G8R8A8_UINT);
|
||||
int attachment_shadow_cascades[3];
|
||||
attachment_shadow_cascades[0] = addAttachment("Shadow Cascade 0", VK_FORMAT_D32_SFLOAT);
|
||||
attachment_shadow_cascades[1] = addAttachment("Shadow Cascade 1", VK_FORMAT_D32_SFLOAT);
|
||||
attachment_shadow_cascades[2] = addAttachment("Shadow Cascade 2", VK_FORMAT_D32_SFLOAT);
|
||||
|
||||
RenderPassInfo info{};
|
||||
info.finalPass = false;
|
||||
|
||||
info.type = RenderPassType::RENDER_PASS_PRESTREAM;
|
||||
addRenderPass(*surface.getDevice(), info);
|
||||
|
||||
for (int shadow_index = 0; shadow_index < shadow_buffer_count; shadow_index++) {
|
||||
info.depthAttachment.id = attachment_shadow_cascades[shadow_index];
|
||||
info.depthAttachment.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
|
||||
info.depthAttachment.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
|
||||
info.depthAttachment.clearVaue.depthStencil.depth = 1.0f;
|
||||
info.depthAttachment.clearVaue.depthStencil.stencil = 0;
|
||||
info.type = RenderPassType::RENDER_PASS_SHADOWMAP;
|
||||
addRenderPass(*surface.getDevice(), info);
|
||||
}
|
||||
|
||||
// ----====---- Opaque Geometry, Forward Rendering ----====----
|
||||
info.depthAttachment.id = attachment_compositeDepth;
|
||||
info.depthAttachment.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
|
||||
info.depthAttachment.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
|
||||
info.depthAttachment.clearVaue.depthStencil.depth = 1.0f;
|
||||
info.depthAttachment.clearVaue.depthStencil.stencil = 0;
|
||||
|
||||
info.colorAttachments[0].id = attachment_compositeColor;
|
||||
info.colorAttachments[0].clearVaue.color.float32[0] = 0.0f;
|
||||
info.colorAttachments[0].clearVaue.color.float32[1] = 0.0f;
|
||||
info.colorAttachments[0].clearVaue.color.float32[2] = 0.0f;
|
||||
info.colorAttachments[0].clearVaue.color.float32[3] = 0.0f;
|
||||
info.colorAttachments[0].loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
|
||||
info.colorAttachments[0].stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
|
||||
|
||||
info.type = RenderPassType::RENDER_PASS_FORWARD_OPAQUE;
|
||||
addRenderPass(*surface.getDevice(), info);
|
||||
|
||||
// ----====---- Transparent Geometry, Forward Rendering ----====----
|
||||
info.depthAttachment.id = attachment_compositeDepth;
|
||||
info.depthAttachment.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
|
||||
info.depthAttachment.loadOp = VK_ATTACHMENT_LOAD_OP_LOAD;
|
||||
info.depthAttachment.clearVaue.depthStencil.depth = 1.0f;
|
||||
info.depthAttachment.clearVaue.depthStencil.stencil = 0;
|
||||
|
||||
info.colorAttachments[0].id = attachment_compositeColor;
|
||||
info.colorAttachments[0].clearVaue.color.float32[0] = 0.0f;
|
||||
info.colorAttachments[0].clearVaue.color.float32[1] = 0.0f;
|
||||
info.colorAttachments[0].clearVaue.color.float32[2] = 0.0f;
|
||||
info.colorAttachments[0].clearVaue.color.float32[3] = 0.0f;
|
||||
info.colorAttachments[0].loadOp = VK_ATTACHMENT_LOAD_OP_LOAD;
|
||||
info.colorAttachments[0].stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
|
||||
|
||||
info.type = RenderPassType::RENDER_PASS_FORWARD_TRANSPARENT;
|
||||
addRenderPass(*surface.getDevice(), info);
|
||||
|
||||
info.type = RenderPassType::RENDER_PASS_DEBUG_OVERLAYS;
|
||||
addRenderPass(*surface.getDevice(), info);
|
||||
|
||||
info.finalPass = true;
|
||||
info.type = RenderPassType::RENDER_PASS_POST_COMPOSITE;
|
||||
addRenderPass(*surface.getDevice(), info);
|
||||
|
||||
return KR_SUCCESS;
|
||||
}
|
||||
44
kraken/KRRenderGraphForward.h
Normal file
44
kraken/KRRenderGraphForward.h
Normal file
@@ -0,0 +1,44 @@
|
||||
//
|
||||
// KRRenderGraphForward.h
|
||||
// Kraken Engine
|
||||
//
|
||||
// Copyright 2024 Kearwood Gilbert. All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification, are
|
||||
// permitted provided that the following conditions are met:
|
||||
//
|
||||
// 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
// conditions and the following disclaimer.
|
||||
//
|
||||
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
// of conditions and the following disclaimer in the documentation and/or other materials
|
||||
// provided with the distribution.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY KEARWOOD GILBERT ''AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||
// FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL KEARWOOD GILBERT OR
|
||||
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
// The views and conclusions contained in the software and documentation are those of the
|
||||
// authors and should not be interpreted as representing official policies, either expressed
|
||||
// or implied, of Kearwood Gilbert.
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "KRRenderGraph.h"
|
||||
|
||||
class KRRenderGraphForward : public KRRenderGraph
|
||||
{
|
||||
public:
|
||||
KRRenderGraphForward(KRContext& context);
|
||||
~KRRenderGraphForward();
|
||||
|
||||
KrResult initialize(KRSurface& surface);
|
||||
|
||||
};
|
||||
@@ -33,6 +33,8 @@
|
||||
#include "KRSwapchain.h"
|
||||
#include "KRRenderPass.h"
|
||||
#include "KRRenderGraphBlackFrame.h"
|
||||
#include "KRRenderGraphDeferred.h"
|
||||
#include "KRRenderGraphForward.h"
|
||||
|
||||
using namespace hydra;
|
||||
|
||||
@@ -46,7 +48,8 @@ KRSurface::KRSurface(KRContext& context, KrSurfaceHandle handle, void* platformH
|
||||
, m_renderFinishedSemaphores{VK_NULL_HANDLE}
|
||||
, m_inFlightFences{VK_NULL_HANDLE}
|
||||
, m_frameIndex(0)
|
||||
, m_renderGraph(std::make_unique<KRRenderGraph>(context))
|
||||
, m_renderGraphForward(std::make_unique<KRRenderGraphForward>(context))
|
||||
, m_renderGraphDeferred(std::make_unique<KRRenderGraphDeferred>(context))
|
||||
, m_blackFrameRenderGraph(std::make_unique<KRRenderGraphBlackFrame>(context))
|
||||
, m_swapChain(std::make_unique<KRSwapchain>(context))
|
||||
, m_surfaceFormat{}
|
||||
@@ -113,7 +116,8 @@ void KRSurface::destroy()
|
||||
destroySwapChain();
|
||||
|
||||
std::unique_ptr<KRDevice>& device = m_pContext->getDeviceManager()->getDevice(m_deviceHandle);
|
||||
m_renderGraph->destroy(*device);
|
||||
m_renderGraphForward->destroy(*device);
|
||||
m_renderGraphDeferred->destroy(*device);
|
||||
m_blackFrameRenderGraph->destroy(*device);
|
||||
|
||||
for (int i=0; i < KRENGINE_MAX_FRAMES_IN_FLIGHT; i++) {
|
||||
@@ -173,124 +177,7 @@ KrResult KRSurface::createSwapChain()
|
||||
imageCount = surfaceCapabilities.maxImageCount;
|
||||
}
|
||||
|
||||
// ----- Configuration -----
|
||||
int shadow_buffer_count = 0;
|
||||
bool enable_deferred_lighting = false;
|
||||
// -------------------------
|
||||
|
||||
int attachment_compositeDepth = m_renderGraph->addAttachment("Composite Depth", depthImageFormat);
|
||||
int attachment_compositeColor = m_renderGraph->addAttachment("Composite Color", m_surfaceFormat.format);
|
||||
int attachment_lightAccumulation = m_renderGraph->addAttachment("Light Accumulation", VK_FORMAT_B8G8R8A8_UINT);
|
||||
int attachment_gbuffer = m_renderGraph->addAttachment("GBuffer", VK_FORMAT_B8G8R8A8_UINT);
|
||||
int attachment_shadow_cascades[3];
|
||||
attachment_shadow_cascades[0] = m_renderGraph->addAttachment("Shadow Cascade 0", VK_FORMAT_D32_SFLOAT);
|
||||
attachment_shadow_cascades[1] = m_renderGraph->addAttachment("Shadow Cascade 1", VK_FORMAT_D32_SFLOAT);
|
||||
attachment_shadow_cascades[2] = m_renderGraph->addAttachment("Shadow Cascade 2", VK_FORMAT_D32_SFLOAT);
|
||||
|
||||
RenderPassInfo info{};
|
||||
info.finalPass = false;
|
||||
|
||||
info.type = RenderPassType::RENDER_PASS_PRESTREAM;
|
||||
m_renderGraph->addRenderPass(*device, info);
|
||||
|
||||
for (int shadow_index = 0; shadow_index < shadow_buffer_count; shadow_index++) {
|
||||
info.depthAttachment.id = attachment_shadow_cascades[shadow_index];
|
||||
info.depthAttachment.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
|
||||
info.depthAttachment.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
|
||||
info.depthAttachment.clearVaue.depthStencil.depth = 1.0f;
|
||||
info.depthAttachment.clearVaue.depthStencil.stencil = 0;
|
||||
info.type = RenderPassType::RENDER_PASS_SHADOWMAP;
|
||||
m_renderGraph->addRenderPass(*device, info);
|
||||
}
|
||||
|
||||
if (enable_deferred_lighting) {
|
||||
// ----====---- Opaque Geometry, Deferred rendering Pass 1 ----====----
|
||||
|
||||
info.depthAttachment.id = attachment_compositeDepth;
|
||||
info.depthAttachment.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
|
||||
info.depthAttachment.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
|
||||
info.depthAttachment.clearVaue.depthStencil.depth = 1.0f;
|
||||
info.depthAttachment.clearVaue.depthStencil.stencil = 0;
|
||||
|
||||
info.colorAttachments[0].id = attachment_compositeColor;
|
||||
info.colorAttachments[0].clearVaue.color.float32[0] = 0.0f;
|
||||
info.colorAttachments[0].clearVaue.color.float32[1] = 0.0f;
|
||||
info.colorAttachments[0].clearVaue.color.float32[2] = 0.0f;
|
||||
info.colorAttachments[0].clearVaue.color.float32[3] = 0.0f;
|
||||
info.colorAttachments[0].loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
|
||||
info.colorAttachments[0].stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
|
||||
info.type = RenderPassType::RENDER_PASS_DEFERRED_GBUFFER;
|
||||
m_renderGraph->addRenderPass(*device, info);
|
||||
|
||||
// ----====---- Opaque Geometry, Deferred rendering Pass 2 ----====----
|
||||
|
||||
info.depthAttachment.loadOp = VK_ATTACHMENT_LOAD_OP_LOAD;
|
||||
info.colorAttachments[0].loadOp = VK_ATTACHMENT_LOAD_OP_LOAD;
|
||||
|
||||
info.colorAttachments[1].id = attachment_lightAccumulation;
|
||||
info.colorAttachments[1].clearVaue.color.float32[0] = 0.0f;
|
||||
info.colorAttachments[1].clearVaue.color.float32[1] = 0.0f;
|
||||
info.colorAttachments[1].clearVaue.color.float32[2] = 0.0f;
|
||||
info.colorAttachments[1].clearVaue.color.float32[3] = 0.0f;
|
||||
info.colorAttachments[1].loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
|
||||
info.colorAttachments[1].stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
|
||||
info.type = RenderPassType::RENDER_PASS_DEFERRED_LIGHTS;
|
||||
m_renderGraph->addRenderPass(*device, info);
|
||||
|
||||
// ----====---- Opaque Geometry, Deferred rendering Pass 3 ----====----
|
||||
info.colorAttachments[0].loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
|
||||
info.colorAttachments[1].loadOp = VK_ATTACHMENT_LOAD_OP_LOAD;
|
||||
info.type = RenderPassType::RENDER_PASS_DEFERRED_OPAQUE;
|
||||
m_renderGraph->addRenderPass(*device, info);
|
||||
|
||||
info.colorAttachments[1] = {};
|
||||
|
||||
} else {
|
||||
// !enable_deferred_lighting
|
||||
|
||||
// ----====---- Opaque Geometry, Forward Rendering ----====----
|
||||
info.depthAttachment.id = attachment_compositeDepth;
|
||||
info.depthAttachment.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
|
||||
info.depthAttachment.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
|
||||
info.depthAttachment.clearVaue.depthStencil.depth = 1.0f;
|
||||
info.depthAttachment.clearVaue.depthStencil.stencil = 0;
|
||||
|
||||
info.colorAttachments[0].id = attachment_compositeColor;
|
||||
info.colorAttachments[0].clearVaue.color.float32[0] = 0.0f;
|
||||
info.colorAttachments[0].clearVaue.color.float32[1] = 0.0f;
|
||||
info.colorAttachments[0].clearVaue.color.float32[2] = 0.0f;
|
||||
info.colorAttachments[0].clearVaue.color.float32[3] = 0.0f;
|
||||
info.colorAttachments[0].loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
|
||||
info.colorAttachments[0].stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
|
||||
|
||||
info.type = RenderPassType::RENDER_PASS_FORWARD_OPAQUE;
|
||||
m_renderGraph->addRenderPass(*device, info);
|
||||
}
|
||||
|
||||
// ----====---- Transparent Geometry, Forward Rendering ----====----
|
||||
info.depthAttachment.id = attachment_compositeDepth;
|
||||
info.depthAttachment.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
|
||||
info.depthAttachment.loadOp = VK_ATTACHMENT_LOAD_OP_LOAD;
|
||||
info.depthAttachment.clearVaue.depthStencil.depth = 1.0f;
|
||||
info.depthAttachment.clearVaue.depthStencil.stencil = 0;
|
||||
|
||||
info.colorAttachments[0].id = attachment_compositeColor;
|
||||
info.colorAttachments[0].clearVaue.color.float32[0] = 0.0f;
|
||||
info.colorAttachments[0].clearVaue.color.float32[1] = 0.0f;
|
||||
info.colorAttachments[0].clearVaue.color.float32[2] = 0.0f;
|
||||
info.colorAttachments[0].clearVaue.color.float32[3] = 0.0f;
|
||||
info.colorAttachments[0].loadOp = VK_ATTACHMENT_LOAD_OP_LOAD;
|
||||
info.colorAttachments[0].stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
|
||||
|
||||
info.type = RenderPassType::RENDER_PASS_FORWARD_TRANSPARENT;
|
||||
m_renderGraph->addRenderPass(*device, info);
|
||||
|
||||
info.type = RenderPassType::RENDER_PASS_DEBUG_OVERLAYS;
|
||||
m_renderGraph->addRenderPass(*device, info);
|
||||
|
||||
info.finalPass = true;
|
||||
info.type = RenderPassType::RENDER_PASS_POST_COMPOSITE;
|
||||
m_renderGraph->addRenderPass(*device, info);
|
||||
|
||||
|
||||
res = m_blackFrameRenderGraph->initialize(*this);
|
||||
@@ -298,7 +185,18 @@ KrResult KRSurface::createSwapChain()
|
||||
return res;
|
||||
}
|
||||
|
||||
m_swapChain->create(*device, m_surface, m_surfaceFormat, depthImageFormat, swapExtent, imageCount, *m_renderGraph->getFinalRenderPass());
|
||||
res = m_renderGraphForward->initialize(*this);
|
||||
if (res != KR_SUCCESS) {
|
||||
return res;
|
||||
}
|
||||
|
||||
res = m_renderGraphDeferred->initialize(*this);
|
||||
if (res != KR_SUCCESS) {
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
m_swapChain->create(*device, m_surface, m_surfaceFormat, depthImageFormat, swapExtent, imageCount, *m_renderGraphForward->getFinalRenderPass());
|
||||
|
||||
return KR_SUCCESS;
|
||||
}
|
||||
@@ -353,12 +251,12 @@ VkFormat KRSurface::getDepthFormat() const
|
||||
|
||||
KRRenderPass* KRSurface::getRenderPass(RenderPassType type)
|
||||
{
|
||||
return m_renderGraph->getRenderPass(type);
|
||||
return m_renderGraphForward->getRenderPass(type);
|
||||
}
|
||||
|
||||
void KRSurface::endFrame()
|
||||
{
|
||||
m_frameIndex++;;
|
||||
m_frameIndex++;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -39,6 +39,8 @@ class KRRenderPass;
|
||||
class KRSwapchain;
|
||||
class KRRenderGraph;
|
||||
class KRRenderGraphBlackFrame;
|
||||
class KRRenderGraphDeferred;
|
||||
class KRRenderGraphForward;
|
||||
enum RenderPassType : uint8_t;
|
||||
|
||||
class KRSurface : public KRContextObject
|
||||
@@ -81,7 +83,8 @@ public:
|
||||
private:
|
||||
void destroySwapChain();
|
||||
KrResult createSwapChain();
|
||||
std::unique_ptr<KRRenderGraph> m_renderGraph;
|
||||
std::unique_ptr<KRRenderGraphForward> m_renderGraphForward;
|
||||
std::unique_ptr<KRRenderGraphDeferred> m_renderGraphDeferred;
|
||||
std::unique_ptr<KRRenderGraphBlackFrame> m_blackFrameRenderGraph;
|
||||
|
||||
VkSurfaceFormatKHR m_surfaceFormat;
|
||||
|
||||
Reference in New Issue
Block a user