diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHDebugDrawSystem.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHDebugDrawSystem.cpp index 90fe51d5..74effb6d 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHDebugDrawSystem.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHDebugDrawSystem.cpp @@ -95,18 +95,26 @@ namespace SHADE // Get Current frame index const uint32_t FRAME_IDX = GFX_SYSTEM->GetCurrentFrameIndex(); - // Set Pipelin - cmdBuffer->BindPipeline(GFX_SYSTEM->GetDebugDrawPipeline()); - cmdBuffer->SetLineWidth(LineWidth); - // Don't draw if no points if (numPoints[FRAME_IDX] > 0) { + cmdBuffer->BindPipeline(GFX_SYSTEM->GetDebugDrawPipeline()); + cmdBuffer->SetLineWidth(LineWidth); cmdBuffer->BindVertexBuffer(0, vertexBuffers[FRAME_IDX], 0); cmdBuffer->DrawArrays(numPoints[FRAME_IDX], 1, 0, 0); } + }); + auto subPassWithDepth = renderGraph->GetNode("Debug Draw with Depth")->GetSubpass("Debug Draw with Depth"); + subPassWithDepth->AddExteriorDrawCalls([this, GFX_SYSTEM](Handle& cmdBuffer) + { + // Get Current frame index + const uint32_t FRAME_IDX = GFX_SYSTEM->GetCurrentFrameIndex(); + + // Don't draw if no points if (numPersistentPoints[FRAME_IDX] > 0) { + cmdBuffer->BindPipeline(GFX_SYSTEM->GetDebugDrawDepthPipeline()); + cmdBuffer->SetLineWidth(LineWidth); cmdBuffer->BindVertexBuffer(0, persistentVertexBuffers[FRAME_IDX], 0); cmdBuffer->DrawArrays(numPersistentPoints[FRAME_IDX], 1, 0, 0); } diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHDebugDrawSystem.h b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHDebugDrawSystem.h index 7c9e7c81..2a9709ed 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHDebugDrawSystem.h +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHDebugDrawSystem.h @@ -131,7 +131,7 @@ namespace SHADE /*---------------------------------------------------------------------------------*/ /// /// Renders a line between two points in world space that will persist until - /// ClearPersistentDraws() is called. + /// ClearPersistentDraws() is called. These lines are depth tested. /// /// Colour of the line. /// First point of the line. @@ -139,7 +139,7 @@ namespace SHADE void DrawPersistentLine(const SHVec4& color, const SHVec3& startPt, const SHVec3& endPt); /// /// Renders a triangle indicated by three points in world space that will persist - /// until ClearPersistentDraws() is called. + /// until ClearPersistentDraws() is called. These lines are depth tested. /// /// Colour of the triangle. /// First point of the triangle. @@ -148,7 +148,7 @@ namespace SHADE void DrawPersistentTri(const SHVec4& color, const SHVec3& pt1, const SHVec3& pt2, const SHVec3& pt3); /// /// Renders a quadrilateral indicated by four points in world space that will persist - /// until ClearPersistentDraws() is called. + /// until ClearPersistentDraws() is called. These lines are depth tested. /// /// Colour of the quadrilateral. /// First point of the triangle. @@ -158,14 +158,16 @@ namespace SHADE void DrawPersistentQuad(const SHVec4& color, const SHVec3& pt1, const SHVec3& pt2, const SHVec3& pt3, const SHVec3& pt4); /// /// Renders a polygon indicated by the specified set of points in world space that - /// will persist until ClearPersistentDraws() is called. + /// will persist until ClearPersistentDraws() is called. These lines are depth + /// tested. /// /// Colour of the polygon. /// List of points for the polygon. void DrawPersistentPoly(const SHVec4& color, std::initializer_list pointList); /// /// Renders a polygon indicated by the specified set of points in world space that - /// will persist until ClearPersistentDraws() is called. + /// will persist until ClearPersistentDraws() is called. These lines are depth + /// tested. /// /// Iterator for a STL-like container. /// Colour of the polygon. @@ -179,7 +181,8 @@ namespace SHADE void DrawPersistentPoly(const SHVec4& color, IterType pointListBegin, IterType pointListEnd); /// /// Renders a wireframe cube centered around the position specified in world space - /// that will persist until ClearPersistentDraws() is called. + /// that will persist until ClearPersistentDraws() is called. These lines are depth + /// tested. /// /// Colour of the cube. /// Position where the cube wil be centered at. @@ -187,7 +190,8 @@ namespace SHADE void DrawPersistentCube(const SHVec4& color, const SHVec3& pos, const SHVec3& size); /// /// Renders a wireframe sphere centered around the position specified in world space - /// that will persist until ClearPersistentDraws() is called. + /// that will persist until ClearPersistentDraws() is called. These lines are depth + /// tested. /// /// Colour of the sphere. /// Position where the sphere wil be centered at. @@ -241,13 +245,6 @@ namespace SHADE void drawCube(std::vector& storage, const SHVec4& color, const SHVec3& pos, const SHVec3& size); void drawSphere(std::vector& storage, const SHVec4& color, const SHVec3& pos, double radius); }; - - template - void SHADE::SHDebugDrawSystem::DrawPersistentPoly(const SHVec4& color, IterType pointListBegin, IterType pointListEnd) - { - - } - } #include "SHDebugDrawSystem.hpp" \ No newline at end of file diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp index 2bc2b7de..4d551cee 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp @@ -171,7 +171,7 @@ namespace SHADE "Normals", "Albedo", "Depth Buffer", - "Scene" + "Scene" }, {}); // no predecessors @@ -186,8 +186,14 @@ namespace SHADE // deferred composite gBufferNode->AddNodeCompute(deferredCompositeShader, { "Position", "Normals", "Albedo", "Light Layer Indices", "Scene" }); - // Set up Debug Draw Pass - auto debugDrawNode = worldRenderGraph->AddNode("Debug Draw", { "Scene" }, {"G-Buffer"}); + // Set up Debug Draw Passes + // - Depth Tested + auto debugDrawNodeDepth = worldRenderGraph->AddNode("Debug Draw with Depth", { "Scene", "Depth Buffer" }, {"G-Buffer"}); + auto debugDrawDepthSubpass = debugDrawNodeDepth->AddSubpass("Debug Draw with Depth"); + debugDrawDepthSubpass->AddColorOutput("Scene"); + debugDrawDepthSubpass->AddDepthOutput("Depth Buffer"); + // - No Depth Test + auto debugDrawNode = worldRenderGraph->AddNode("Debug Draw", { "Scene" }, { "Debug Draw with Depth" }); auto debugDrawSubpass = debugDrawNode->AddSubpass("Debug Draw"); debugDrawSubpass->AddColorOutput("Scene"); @@ -209,53 +215,8 @@ namespace SHADE defaultMaterial = AddMaterial(defaultVertShader, defaultFragShader, gBufferSubpass); // Create debug draw pipeline - auto debugDrawPipelineLayout = resourceManager.Create - ( - device, SHPipelineLayoutParams - { - .shaderModules = { debugVertShader, debugFragShader }, - .globalDescSetLayouts = SHGraphicsGlobalData::GetDescSetLayouts() - } - ); - debugDrawPipeline = resourceManager.Create(device, debugDrawPipelineLayout, nullptr, debugDrawNode->GetRenderpass(), debugDrawSubpass); - debugDrawPipeline->GetPipelineState().SetRasterizationState(SHRasterizationState - { - .polygonMode = vk::PolygonMode::eLine, - .cull_mode = vk::CullModeFlagBits::eNone - }); - debugDrawPipeline->GetPipelineState().SetInputAssemblyState(SHInputAssemblyState - { - .topology = vk::PrimitiveTopology::eLineList - }); - - SHVertexInputState debugDrawVertexInputState; - debugDrawVertexInputState.AddBinding(false, true, { SHVertexAttribute(SHAttribFormat::FLOAT_4D), SHVertexAttribute(SHAttribFormat::FLOAT_4D) }); - debugDrawPipeline->GetPipelineState().SetVertexInputState(debugDrawVertexInputState); - SHColorBlendState colorBlendState{}; - colorBlendState.logic_op_enable = VK_FALSE; - colorBlendState.logic_op = vk::LogicOp::eCopy; - - auto const& subpassColorReferences = debugDrawSubpass->GetColorAttachmentReferences(); - colorBlendState.attachments.reserve(subpassColorReferences.size()); - - for (auto& att : subpassColorReferences) - { - colorBlendState.attachments.push_back(vk::PipelineColorBlendAttachmentState - { - .blendEnable = SHVkUtil::IsBlendCompatible(debugDrawSubpass->GetFormatFromAttachmentReference(att.attachment)), - .srcColorBlendFactor = vk::BlendFactor::eSrcAlpha, - .dstColorBlendFactor = vk::BlendFactor::eOneMinusSrcAlpha, - .colorBlendOp = vk::BlendOp::eAdd, - .srcAlphaBlendFactor = vk::BlendFactor::eOne, - .dstAlphaBlendFactor = vk::BlendFactor::eZero, - .alphaBlendOp = vk::BlendOp::eAdd, - .colorWriteMask = vk::ColorComponentFlagBits::eR | vk::ColorComponentFlagBits::eG | vk::ColorComponentFlagBits::eB | vk::ColorComponentFlagBits::eA, - } - ); - } - - debugDrawPipeline->GetPipelineState().SetColorBlenState(colorBlendState); - debugDrawPipeline->ConstructPipeline(); + debugDrawPipeline = createDebugDrawPipeline(debugDrawNode->GetRenderpass(), debugDrawSubpass); + debugDrawDepthPipeline = createDebugDrawPipeline(debugDrawNodeDepth->GetRenderpass(), debugDrawDepthSubpass); } void SHGraphicsSystem::InitMiddleEnd(void) noexcept @@ -867,5 +828,57 @@ namespace SHADE return worldRenderGraph->GetNode(G_BUFFER_RENDER_GRAPH_NODE_NAME.data()); } + Handle SHGraphicsSystem::createDebugDrawPipeline(Handle renderPass, Handle subpass) + { + auto pipelineLayout = resourceManager.Create + ( + device, SHPipelineLayoutParams + { + .shaderModules = { debugVertShader, debugFragShader }, + .globalDescSetLayouts = SHGraphicsGlobalData::GetDescSetLayouts() + } + ); + auto pipeline = resourceManager.Create(device, pipelineLayout, nullptr, renderPass, subpass); + pipeline->GetPipelineState().SetRasterizationState(SHRasterizationState + { + .polygonMode = vk::PolygonMode::eLine, + .cull_mode = vk::CullModeFlagBits::eNone + }); + pipeline->GetPipelineState().SetInputAssemblyState(SHInputAssemblyState + { + .topology = vk::PrimitiveTopology::eLineList + }); + + SHVertexInputState debugDrawVertexInputState; + debugDrawVertexInputState.AddBinding(false, true, { SHVertexAttribute(SHAttribFormat::FLOAT_4D), SHVertexAttribute(SHAttribFormat::FLOAT_4D) }); + pipeline->GetPipelineState().SetVertexInputState(debugDrawVertexInputState); + SHColorBlendState colorBlendState{}; + colorBlendState.logic_op_enable = VK_FALSE; + colorBlendState.logic_op = vk::LogicOp::eCopy; + + auto const& subpassColorReferences = subpass->GetColorAttachmentReferences(); + colorBlendState.attachments.reserve(subpassColorReferences.size()); + + for (auto& att : subpassColorReferences) + { + colorBlendState.attachments.push_back(vk::PipelineColorBlendAttachmentState + { + .blendEnable = SHVkUtil::IsBlendCompatible(subpass->GetFormatFromAttachmentReference(att.attachment)), + .srcColorBlendFactor = vk::BlendFactor::eSrcAlpha, + .dstColorBlendFactor = vk::BlendFactor::eOneMinusSrcAlpha, + .colorBlendOp = vk::BlendOp::eAdd, + .srcAlphaBlendFactor = vk::BlendFactor::eOne, + .dstAlphaBlendFactor = vk::BlendFactor::eZero, + .alphaBlendOp = vk::BlendOp::eAdd, + .colorWriteMask = vk::ColorComponentFlagBits::eR | vk::ColorComponentFlagBits::eG | vk::ColorComponentFlagBits::eB | vk::ColorComponentFlagBits::eA, + }); + } + + pipeline->GetPipelineState().SetColorBlenState(colorBlendState); + pipeline->ConstructPipeline(); + + return pipeline; + } + #pragma endregion MISC } diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.h b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.h index b307dc92..07e5fbab 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.h +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.h @@ -289,6 +289,7 @@ namespace SHADE Handle GetPostOffscreenRenderSystem(void) const noexcept {return postOffscreenRender;}; Handle GetPrimaryRenderpass() const noexcept; Handle GetDebugDrawPipeline(void) const noexcept { return debugDrawPipeline; } + Handle GetDebugDrawDepthPipeline(void) const noexcept { return debugDrawDepthPipeline; } uint32_t GetCurrentFrameIndex(void) const noexcept { return renderContext.GetCurrentFrame(); } /*-----------------------------------------------------------------------------*/ @@ -355,6 +356,7 @@ namespace SHADE // Built-In Materials Handle defaultMaterial; Handle debugDrawPipeline; + Handle debugDrawDepthPipeline; Handle worldRenderGraph; @@ -367,5 +369,9 @@ namespace SHADE uint32_t resizeHeight; bool restoredFromMinimize = false; + /*---------------------------------------------------------------------------------*/ + /* Helper Functions */ + /*---------------------------------------------------------------------------------*/ + Handle createDebugDrawPipeline(Handle renderPass, Handle subpass); }; } \ No newline at end of file