From 03becd8e471aec37ffcbb1d166dd852197d052f8 Mon Sep 17 00:00:00 2001 From: Brandon Mak Date: Sun, 1 Jan 2023 13:59:10 +0800 Subject: [PATCH 01/45] Removing resources now remove subpasses and computes involved - Added an empty node in the render graph for shadow mapping --- .../MiddleEnd/Interface/SHGraphicsSystem.cpp | 5 +- .../Graphics/RenderGraph/SHRenderGraph.cpp | 109 +++++----- .../src/Graphics/RenderGraph/SHRenderGraph.h | 1 - .../RenderGraph/SHRenderGraphNode.cpp | 198 ++++++++++-------- .../RenderGraph/SHRenderGraphNodeCompute.cpp | 78 ++++--- .../RenderGraph/SHRenderGraphNodeCompute.h | 12 ++ .../src/Graphics/RenderGraph/SHSubpass.cpp | 26 +-- .../src/Graphics/RenderGraph/SHSubpass.h | 7 +- 8 files changed, 241 insertions(+), 195 deletions(-) diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp index b1256921..18d79579 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp @@ -259,9 +259,7 @@ namespace SHADE /*-----------------------------------------------------------------------*/ // Shadow map pass will have no resources bound at first. Lighting system will add resources to the node. // It will initially also not have any subpasses since they will be added for each light that casts shadows. - //auto shadowMapPass = renderGraph->AddNode("Shadow Map Pass", {}, {}); - - + auto shadowMapPass = renderGraph->AddNode("Shadow Map Pass", {}, {}); /*-----------------------------------------------------------------------*/ /* DEFERRED COMPOSITE NODE */ @@ -450,6 +448,7 @@ namespace SHADE InitMiddleEnd(); InitSubsystems(); InitBuiltInResources(); + InitEvents(); } void SHGraphicsSystem::Exit(void) diff --git a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraph.cpp b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraph.cpp index 74371a64..e9a0e0bd 100644 --- a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraph.cpp +++ b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraph.cpp @@ -106,6 +106,9 @@ namespace SHADE for (auto& affectedNode : affectedNodes) nodes[affectedNode]->CreateFramebuffer(); + + renderGraphStorage->graphResources->at(resourceName).Free(); + renderGraphStorage->graphResources->erase (resourceName); /* * IMPORTANT NOTES * @@ -168,65 +171,62 @@ namespace SHADE { // key is handle ID, value is final layout. std::unordered_map resourceAttFinalLayouts; - if (node->subpasses.empty()) + if (!node->subpasses.empty()) { - SHLOG_ERROR("Node does not contain a subpass. Cannot configure attachment descriptions as a result. "); - return; - } - - // We first want to take all resources track their layout as undefined at the start of the node/renderpass - auto const resources = node->GetResources(); - for (auto& resource : resources) - { - resource->GetInfoTracker()->TrackLayout(node, {}, vk::ImageLayout::eUndefined); - } - - // attempt to get all final layouts for all resources - for (auto& subpass : node->subpasses) - { - for (auto& color : subpass->colorReferences) + // We first want to take all resources track their layout as undefined at the start of the node/renderpass + auto const resources = node->GetResources(); + for (auto& resource : resources) { - // If final renderpass and attachment is a COLOR_PRESENT resource, make resource transition to present after last subpass - if (i == nodes.size() - 1 && (node->attResources[color.attachment]->resourceTypeFlags & static_cast(SH_RENDER_GRAPH_RESOURCE_FLAGS::COLOR_PRESENT))) - resourceAttFinalLayouts[color.attachment] = vk::ImageLayout::ePresentSrcKHR; - else - resourceAttFinalLayouts[color.attachment] = color.layout; - - node->attResources[color.attachment]->infoTracker->TrackLayout(node, subpass, color.layout); + resource->GetInfoTracker()->TrackLayout(node, {}, vk::ImageLayout::eUndefined); } - for (auto& depth : subpass->depthReferences) + // attempt to get all final layouts for all resources + for (auto& subpass : node->subpasses) { - resourceAttFinalLayouts[depth.attachment] = depth.layout; - node->attResources[depth.attachment]->infoTracker->TrackLayout(node, subpass, depth.layout); + for (auto& color : subpass->colorReferences) + { + // If final renderpass and attachment is a COLOR_PRESENT resource, make resource transition to present after last subpass + if (i == nodes.size() - 1 && (node->attResources[color.attachment]->resourceTypeFlags & static_cast(SH_RENDER_GRAPH_RESOURCE_FLAGS::COLOR_PRESENT))) + resourceAttFinalLayouts[color.attachment] = vk::ImageLayout::ePresentSrcKHR; + else + resourceAttFinalLayouts[color.attachment] = color.layout; + + node->attResources[color.attachment]->infoTracker->TrackLayout(node, subpass, color.layout); + } + + for (auto& depth : subpass->depthReferences) + { + resourceAttFinalLayouts[depth.attachment] = depth.layout; + node->attResources[depth.attachment]->infoTracker->TrackLayout(node, subpass, depth.layout); + } + + for (auto& input : subpass->inputReferences) + { + resourceAttFinalLayouts[input.attachment] = input.layout; + node->attResources[input.attachment]->infoTracker->TrackLayout(node, subpass, input.layout); + } } - for (auto& input : subpass->inputReferences) + for (uint32_t j = 0; j < node->attachmentDescriptions.size(); ++j) { - resourceAttFinalLayouts[input.attachment] = input.layout; - node->attResources[input.attachment]->infoTracker->TrackLayout(node, subpass, input.layout); - } - } + auto& att = node->attachmentDescriptions[j]; + auto& resource = node->attResources[j]; - for (uint32_t j = 0; j < node->attachmentDescriptions.size(); ++j) - { - auto& att = node->attachmentDescriptions[j]; - auto& resource = node->attResources[j]; - - // If resource is from another render graph, use the final layout it had when it was last used in that graph. This is initialized in LinkNonOwningResource. - // We also want to load the attachment, not "don't care". - if (resource->resourceTypeFlags & SHUtilities::ConvertEnum(SH_RENDER_GRAPH_RESOURCE_FLAGS::SHARED) && + // If resource is from another render graph, use the final layout it had when it was last used in that graph. This is initialized in LinkNonOwningResource. + // We also want to load the attachment, not "don't care". + if (resource->resourceTypeFlags & SHUtilities::ConvertEnum(SH_RENDER_GRAPH_RESOURCE_FLAGS::SHARED) && renderGraphStorage->nonOwningResourceInitialLayouts.contains(resource.GetId().Raw)) - { - att.initialLayout = renderGraphStorage->nonOwningResourceInitialLayouts.at (resource.GetId().Raw); - att.loadOp = vk::AttachmentLoadOp::eLoad; - att.stencilLoadOp = vk::AttachmentLoadOp::eLoad; - } - else - att.initialLayout = vk::ImageLayout::eUndefined; + { + att.initialLayout = renderGraphStorage->nonOwningResourceInitialLayouts.at(resource.GetId().Raw); + att.loadOp = vk::AttachmentLoadOp::eLoad; + att.stencilLoadOp = vk::AttachmentLoadOp::eLoad; + } + else + att.initialLayout = vk::ImageLayout::eUndefined; - att.finalLayout = resourceAttFinalLayouts[j]; - resource->GetInfoTracker()->TrackLayout(node, {}, att.finalLayout); + att.finalLayout = resourceAttFinalLayouts[j]; + resource->GetInfoTracker()->TrackLayout(node, {}, att.finalLayout); + } } ++i; } @@ -532,10 +532,6 @@ namespace SHADE ConfigureSubSystems(); } - void SHRenderGraph::Regenerate(void) noexcept - { - - } /***************************************************************************/ /*! @@ -572,10 +568,13 @@ namespace SHADE for (auto& node : nodes) { - // bind static global data - SHGlobalDescriptorSets::BindStaticGlobalData(cmdBuffer, SH_PIPELINE_TYPE::GRAPHICS, descMappings.at(SHPredefinedDescriptorTypes::STATIC_DATA)); + if (node->renderpass) + { + // bind static global data + SHGlobalDescriptorSets::BindStaticGlobalData(cmdBuffer, SH_PIPELINE_TYPE::GRAPHICS, descMappings.at(SHPredefinedDescriptorTypes::STATIC_DATA)); - node->Execute(cmdBuffer, descPool, frameIndex); + node->Execute(cmdBuffer, descPool, frameIndex); + } } cmdBuffer->EndLabeledSegment(); diff --git a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraph.h b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraph.h index c7fe221b..7dc19a80 100644 --- a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraph.h +++ b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraph.h @@ -134,7 +134,6 @@ namespace SHADE ) noexcept; void Generate (void) noexcept; - void Regenerate (void) noexcept; void CheckForNodeComputes (void) noexcept; void Execute (uint32_t frameIndex, Handle descPool) noexcept; void Begin (uint32_t frameIndex) noexcept; diff --git a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNode.cpp b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNode.cpp index 3c412645..56d8734a 100644 --- a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNode.cpp +++ b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNode.cpp @@ -32,8 +32,11 @@ namespace SHADE renderpass.Free(); } - renderpass = graphStorage->logicalDevice->CreateRenderpass(attachmentDescriptions, spDescs, spDeps); - SET_VK_OBJ_NAME(graphStorage->logicalDevice, vk::ObjectType::eRenderPass, renderpass->GetVkRenderpass(), "[RenderPass] " + name); + if (!spDescs.empty()) + { + renderpass = graphStorage->logicalDevice->CreateRenderpass(attachmentDescriptions, spDescs, spDeps); + SET_VK_OBJ_NAME(graphStorage->logicalDevice, vk::ObjectType::eRenderPass, renderpass->GetVkRenderpass(), "[RenderPass] " + name); + } } /***************************************************************************/ @@ -46,77 +49,86 @@ namespace SHADE /***************************************************************************/ void SHRenderGraphNode::CreateFramebuffer(void) noexcept { - if (!framebuffers.empty()) + if (renderpass) { - for (auto fbo : framebuffers) + if (!framebuffers.empty()) { - if (fbo) - fbo.Free(); - } - } - - for (uint32_t i = 0; i < framebuffers.size(); ++i) - { - std::vector> imageViews(attResources.size()); - uint32_t fbWidth = std::numeric_limits::max(); - uint32_t fbHeight = std::numeric_limits::max(); - - for (uint32_t j = 0; j < attResources.size(); ++j) - { - uint32_t imageViewIndex = (attResources[j]->resourceTypeFlags & static_cast(SH_RENDER_GRAPH_RESOURCE_FLAGS::COLOR_PRESENT)) ? i : 0; - imageViews[j] = attResources[j]->imageViews[imageViewIndex]; - - // We want the minimum dimensions for the framebuffer because the image attachments referenced cannot have dimensions smaller than the framebuffer's - if (fbWidth > attResources[j]->width) - fbWidth = attResources[j]->width; - if (fbHeight > attResources[j]->height) - fbHeight = attResources[j]->height; + for (auto fbo : framebuffers) + { + if (fbo) + fbo.Free(); + } } + for (uint32_t i = 0; i < framebuffers.size(); ++i) + { + std::vector> imageViews(attResources.size()); + uint32_t fbWidth = std::numeric_limits::max(); + uint32_t fbHeight = std::numeric_limits::max(); - framebuffers[i] = graphStorage->logicalDevice->CreateFramebuffer(renderpass, imageViews, fbWidth, fbHeight); - SET_VK_OBJ_NAME(graphStorage->logicalDevice, vk::ObjectType::eFramebuffer, framebuffers[i]->GetVkFramebuffer(), "[Framebuffer] " + name + std::to_string(i)); + for (uint32_t j = 0; j < attResources.size(); ++j) + { + uint32_t imageViewIndex = (attResources[j]->resourceTypeFlags & static_cast(SH_RENDER_GRAPH_RESOURCE_FLAGS::COLOR_PRESENT)) ? i : 0; + imageViews[j] = attResources[j]->imageViews[imageViewIndex]; + + // We want the minimum dimensions for the framebuffer because the image attachments referenced cannot have dimensions smaller than the framebuffer's + if (fbWidth > attResources[j]->width) + fbWidth = attResources[j]->width; + if (fbHeight > attResources[j]->height) + fbHeight = attResources[j]->height; + } + + + framebuffers[i] = graphStorage->logicalDevice->CreateFramebuffer(renderpass, imageViews, fbWidth, fbHeight); + SET_VK_OBJ_NAME(graphStorage->logicalDevice, vk::ObjectType::eFramebuffer, framebuffers[i]->GetVkFramebuffer(), "[Framebuffer] " + name + std::to_string(i)); + } } } void SHRenderGraphNode::HandleResize(void) noexcept { - renderpass->HandleResize(); - - for (uint32_t i = 0; i < framebuffers.size(); ++i) + if (renderpass) { - std::vector> imageViews(attResources.size()); - uint32_t fbWidth = std::numeric_limits::max(); - uint32_t fbHeight = std::numeric_limits::max(); + renderpass->HandleResize(); - for (uint32_t j = 0; j < attResources.size(); ++j) + for (uint32_t i = 0; i < framebuffers.size(); ++i) { - uint32_t imageViewIndex = (attResources[j]->resourceTypeFlags & static_cast(SH_RENDER_GRAPH_RESOURCE_FLAGS::COLOR_PRESENT)) ? i : 0; - imageViews[j] = attResources[j]->imageViews[imageViewIndex]; + std::vector> imageViews(attResources.size()); + uint32_t fbWidth = std::numeric_limits::max(); + uint32_t fbHeight = std::numeric_limits::max(); - // We want the minimum dimensions for the framebuffer because the image attachments referenced cannot have dimensions smaller than the framebuffer's - if (fbWidth > attResources[j]->width) - fbWidth = attResources[j]->width; - if (fbHeight > attResources[j]->height) - fbHeight = attResources[j]->height; + for (uint32_t j = 0; j < attResources.size(); ++j) + { + uint32_t imageViewIndex = (attResources[j]->resourceTypeFlags & static_cast(SH_RENDER_GRAPH_RESOURCE_FLAGS::COLOR_PRESENT)) ? i : 0; + imageViews[j] = attResources[j]->imageViews[imageViewIndex]; + + // We want the minimum dimensions for the framebuffer because the image attachments referenced cannot have dimensions smaller than the framebuffer's + if (fbWidth > attResources[j]->width) + fbWidth = attResources[j]->width; + if (fbHeight > attResources[j]->height) + fbHeight = attResources[j]->height; + } + + framebuffers[i]->HandleResize(renderpass, imageViews, fbWidth, fbHeight); } - framebuffers[i]->HandleResize(renderpass, imageViews, fbWidth, fbHeight); - } + for (auto& subpass : subpasses) + { + subpass->HandleResize(); + } - for (auto& subpass : subpasses) - { - subpass->HandleResize(); - } - - for (auto& nodeCompute : nodeComputes) - { - nodeCompute->HandleResize(); + for (auto& nodeCompute : nodeComputes) + { + nodeCompute->HandleResize(); + } } } void SHRenderGraphNode::ConfigureSubpasses(void) noexcept { + if (subpasses.empty()) + return; + // Create subpass description and dependencies based on number of subpasses spDescs.resize(subpasses.size()); spDeps.resize(subpasses.size()); @@ -512,11 +524,8 @@ namespace SHADE // Remove footprint of attachment from all subpasses as well for (auto it = subpasses.begin(); it != subpasses.end(); ++it) { - // attempt to detach resource from subpass - (*it)->DetachResource(resourceName, index); - - // If the subpass ends up having no attachments after, erase it from the node - if ((*it)->HasNoAttachments()) + // If the subpass uses the resource, just remove the subpass since the subpass will be invalid + if ((*it)->UsesResource(index)) { // erase from indexing subpassIndexing.erase((*it)->GetName()); @@ -530,6 +539,24 @@ namespace SHADE for (uint32_t i = 0; i < subpasses.size(); ++i) subpasses[i]->SetIndex(i); + // remove node computes using the resource + for (auto it = nodeComputes.begin(); it != nodeComputes.end(); ++it) + { + if ((*it)->UsesResource(resourceHandleID)) + { + it = nodeComputes.erase(it); + } + } + + // recompute the barriers for the other computes + for (auto it = nodeComputes.begin(); it != nodeComputes.end(); ++it) + { + if (it == nodeComputes.begin()) + (*it)->SetFollowingEndRenderpass(true); + + (*it)->InitializeBarriers(); + } + return true; } return false; @@ -537,37 +564,40 @@ namespace SHADE void SHRenderGraphNode::Execute(Handle commandBuffer, Handle descPool, uint32_t frameIndex) noexcept { - uint32_t framebufferIndex = (framebuffers.size() > 1) ? frameIndex : 0; - commandBuffer->BeginRenderpass(renderpass, framebuffers[framebufferIndex]); - - for (uint32_t i = 0; i < subpasses.size(); ++i) + if (renderpass) { - subpasses[i]->Execute(commandBuffer, descPool, frameIndex); + uint32_t framebufferIndex = (framebuffers.size() > 1) ? frameIndex : 0; + commandBuffer->BeginRenderpass(renderpass, framebuffers[framebufferIndex]); - // Go to next subpass if not last subpass - if (i != static_cast(subpasses.size()) - 1u) - commandBuffer->NextSubpass(); + for (uint32_t i = 0; i < subpasses.size(); ++i) + { + subpasses[i]->Execute(commandBuffer, descPool, frameIndex); + + // Go to next subpass if not last subpass + if (i != static_cast(subpasses.size()) - 1u) + commandBuffer->NextSubpass(); + } + + commandBuffer->EndRenderpass(); + + auto const& descMappings = SHGraphicsPredefinedData::GetMappings(SHGraphicsPredefinedData::SystemType::RENDER_GRAPH_NODE_COMPUTE); + + // We bind these 2 descriptor sets here because they apply to all node computes + if (!nodeComputes.empty()) + { + commandBuffer->ForceSetPipelineLayout(SHGraphicsPredefinedData::GetSystemData(SHGraphicsPredefinedData::SystemType::RENDER_GRAPH_NODE_COMPUTE).dummyPipelineLayout, SH_PIPELINE_TYPE::COMPUTE); + + // bind static global data + SHGlobalDescriptorSets::BindStaticGlobalData(commandBuffer, SH_PIPELINE_TYPE::COMPUTE, descMappings.at(SHPredefinedDescriptorTypes::STATIC_DATA)); + + // bind lighting data + SHGlobalDescriptorSets::BindLightingData(commandBuffer, SH_PIPELINE_TYPE::COMPUTE, descMappings.at(SHPredefinedDescriptorTypes::LIGHTS), frameIndex); + } + + // Execute all subpass computes + for (auto& sbCompute : nodeComputes) + sbCompute->Execute(commandBuffer, frameIndex); } - - commandBuffer->EndRenderpass(); - - auto const& descMappings = SHGraphicsPredefinedData::GetMappings(SHGraphicsPredefinedData::SystemType::RENDER_GRAPH_NODE_COMPUTE); - - // We bind these 2 descriptor sets here because they apply to all node computes - if (!nodeComputes.empty()) - { - commandBuffer->ForceSetPipelineLayout(SHGraphicsPredefinedData::GetSystemData(SHGraphicsPredefinedData::SystemType::RENDER_GRAPH_NODE_COMPUTE).dummyPipelineLayout, SH_PIPELINE_TYPE::COMPUTE); - - // bind static global data - SHGlobalDescriptorSets::BindStaticGlobalData(commandBuffer, SH_PIPELINE_TYPE::COMPUTE, descMappings.at(SHPredefinedDescriptorTypes::STATIC_DATA)); - - // bind lighting data - SHGlobalDescriptorSets::BindLightingData(commandBuffer, SH_PIPELINE_TYPE::COMPUTE, descMappings.at(SHPredefinedDescriptorTypes::LIGHTS), frameIndex); - } - - // Execute all subpass computes - for (auto& sbCompute : nodeComputes) - sbCompute->Execute(commandBuffer, frameIndex); } Handle SHRenderGraphNode::GetOrCreatePipeline(std::pair, Handle> const& vsFsPair, Handle subpass) noexcept diff --git a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNodeCompute.cpp b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNodeCompute.cpp index cfc8443c..e1bc3842 100644 --- a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNodeCompute.cpp +++ b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNodeCompute.cpp @@ -14,6 +14,54 @@ namespace SHADE { + + bool SHRenderGraphNodeCompute::UsesResource(uint64_t resourceHandleID) const noexcept + { + for (auto& resource : resources) + { + if (resource.GetId().Raw == resourceHandleID) + return true; + } + return false; + } + + void SHRenderGraphNodeCompute::InitializeBarriers(void) noexcept + { + for (uint32_t i = 0; auto & barriers : memoryBarriers) + { + barriers.clear(); + + for (auto& resource : resources) + { + vk::AccessFlags srcAccessMask = (followingEndRenderpass) ? vk::AccessFlagBits::eInputAttachmentRead : (vk::AccessFlagBits::eShaderRead | vk::AccessFlagBits::eShaderWrite); + barriers.push_back(vk::ImageMemoryBarrier + { + .srcAccessMask = srcAccessMask, + .dstAccessMask = vk::AccessFlagBits::eShaderRead | vk::AccessFlagBits::eShaderWrite, + .oldLayout = vk::ImageLayout::eGeneral, + .newLayout = vk::ImageLayout::eGeneral, + .srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED, + .dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED, + .image = resource->GetImage((resource->resourceTypeFlags & static_cast(SH_RENDER_GRAPH_RESOURCE_FLAGS::COLOR_PRESENT)) ? i : 0)->GetVkImage(), + .subresourceRange = vk::ImageSubresourceRange + { + .aspectMask = resource->imageAspectFlags, + .baseMipLevel = 0, + .levelCount = resource->mipLevels, + .baseArrayLayer = 0, + .layerCount = 1, + } + }); + } + ++i; + } + } + + void SHRenderGraphNodeCompute::SetFollowingEndRenderpass(uint32_t flag) noexcept + { + followingEndRenderpass = flag; + } + SHRenderGraphNodeCompute::SHRenderGraphNodeCompute(std::string nodeName, Handle graphStorage, Handle computeShaderModule, std::vector>&& subpassComputeResources, std::unordered_set&& dynamicBufferBindings, bool followingEndRP, float inNumWorkGroupScale/* = 1.0f*/) noexcept : computePipeline{} , pipelineLayout{} @@ -157,35 +205,7 @@ namespace SHADE groupSizeX = maxWidth / workGroupSizeX; groupSizeY = maxHeight / workGroupSizeY; - for (uint32_t i = 0; auto& barriers : memoryBarriers) - { - barriers.clear(); - - for (auto& resource : resources) - { - vk::AccessFlags srcAccessMask = (followingEndRenderpass) ? vk::AccessFlagBits::eInputAttachmentRead : (vk::AccessFlagBits::eShaderRead | vk::AccessFlagBits::eShaderWrite); - barriers.push_back(vk::ImageMemoryBarrier - { - .srcAccessMask = srcAccessMask, - .dstAccessMask = vk::AccessFlagBits::eShaderRead | vk::AccessFlagBits::eShaderWrite, - .oldLayout = vk::ImageLayout::eGeneral, - .newLayout = vk::ImageLayout::eGeneral, - .srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED, - .dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED, - .image = resource->GetImage((resource->resourceTypeFlags & static_cast(SH_RENDER_GRAPH_RESOURCE_FLAGS::COLOR_PRESENT)) ? i : 0)->GetVkImage(), - .subresourceRange = vk::ImageSubresourceRange - { - .aspectMask = resource->imageAspectFlags, - .baseMipLevel = 0, - .levelCount = resource->mipLevels, - .baseArrayLayer = 0, - .layerCount = 1, - } - }); - } - - ++i; - } + InitializeBarriers(); } void SHRenderGraphNodeCompute::SetDynamicOffsets(std::span perFrameSizes) noexcept diff --git a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNodeCompute.h b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNodeCompute.h index dc3ca886..476099c7 100644 --- a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNodeCompute.h +++ b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNodeCompute.h @@ -73,6 +73,18 @@ namespace SHADE //! Name of this node std::string name; + private: + /*-----------------------------------------------------------------------*/ + /* PRIVATE MEMBER FUNCTIONS */ + /*-----------------------------------------------------------------------*/ + bool UsesResource (uint64_t resourceHandleID) const noexcept; + void InitializeBarriers (void) noexcept; + + /*-----------------------------------------------------------------------*/ + /* PRIVATE SETTERS AND GETTERS */ + /*-----------------------------------------------------------------------*/ + void SetFollowingEndRenderpass (uint32_t flag) noexcept; + public: SHRenderGraphNodeCompute(std::string nodeName, Handle graphStorage, Handle computeShaderModule, std::vector>&& subpassComputeResources, std::unordered_set&& dynamicBufferBindings, bool followingEndRP, float inNumWorkGroupScale = 1.0f) noexcept; diff --git a/SHADE_Engine/src/Graphics/RenderGraph/SHSubpass.cpp b/SHADE_Engine/src/Graphics/RenderGraph/SHSubpass.cpp index 3d2b1699..1f03bbc4 100644 --- a/SHADE_Engine/src/Graphics/RenderGraph/SHSubpass.cpp +++ b/SHADE_Engine/src/Graphics/RenderGraph/SHSubpass.cpp @@ -265,42 +265,24 @@ namespace SHADE */ /***************************************************************************/ - void SHSubpass::DetachResource(std::string const& resourceName, uint32_t attachmentIndex) noexcept + bool SHSubpass::UsesResource(uint32_t attachmentIndex) noexcept { for (uint32_t i = 0; i < colorReferences.size(); ++i) { if (colorReferences[i].attachment == attachmentIndex) - { - colorReferences.erase (colorReferences.begin() + i); - break; - } + return true; } for (uint32_t i = 0; i < depthReferences.size(); ++i) { if (depthReferences[i].attachment == attachmentIndex) - { - depthReferences.erase(depthReferences.begin() + i); - break; - } + return true; } for (uint32_t i = 0; i < inputReferences.size(); ++i) { if (inputReferences[i].attachment == attachmentIndex) - { - inputReferences.erase(inputReferences.begin() + i); - break; - } - } - - for (uint32_t i = 0; i < inputNames.size(); ++i) - { - if (inputNames[i] == resourceName) - { - inputNames.erase(inputNames.begin() + i); - break; - } + return true; } } diff --git a/SHADE_Engine/src/Graphics/RenderGraph/SHSubpass.h b/SHADE_Engine/src/Graphics/RenderGraph/SHSubpass.h index 6c582aa6..7f1bd3da 100644 --- a/SHADE_Engine/src/Graphics/RenderGraph/SHSubpass.h +++ b/SHADE_Engine/src/Graphics/RenderGraph/SHSubpass.h @@ -95,6 +95,12 @@ namespace SHADE std::string name; + private: + /*-----------------------------------------------------------------------*/ + /* PRIVATE MEMBER FUNCTIONS */ + /*-----------------------------------------------------------------------*/ + bool UsesResource(uint32_t attachmentIndex) noexcept; + public: /*-----------------------------------------------------------------------*/ /* CTORS AND DTORS */ @@ -119,7 +125,6 @@ namespace SHADE void Execute(Handle commandBuffer, Handle descPool, uint32_t frameIndex) noexcept; void HandleResize (void) noexcept; void BindInputDescriptorSets (Handle cmdBuffer, uint32_t setIndex, uint32_t frameIndex) const noexcept; - void DetachResource (std::string const& resourceName, uint32_t attachmentIndex) noexcept; bool HasNoAttachments (void) const noexcept; void Init(SHResourceHub& resourceManager) noexcept; From 7f8dc2b6478296a7cf71053de1916acac9a4ffb8 Mon Sep 17 00:00:00 2001 From: Brandon Mak Date: Mon, 2 Jan 2023 18:24:29 +0800 Subject: [PATCH 02/45] Added constants for render graph node names - Fleshed out event function to add resource and subpass to shadow map render graph node when shadow is turned on - Added support for linking resources and subpasses to render graph at runtime --- SHADE_Engine/src/Editor/SHEditor.cpp | 4 +- .../MiddleEnd/Interface/SHDebugDrawSystem.cpp | 4 +- .../MiddleEnd/Interface/SHGraphicsConstants.h | 133 +++++++++-------- .../MiddleEnd/Interface/SHGraphicsSystem.cpp | 48 ++++--- .../MiddleEnd/Interface/SHGraphicsSystem.h | 6 +- .../Graphics/RenderGraph/SHRenderGraph.cpp | 60 +------- .../src/Graphics/RenderGraph/SHRenderGraph.h | 9 +- .../RenderGraph/SHRenderGraphNode.cpp | 136 ++++++++++++++++++ .../Graphics/RenderGraph/SHRenderGraphNode.h | 19 ++- 9 files changed, 266 insertions(+), 153 deletions(-) diff --git a/SHADE_Engine/src/Editor/SHEditor.cpp b/SHADE_Engine/src/Editor/SHEditor.cpp index 93b42418..f3fe6b72 100644 --- a/SHADE_Engine/src/Editor/SHEditor.cpp +++ b/SHADE_Engine/src/Editor/SHEditor.cpp @@ -502,7 +502,7 @@ namespace SHADE //auto const& renderers = gfxSystem->GetDefaultViewport()->GetRenderers(); auto renderGraph = gfxSystem->GetRenderGraph(); - auto renderPass = renderGraph->GetNode("ImGui Node")->GetRenderpass(); + auto renderPass = renderGraph->GetNode(SHGraphicsConstants::RenderGraphNodeNames::IMGUI_PASS.data())->GetRenderpass(); if(ImGui_ImplVulkan_Init(&initInfo, renderPass->GetVkRenderpass()) == false) { @@ -521,7 +521,7 @@ namespace SHADE ImGui_ImplVulkan_DestroyFontUploadObjects(); - renderGraph->GetNode("ImGui Node")->GetSubpass("ImGui Draw")->AddExteriorDrawCalls([](Handle cmd, Handle renderer, uint32_t frameIndex) + renderGraph->GetNode(SHGraphicsConstants::RenderGraphNodeNames::IMGUI_PASS.data())->GetSubpass("ImGui Draw")->AddExteriorDrawCalls([](Handle cmd, Handle renderer, uint32_t frameIndex) { cmd->BeginLabeledSegment("ImGui Draw"); ImGui_ImplVulkan_RenderDrawData(ImGui::GetDrawData(), cmd->GetVkCommandBuffer()); diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHDebugDrawSystem.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHDebugDrawSystem.cpp index b57249de..fc701da3 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHDebugDrawSystem.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHDebugDrawSystem.cpp @@ -101,7 +101,7 @@ namespace SHADE // Register function for subpass //auto const& RENDERERS = gfxSystem->GetDefaultViewport()->GetRenderers(); auto renderGraph = gfxSystem->GetRenderGraph(); - auto subPass = renderGraph->GetNode("Debug Draw")->GetSubpass("Debug Draw"); + auto subPass = renderGraph->GetNode(SHGraphicsConstants::RenderGraphNodeNames::DEBUG_DRAW.data())->GetSubpass("Debug Draw"); subPass->AddExteriorDrawCalls([this](Handle cmdBuffer, Handle renderer, uint32_t frameIndex) { const uint32_t FRAME_IDX = gfxSystem->GetCurrentFrameIndex(); @@ -125,7 +125,7 @@ namespace SHADE } cmdBuffer->EndLabeledSegment(); }); - auto subPassWithDepth = renderGraph->GetNode("Debug Draw with Depth")->GetSubpass("Debug Draw with Depth"); + auto subPassWithDepth = renderGraph->GetNode(SHGraphicsConstants::RenderGraphNodeNames::DEBUG_DRAW_DEPTH_PASS.data())->GetSubpass("Debug Draw with Depth"); subPassWithDepth->AddExteriorDrawCalls([this](Handle cmdBuffer, Handle renderer, uint32_t frameIndex) { const uint32_t FRAME_IDX = gfxSystem->GetCurrentFrameIndex(); diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsConstants.h b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsConstants.h index c889a321..f331ce02 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsConstants.h +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsConstants.h @@ -31,68 +31,79 @@ namespace SHADE static constexpr uint32_t EDITOR = 0; }; - //struct DescriptorSetIndex - //{ - // /***************************************************************************/ - // /*! - // \brief - // DescriptorSet Index for static global values like generic data, and - // texture samplers - // */ - // /***************************************************************************/ - // static constexpr uint32_t STATIC_GLOBALS = 0; - // /***************************************************************************/ - // /*! - // \brief - // DescriptorSet Index for dynamic global values like lights. - // */ - // /***************************************************************************/ - // static constexpr uint32_t DYNAMIC_GLOBALS = 1; - // /***************************************************************************/ - // /*! - // \brief - // DescriptorSet Index for high frequency changing global values like - // camera matrices. - // */ - // /***************************************************************************/ - // static constexpr uint32_t HIGH_FREQUENCY_GLOBALS = 2; - // /***************************************************************************/ - // /*! - // \brief - // DescriptorSet Index for per-instance/material changing values. - // */ - // /***************************************************************************/ - // static constexpr uint32_t PER_INSTANCE = 3; - // /***************************************************************************/ - // /*! - // \brief - // DescriptorSet Index for render graph resources. Unlike the sets from - // 1 to 3 and 6, this set index does not have hard coded bindings and is - // NOT part of the layouts included in the global data. - // */ - // /***************************************************************************/ - // static constexpr uint32_t RENDERGRAPH_RESOURCE = 4; - // /***************************************************************************/ - // /*! - // \brief - // DescriptorSet Index for render graph node compute resources. For data - // that we wish to pass to compute shaders in the render graph, this is - // the set to use. Unlike the sets from 1 to 3 and 6, this set index does not have - // hard coded bindings and is NOT part of the layouts included in the global - // data. - // */ - // /***************************************************************************/ - // static constexpr uint32_t RENDERGRAPH_NODE_COMPUTE_RESOURCE = 5; + struct RenderGraphNodeNames + { + /***************************************************************************/ + /*! + + \brief + Name of G-Buffer render graph node. + + */ + /***************************************************************************/ + static constexpr std::string_view GBUFFER_PASS = "G-Buffer"; - // /***************************************************************************/ - // /*! - // \brief - // To store font data. - // - // */ - // /***************************************************************************/ - // static constexpr uint32_t FONT_DATA = 4; - //}; + /***************************************************************************/ + /*! + + \brief + Name of shadow map render graph node. + + */ + /***************************************************************************/ + static constexpr std::string_view SHADOW_MAP_PASS = "Shadow Map Pass"; + + /***************************************************************************/ + /*! + + \brief + Name of deferred composite render graph node. + + */ + /***************************************************************************/ + static constexpr std::string_view DEFERRED_COMPOSITE_PASS = "Deferred Comp Pass"; + + /***************************************************************************/ + /*! + + \brief + Name of Debug Draw with Depth render graph node. + + */ + /***************************************************************************/ + static constexpr std::string_view DEBUG_DRAW_DEPTH_PASS = "Debug Draw with Depth Pass"; + + /***************************************************************************/ + /*! + + \brief + Name of Debug Draw render graph node. + + */ + /***************************************************************************/ + static constexpr std::string_view DEBUG_DRAW = "Debug Draw Pass"; + + /***************************************************************************/ + /*! + + \brief + Name of screen space pass render graph node. + + */ + /***************************************************************************/ + static constexpr std::string_view SCREEN_SPACE_PASS = "Screen Space Pass"; + + /***************************************************************************/ + /*! + + \brief + Name of ImGui pass render graph node. + + */ + /***************************************************************************/ + static constexpr std::string_view IMGUI_PASS = "ImGui Pass"; + + }; struct DescriptorSetBindings { diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp index 18d79579..2ad41151 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp @@ -44,6 +44,8 @@ of DigiPen Institute of Technology is prohibited. #include "Graphics/MiddleEnd/TextRendering/SHFreetypeInstance.h" #include "Graphics/MiddleEnd/TextRendering/SHTextRenderingSubSystem.h" #include "Graphics/MiddleEnd/GlobalData/SHGlobalDescriptorSets.h" +#include "Events/SHEvent.h" +#include "Graphics/MiddleEnd/Lights/SHLightComponent.h" namespace SHADE { @@ -198,7 +200,8 @@ namespace SHADE /*-----------------------------------------------------------------------*/ /* MAIN NODE */ /*-----------------------------------------------------------------------*/ - auto gBufferNode = renderGraph->AddNode("G-Buffer", + auto gBufferNode = renderGraph->AddNode(SHGraphicsConstants::RenderGraphNodeNames::GBUFFER_PASS.data(), + //auto gBufferNode = renderGraph->AddNode(SHGraphicsConstants::RenderGraphNodeNames::GBUFFER_PASS.data() { "Position", "Entity ID", @@ -259,13 +262,13 @@ namespace SHADE /*-----------------------------------------------------------------------*/ // Shadow map pass will have no resources bound at first. Lighting system will add resources to the node. // It will initially also not have any subpasses since they will be added for each light that casts shadows. - auto shadowMapPass = renderGraph->AddNode("Shadow Map Pass", {}, {}); + auto shadowMapPass = renderGraph->AddNode(SHGraphicsConstants::RenderGraphNodeNames::SHADOW_MAP_PASS.data(), {}, {}); /*-----------------------------------------------------------------------*/ /* DEFERRED COMPOSITE NODE */ /*-----------------------------------------------------------------------*/ // This pass will facilitate both lighting and shadows in 1 single pass. - auto deferredCompositeNode = renderGraph->AddNode("Deferred Comp Pass", + auto deferredCompositeNode = renderGraph->AddNode(SHGraphicsConstants::RenderGraphNodeNames::DEFERRED_COMPOSITE_PASS.data(), { "Position", "Light Layer Indices", @@ -274,7 +277,7 @@ namespace SHADE "Scene", "SSAO Blur" }, - {"G-Buffer"}); + { SHGraphicsConstants::RenderGraphNodeNames::GBUFFER_PASS .data()}); /*-----------------------------------------------------------------------*/ /* DEFERRED COMPOSITE SUBPASS INIT */ @@ -286,19 +289,19 @@ namespace SHADE /*-----------------------------------------------------------------------*/ // Set up Debug Draw Passes // - Depth Tested - auto debugDrawNodeDepth = renderGraph->AddNode("Debug Draw with Depth", { "Scene", "Depth Buffer" }, {"G-Buffer", "Deferred Comp Pass"}); + auto debugDrawNodeDepth = renderGraph->AddNode(SHGraphicsConstants::RenderGraphNodeNames::DEBUG_DRAW_DEPTH_PASS.data(), {"Scene", "Depth Buffer"}, {SHGraphicsConstants::RenderGraphNodeNames::GBUFFER_PASS.data(), SHGraphicsConstants::RenderGraphNodeNames::DEFERRED_COMPOSITE_PASS.data()}); auto debugDrawDepthSubpass = debugDrawNodeDepth->AddSubpass("Debug Draw with Depth", worldViewport, worldRenderer); debugDrawDepthSubpass->AddColorOutput("Scene"); debugDrawDepthSubpass->AddDepthOutput("Depth Buffer"); // - No Depth Test - auto debugDrawNode = renderGraph->AddNode("Debug Draw", { "Scene" }, { "Debug Draw with Depth" }); + auto debugDrawNode = renderGraph->AddNode(SHGraphicsConstants::RenderGraphNodeNames::DEBUG_DRAW.data(), {"Scene"}, {SHGraphicsConstants::RenderGraphNodeNames::DEBUG_DRAW_DEPTH_PASS.data()}); auto debugDrawSubpass = debugDrawNode->AddSubpass("Debug Draw", worldViewport, worldRenderer); debugDrawSubpass->AddColorOutput("Scene"); /*-----------------------------------------------------------------------*/ /* SCREEN SPACE PASS */ /*-----------------------------------------------------------------------*/ - auto screenSpaceNode = renderGraph->AddNode("Screen Space Pass", { "Scene", "Entity ID" }, {"Deferred Comp Pass", "G-Buffer", "Debug Draw" }); + auto screenSpaceNode = renderGraph->AddNode(SHGraphicsConstants::RenderGraphNodeNames::SCREEN_SPACE_PASS.data(), {"Scene", "Entity ID"}, {SHGraphicsConstants::RenderGraphNodeNames::DEFERRED_COMPOSITE_PASS.data(), SHGraphicsConstants::RenderGraphNodeNames::GBUFFER_PASS.data(), SHGraphicsConstants::RenderGraphNodeNames::DEBUG_DRAW.data()}); auto uiSubpass = screenSpaceNode->AddSubpass("UI", worldViewport, screenRenderer); uiSubpass->AddColorOutput("Scene"); uiSubpass->AddColorOutput("Entity ID"); @@ -313,16 +316,16 @@ namespace SHADE #ifdef SHEDITOR { // Dummy Node to transition scene render graph resource - auto dummyNode = renderGraph->AddNode("Dummy Pass", { "Scene" }, { "Screen Space Pass" }); + auto dummyNode = renderGraph->AddNode("Dummy Pass", { "Scene" }, { SHGraphicsConstants::RenderGraphNodeNames::SCREEN_SPACE_PASS .data()}); auto dummySubpass = dummyNode->AddSubpass("Dummy Subpass", {}, {}); dummySubpass->AddInput("Scene"); - auto imGuiNode = renderGraph->AddNode("ImGui Node", { "Present" }, {}); + auto imGuiNode = renderGraph->AddNode(SHGraphicsConstants::RenderGraphNodeNames::IMGUI_PASS.data(), {"Present"}, {}); auto imGuiSubpass = imGuiNode->AddSubpass("ImGui Draw", {}, {}); imGuiSubpass->AddColorOutput("Present"); } #else - renderGraph->AddRenderToSwapchainNode("Scene", "Present", { "Screen Space Pass" }, { renderToSwapchainVS, renderToSwapchainFS }); + renderGraph->AddRenderToSwapchainNode("Scene", "Present", { SHGraphicsConstants::RenderGraphNodeNames::SCREEN_SPACE_PASS .data()}, {renderToSwapchainVS, renderToSwapchainFS}); #endif @@ -396,7 +399,7 @@ namespace SHADE textRenderingSubSystem = resourceManager.Create(); // initialize the text renderer - auto uiNode = renderGraph->GetNode("Screen Space Pass"); + auto uiNode = renderGraph->GetNode(SHGraphicsConstants::RenderGraphNodeNames::SCREEN_SPACE_PASS.data()); textRenderingSubSystem->Init(device, uiNode->GetRenderpass(), uiNode->GetSubpass("UI"), descPool, textVS, textFS); SHGlobalDescriptorSets::SetLightingSubSystem(lightingSubSystem); @@ -423,7 +426,7 @@ namespace SHADE defaultMaterial = AddMaterial ( defaultVertShader, defaultFragShader, - renderGraph->GetNode("G-Buffer")->GetSubpass("G-Buffer Write") + renderGraph->GetNode(SHGraphicsConstants::RenderGraphNodeNames::GBUFFER_PASS.data())->GetSubpass("G-Buffer Write") ); defaultMaterial->SetProperty("data.textureIndex", defaultTexture->TextureArrayIndex); } @@ -724,16 +727,29 @@ namespace SHADE renderers.erase(iter); } - SHEventHandle SHGraphicsSystem::ReceiveLightEnableShadowEvent(SHEventPtr event) noexcept + SHEventHandle SHGraphicsSystem::ReceiveLightEnableShadowEvent(SHEventPtr eventPtr) noexcept { + // we need to wait for the device to finish using the graph first + device->WaitIdle(); + + auto const& EVENT_DATA = reinterpret_cast*>(eventPtr.get())->data; + auto* lightComp = SHComponentManager::GetComponent(EVENT_DATA->lightEntity); + std::string resourceName = "ShadowMap " + std::to_string(EVENT_DATA->lightEntity); + // Add the shadow map resource to the graph + renderGraph->AddResource(resourceName, {SH_RENDER_GRAPH_RESOURCE_FLAGS::COLOR, SH_RENDER_GRAPH_RESOURCE_FLAGS::INPUT, SH_RENDER_GRAPH_RESOURCE_FLAGS::STORAGE}, resizeWidth, resizeHeight, vk::Format::eD24UnormS8Uint); // link resource to node. This means linking the resource and regenerating the node's renderpass and framebuffer. + auto shadowMapNode = renderGraph->GetNode(SHGraphicsConstants::RenderGraphNodeNames::SHADOW_MAP_PASS.data()); + shadowMapNode->RuntimeLinkResource(resourceName); // Add a subpass to render to that shadow map + shadowMapNode->RuntimeAddSubpass(resourceName + " Subpass", worldViewport, worldRenderer); + + // regenerate the node + //shadowMapNode->RuntimeStandaloneRegenerate(); - //renderGraph->GetNode (); - return event->handle; + return eventPtr->handle; } Handle SHGraphicsSystem::AddMaterial(Handle vertShader, Handle fragShader, Handle subpass) @@ -1076,7 +1092,7 @@ namespace SHADE Handle SHGraphicsSystem::GetPrimaryRenderpass() const noexcept { - return renderGraph->GetNode(G_BUFFER_RENDER_GRAPH_NODE_NAME.data()); + return renderGraph->GetNode(SHGraphicsConstants::RenderGraphNodeNames::GBUFFER_PASS.data()); } Handle SHGraphicsSystem::GetDebugDrawPipeline(DebugDrawPipelineType type) const noexcept diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.h b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.h index 40148e05..88d66ded 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.h +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.h @@ -177,7 +177,7 @@ namespace SHADE /*-----------------------------------------------------------------------*/ /* Light functions */ /*-----------------------------------------------------------------------*/ - SHEventHandle ReceiveLightEnableShadowEvent (SHEventPtr event) noexcept; + SHEventHandle ReceiveLightEnableShadowEvent (SHEventPtr eventPtr) noexcept; /*-----------------------------------------------------------------------------*/ /* Material Functions */ @@ -405,10 +405,6 @@ namespace SHADE SHWindow* GetWindow() noexcept { return window; } private: - /*-----------------------------------------------------------------------------*/ - /* Constants */ - /*-----------------------------------------------------------------------------*/ - static constexpr std::string_view G_BUFFER_RENDER_GRAPH_NODE_NAME = "G-Buffer"; /*-----------------------------------------------------------------------------*/ /* Data Members */ diff --git a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraph.cpp b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraph.cpp index e9a0e0bd..e6b9ae33 100644 --- a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraph.cpp +++ b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraph.cpp @@ -169,65 +169,7 @@ namespace SHADE for (uint32_t i = 0; auto& node : nodes) { - // key is handle ID, value is final layout. - std::unordered_map resourceAttFinalLayouts; - if (!node->subpasses.empty()) - { - // We first want to take all resources track their layout as undefined at the start of the node/renderpass - auto const resources = node->GetResources(); - for (auto& resource : resources) - { - resource->GetInfoTracker()->TrackLayout(node, {}, vk::ImageLayout::eUndefined); - } - - // attempt to get all final layouts for all resources - for (auto& subpass : node->subpasses) - { - for (auto& color : subpass->colorReferences) - { - // If final renderpass and attachment is a COLOR_PRESENT resource, make resource transition to present after last subpass - if (i == nodes.size() - 1 && (node->attResources[color.attachment]->resourceTypeFlags & static_cast(SH_RENDER_GRAPH_RESOURCE_FLAGS::COLOR_PRESENT))) - resourceAttFinalLayouts[color.attachment] = vk::ImageLayout::ePresentSrcKHR; - else - resourceAttFinalLayouts[color.attachment] = color.layout; - - node->attResources[color.attachment]->infoTracker->TrackLayout(node, subpass, color.layout); - } - - for (auto& depth : subpass->depthReferences) - { - resourceAttFinalLayouts[depth.attachment] = depth.layout; - node->attResources[depth.attachment]->infoTracker->TrackLayout(node, subpass, depth.layout); - } - - for (auto& input : subpass->inputReferences) - { - resourceAttFinalLayouts[input.attachment] = input.layout; - node->attResources[input.attachment]->infoTracker->TrackLayout(node, subpass, input.layout); - } - } - - for (uint32_t j = 0; j < node->attachmentDescriptions.size(); ++j) - { - auto& att = node->attachmentDescriptions[j]; - auto& resource = node->attResources[j]; - - // If resource is from another render graph, use the final layout it had when it was last used in that graph. This is initialized in LinkNonOwningResource. - // We also want to load the attachment, not "don't care". - if (resource->resourceTypeFlags & SHUtilities::ConvertEnum(SH_RENDER_GRAPH_RESOURCE_FLAGS::SHARED) && - renderGraphStorage->nonOwningResourceInitialLayouts.contains(resource.GetId().Raw)) - { - att.initialLayout = renderGraphStorage->nonOwningResourceInitialLayouts.at(resource.GetId().Raw); - att.loadOp = vk::AttachmentLoadOp::eLoad; - att.stencilLoadOp = vk::AttachmentLoadOp::eLoad; - } - else - att.initialLayout = vk::ImageLayout::eUndefined; - - att.finalLayout = resourceAttFinalLayouts[j]; - resource->GetInfoTracker()->TrackLayout(node, {}, att.finalLayout); - } - } + node->StandaloneConfigureAttDesc(i == nodes.size() - 1); ++i; } diff --git a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraph.h b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraph.h index 7dc19a80..6dbc4308 100644 --- a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraph.h +++ b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraph.h @@ -164,7 +164,14 @@ namespace SHADE * that manage the resources instead and can facilitate such linking of resources. Either that, or we allow only 1 render graph, * but different matrices (SHRenderer) can be used in different nodes. * - There are also way too many hash maps created for ease of access. This definitely can be cut down. - * - + * - In hindsight there should have been a distinction between static and dynamic nodes. Static nodes are the ones that are accounted + * for in the generation of the render graph. Dynamic nodes begin with nothing at first, but allows for linking of resources and subpasses + * while the render graph is executing. The resources here should also be dynamic, which means it should never be used in anywhere else other + * than in the node that is using it. This would mean its initial layouts are always specified as undefined and final layouts specified as + * whatever the last subpass that is using that resource specifies in the node. Dynamic nodes are meant to render to resources that would later + * be used externally, as descriptors for example (the descriptors can be used in a render graph node compute for example). Dynamic nodes run as + * if they are the only nodes in the graph, because their resources are not used in other nodes and are thus not predecessors or successors of any + * other node. * */ diff --git a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNode.cpp b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNode.cpp index 56d8734a..cc9d61a9 100644 --- a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNode.cpp +++ b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNode.cpp @@ -495,6 +495,68 @@ namespace SHADE } } + void SHRenderGraphNode::StandaloneConfigureAttDesc(bool isLastNode) noexcept + { + // key is handle ID, value is final layout. + std::unordered_map resourceAttFinalLayouts; + if (!subpasses.empty()) + { + // We first want to take all resources track their layout as undefined at the start of the node/renderpass + for (auto& resource : attResources) + { + resource->GetInfoTracker()->TrackLayout(GetHandle(), {}, vk::ImageLayout::eUndefined); + } + + // attempt to get all final layouts for all resources + for (auto& subpass : subpasses) + { + for (auto& color : subpass->colorReferences) + { + // If final renderpass and attachment is a COLOR_PRESENT resource, make resource transition to present after last subpass + if (isLastNode && (attResources[color.attachment]->resourceTypeFlags & static_cast(SH_RENDER_GRAPH_RESOURCE_FLAGS::COLOR_PRESENT))) + resourceAttFinalLayouts[color.attachment] = vk::ImageLayout::ePresentSrcKHR; + else + resourceAttFinalLayouts[color.attachment] = color.layout; + + attResources[color.attachment]->infoTracker->TrackLayout(GetHandle(), subpass, color.layout); + } + + for (auto& depth : subpass->depthReferences) + { + resourceAttFinalLayouts[depth.attachment] = depth.layout; + attResources[depth.attachment]->infoTracker->TrackLayout(GetHandle(), subpass, depth.layout); + } + + for (auto& input : subpass->inputReferences) + { + resourceAttFinalLayouts[input.attachment] = input.layout; + attResources[input.attachment]->infoTracker->TrackLayout(GetHandle(), subpass, input.layout); + } + } + + for (uint32_t j = 0; j < attachmentDescriptions.size(); ++j) + { + auto& att = attachmentDescriptions[j]; + auto& resource = attResources[j]; + + // If resource is from another render graph, use the final layout it had when it was last used in that graph. This is initialized in LinkNonOwningResource. + // We also want to load the attachment, not "don't care". + if (resource->resourceTypeFlags & SHUtilities::ConvertEnum(SH_RENDER_GRAPH_RESOURCE_FLAGS::SHARED) && + graphStorage->nonOwningResourceInitialLayouts.contains(resource.GetId().Raw)) + { + att.initialLayout = graphStorage->nonOwningResourceInitialLayouts.at(resource.GetId().Raw); + att.loadOp = vk::AttachmentLoadOp::eLoad; + att.stencilLoadOp = vk::AttachmentLoadOp::eLoad; + } + else + att.initialLayout = vk::ImageLayout::eUndefined; + + att.finalLayout = resourceAttFinalLayouts[j]; + resource->GetInfoTracker()->TrackLayout(GetHandle(), {}, att.finalLayout); + } + } + } + /***************************************************************************/ /*! @@ -521,6 +583,9 @@ namespace SHADE // remove attachment reference attachmentDescriptions.erase (attachmentDescriptions.begin() + index); + // erase from mapping as well + resourceAttachmentMapping->erase(resourceHandleID); + // Remove footprint of attachment from all subpasses as well for (auto it = subpasses.begin(); it != subpasses.end(); ++it) { @@ -629,6 +694,77 @@ namespace SHADE batcher.FinaliseBatches(graphStorage->logicalDevice, descPool, frameIndex); } + /***************************************************************************/ + /*! + + \brief + This function simply appends to the container of VkAttachmentDescription + and attResources. It will assume the resource is used standalone in the + node and will not account for its usage in other nodes. As such its + initialLayout will always be UNDEFINED and its finalLayout will be + whatever is calculated if the node is regenerated using + StandaloneRegnerate. This function also does not affect the render graph + while its running since the 2 containers above have already been copied + to the GPU. + + \param resourceName + The name of the resource for getting the resource. + + */ + /***************************************************************************/ + void SHRenderGraphNode::RuntimeLinkResource(std::string resourceName) noexcept + { + // Get new resource + Handle newResource = graphStorage->graphResources->at(resourceName); + + // append new resource to container + attResources.push_back(newResource); + + attachmentDescriptions.push_back(vk::AttachmentDescription + { + .format = newResource->GetResourceFormat(), + .samples = vk::SampleCountFlagBits::e1, + .loadOp = vk::AttachmentLoadOp::eClear, + .storeOp = vk::AttachmentStoreOp::eStore, + .stencilLoadOp = vk::AttachmentLoadOp::eClear, + .stencilStoreOp = vk::AttachmentStoreOp::eStore, + }); + + resourceAttachmentMapping->try_emplace(newResource.GetId().Raw, attachmentDescriptions.size() - 1); + } + + void SHRenderGraphNode::RuntimeAddSubpass(std::string subpassName, Handle viewport, Handle renderer) noexcept + { + AddSubpass(std::move (subpassName), viewport, renderer); + } + + /***************************************************************************/ + /*! + + \brief + USE WITH CAUTION because the function does not reevaluate resource + layouts in attachment descriptions. All resources here will start at + UNDEFINED and end at whatever the last subpass using the attachment + specifies. It will also not support render graph node computes given its + complexity if it has to be accounted for. + + IN SHORT, IT GENERATES A RENDERPASS AS IF ITS THE ONLY NODE + IN THE RENDER GRAPH. SEE NOTES IN SHRenderGraph.h + + This function is mainly meant for nodes that are dynamic (in hindsight, + there really should have been a distinction between static and dynamic + nodes). + + */ + /***************************************************************************/ + void SHRenderGraphNode::RuntimeStandaloneRegenerate(void) noexcept + { + StandaloneConfigureAttDesc(false); + ConfigureSubpasses(); + CreateRenderpass(); + CreateFramebuffer(); + } + /***************************************************************************/ /*! diff --git a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNode.h b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNode.h index a581d21c..d8e4caa4 100644 --- a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNode.h +++ b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNode.h @@ -93,6 +93,9 @@ namespace SHADE void CreateFramebuffer(void) noexcept; void HandleResize (void) noexcept; void ConfigureSubpasses (void) noexcept; + bool DetachResource(std::string const& resourceName, uint64_t resourceHandleID) noexcept; + void AddDummySubpassIfNeeded(void) noexcept; + void StandaloneConfigureAttDesc (bool isLastNode) noexcept; public: /*-----------------------------------------------------------------------*/ @@ -105,15 +108,17 @@ namespace SHADE /*-----------------------------------------------------------------------*/ /* PUBLIC MEMBER FUNCTIONS */ /*-----------------------------------------------------------------------*/ - Handle AddSubpass(std::string subpassName, Handle viewport, Handle renderer) noexcept; + Handle AddSubpass(std::string subpassName, Handle viewport, Handle renderer) noexcept; Handle AddNodeCompute(std::string nodeName, Handle computeShaderModule, std::initializer_list resources, std::unordered_set&& dynamicBufferBindings = {}, float numWorkGroupScale = 1.0f) noexcept; - void AddDummySubpassIfNeeded (void) noexcept; - bool DetachResource (std::string const& resourceName, uint64_t resourceHandleID) noexcept; + + void Execute(Handle commandBuffer, Handle descPool, uint32_t frameIndex) noexcept; + Handle GetOrCreatePipeline(std::pair, Handle> const& vsFsPair, Handle subpass) noexcept; + void FinaliseBatch(uint32_t frameIndex, Handle descPool); - // TODO: RemoveSubpass() - void Execute(Handle commandBuffer, Handle descPool, uint32_t frameIndex) noexcept; - Handle GetOrCreatePipeline(std::pair, Handle> const& vsFsPair, Handle subpass) noexcept; - void FinaliseBatch(uint32_t frameIndex, Handle descPool); + // Runtime functions that don't affect the renderpass + void RuntimeLinkResource(std::string resourceName) noexcept; + void RuntimeAddSubpass(std::string subpassName, Handle viewport, Handle renderer) noexcept; + void RuntimeStandaloneRegenerate (void) noexcept; /*-----------------------------------------------------------------------*/ /* SETTERS AND GETTERS */ From ef8867a7a55f9773e34f76362888f92ae9803efd Mon Sep 17 00:00:00 2001 From: Brandon Mak Date: Mon, 2 Jan 2023 22:16:35 +0800 Subject: [PATCH 03/45] Shadows WIP --- .../Descriptors/SHVkDescriptorSetGroup.cpp | 15 ++++ .../Descriptors/SHVkDescriptorSetGroup.h | 1 + .../GlobalData/SHGraphicsPredefinedData.cpp | 14 ++++ .../GlobalData/SHGraphicsPredefinedData.h | 1 + .../MiddleEnd/Interface/SHGraphicsConstants.h | 9 +++ .../MiddleEnd/Interface/SHGraphicsSystem.cpp | 6 +- .../MiddleEnd/Lights/SHLightingSubSystem.cpp | 55 +++++++++++++- .../MiddleEnd/Lights/SHLightingSubSystem.h | 76 +++++++++++++------ 8 files changed, 153 insertions(+), 24 deletions(-) diff --git a/SHADE_Engine/src/Graphics/Descriptors/SHVkDescriptorSetGroup.cpp b/SHADE_Engine/src/Graphics/Descriptors/SHVkDescriptorSetGroup.cpp index e77234ca..7c5c0e48 100644 --- a/SHADE_Engine/src/Graphics/Descriptors/SHVkDescriptorSetGroup.cpp +++ b/SHADE_Engine/src/Graphics/Descriptors/SHVkDescriptorSetGroup.cpp @@ -177,6 +177,21 @@ namespace SHADE } } + void SHVkDescriptorSetGroup::ModifyWriteDescImage(uint32_t set, uint32_t binding, std::tuple, Handle, vk::ImageLayout> const& imageViewAndSampler, uint32_t descIndex) noexcept + { + // Find the target writeDescSet + BindingAndSetHash writeHash = binding; + writeHash |= static_cast(set) << 32; + auto& writeInfo = updater.writeInfos[updater.writeHashMap.at(writeHash)]; + + // write sampler and image view + auto& [view, sampler, layout] = imageViewAndSampler; + writeInfo.descImageInfos[descIndex].imageView = view->GetImageView(); + writeInfo.descImageInfos[descIndex].sampler = sampler ? sampler->GetVkSampler() : nullptr; + writeInfo.descImageInfos[descIndex].imageLayout = layout; + + } + void SHVkDescriptorSetGroup::ModifyWriteDescBuffer(uint32_t set, uint32_t binding, std::span> const& buffers, uint32_t offset, uint32_t range) noexcept { // Find the target writeDescSet diff --git a/SHADE_Engine/src/Graphics/Descriptors/SHVkDescriptorSetGroup.h b/SHADE_Engine/src/Graphics/Descriptors/SHVkDescriptorSetGroup.h index a228bc66..4538b271 100644 --- a/SHADE_Engine/src/Graphics/Descriptors/SHVkDescriptorSetGroup.h +++ b/SHADE_Engine/src/Graphics/Descriptors/SHVkDescriptorSetGroup.h @@ -67,6 +67,7 @@ namespace SHADE void UpdateDescriptorSetBuffer(uint32_t set, uint32_t binding) noexcept; void ModifyWriteDescImage(uint32_t set, uint32_t binding, std::span, Handle, vk::ImageLayout>> const& imageViewsAndSamplers) noexcept; + void ModifyWriteDescImage(uint32_t set, uint32_t binding, std::tuple, Handle, vk::ImageLayout> const& imageViewAndSampler, uint32_t descIndex) noexcept; void ModifyWriteDescBuffer (uint32_t set, uint32_t binding, std::span> const& buffers, uint32_t offset, uint32_t range) noexcept; diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/GlobalData/SHGraphicsPredefinedData.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/GlobalData/SHGraphicsPredefinedData.cpp index ffe29b36..d09ec5b4 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/GlobalData/SHGraphicsPredefinedData.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/GlobalData/SHGraphicsPredefinedData.cpp @@ -150,12 +150,26 @@ namespace SHADE Handle fontDataDescSetLayout = logicalDevice->CreateDescriptorSetLayout({ fontBitmapBinding, fontMatrixBinding }); SET_VK_OBJ_NAME(logicalDevice, vk::ObjectType::eDescriptorSetLayout, fontDataDescSetLayout->GetVkHandle(), "[Descriptor Set Layout] Font Data"); + // descriptor binding for storing shadow maps + SHVkDescriptorSetLayout::Binding shadowMapBinding + { + .Type = vk::DescriptorType::eCombinedImageSampler, + .Stage = vk::ShaderStageFlagBits::eVertex | vk::ShaderStageFlagBits::eFragment | vk::ShaderStageFlagBits::eCompute, + .BindPoint = SHGraphicsConstants::DescriptorSetBindings::IMAGE_AND_SAMPLERS_DATA, + .DescriptorCount = 200, // we can have up to 2000 textures for now + .flags = vk::DescriptorBindingFlagBits::eVariableDescriptorCount, + }; + + // For global data (generic data and textures) + Handle shadowMapDescLayout = logicalDevice->CreateDescriptorSetLayout({ shadowMapBinding }); + SET_VK_OBJ_NAME(logicalDevice, vk::ObjectType::eDescriptorSetLayout, shadowMapDescLayout->GetVkHandle(), "[Descriptor Set Layout] Shadow Maps"); predefinedLayouts.push_back(staticGlobalLayout); predefinedLayouts.push_back(lightDataDescSetLayout); predefinedLayouts.push_back(cameraDataGlobalLayout); predefinedLayouts.push_back(materialDataPerInstanceLayout); predefinedLayouts.push_back(fontDataDescSetLayout); + predefinedLayouts.push_back(shadowMapDescLayout); perSystemData[SHUtilities::ConvertEnum(SystemType::BATCHING)].descSetLayouts = GetPredefinedDescSetLayouts ( diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/GlobalData/SHGraphicsPredefinedData.h b/SHADE_Engine/src/Graphics/MiddleEnd/GlobalData/SHGraphicsPredefinedData.h index 11bfc469..b4004d5a 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/GlobalData/SHGraphicsPredefinedData.h +++ b/SHADE_Engine/src/Graphics/MiddleEnd/GlobalData/SHGraphicsPredefinedData.h @@ -28,6 +28,7 @@ namespace SHADE CAMERA = 0x04, MATERIALS = 0x08, FONT = 0x10, + SHADOW = 0x20, }; enum class SystemType diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsConstants.h b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsConstants.h index f331ce02..b061dde3 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsConstants.h +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsConstants.h @@ -169,6 +169,15 @@ namespace SHADE /***************************************************************************/ static constexpr uint32_t FONT_MATRIX_DATA = 1; + /***************************************************************************/ + /*! + \brief + Descriptor set binding for shadow map images. + + */ + /***************************************************************************/ + static constexpr uint32_t SHADOW_MAP_IMAGE_SAMPLER_DATA = 0; + }; struct VertexBufferBindings diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp index 2ad41151..6647ea74 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp @@ -394,7 +394,11 @@ namespace SHADE postOffscreenRenderSubSystem->Init(device, renderGraph->GetRenderGraphResource("Scene"), descPool); lightingSubSystem = resourceManager.Create(); - lightingSubSystem->Init(device, descPool); + lightingSubSystem->Init(device, descPool, samplerCache.GetSampler (device, SHVkSamplerParams + { + // nothing for now + }) + ); textRenderingSubSystem = resourceManager.Create(); diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightingSubSystem.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightingSubSystem.cpp index ddacf3a7..7a4a3203 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightingSubSystem.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightingSubSystem.cpp @@ -10,6 +10,9 @@ #include "SHLightComponent.h" #include "Math/Vector/SHVec4.h" #include "Math/SHMatrix.h" +#include "Graphics/Images/SHVkImageView.h" +#include "Graphics/MiddleEnd/Textures/SHVkSamplerCache.h" +#include "Graphics/Images/SHVkSampler.h" namespace SHADE { @@ -365,6 +368,11 @@ namespace SHADE } } + void SHLightingSubSystem::UpdateShadowMapDesc(void) noexcept + { + + } + /***************************************************************************/ /*! @@ -375,13 +383,14 @@ namespace SHADE */ /***************************************************************************/ - void SHLightingSubSystem::Init(Handle device, Handle descPool) noexcept + void SHLightingSubSystem::Init(Handle device, Handle descPool, Handle inShadowMapSampler) noexcept { SHComponentManager::CreateComponentSparseSet(); logicalDevice = device; uint32_t constexpr NUM_LIGHT_TYPES = SHUtilities::ConvertEnum(SH_LIGHT_TYPE::NUM_TYPES); +#pragma region LIGHTING std::vector variableSizes{ NUM_LIGHT_TYPES }; std::fill (variableSizes.begin(), variableSizes.end(), 1); @@ -418,7 +427,21 @@ namespace SHADE dynamicOffsets[i].resize(NUM_LIGHT_TYPES + 1); // +1 for the count } +#pragma endregion + +#pragma region SHADOWS + std::vector shadowDescVariableSizes{ MAX_SHADOWS }; + shadowMapDescriptorSet = descPool->Allocate({SHGraphicsPredefinedData::GetPredefinedDescSetLayouts(SHGraphicsPredefinedData::PredefinedDescSetLayoutTypes::SHADOW)}, shadowDescVariableSizes); + +#ifdef _DEBUG + const auto& SHADOW_MAP_DESC_SETS = shadowMapDescriptorSet->GetVkHandle(); + for (int i = 0; i < static_cast(SHADOW_MAP_DESC_SETS.size()); ++i) + SET_VK_OBJ_NAME(logicalDevice, vk::ObjectType::eDescriptorSet, SHADOW_MAP_DESC_SETS[i], "[Descriptor Set] Shadow Map Data Frame #" + std::to_string(i)); +#endif + + shadowMapSampler = inShadowMapSampler; //numLightComponents = 0; +#pragma endregion } /***************************************************************************/ @@ -526,6 +549,36 @@ namespace SHADE } + void SHLightingSubSystem::AddShadowMap(Handle newShadowMap) noexcept + { + // Add to container of shadow maps + shadowMaps.emplace_back(newShadowMap); + + // Just use the image view stored in the resource + Handle const NEW_IMAGE_VIEW = newShadowMap->GetImageView(); + + // Prepare to write to descriptor + shadowMapImageSamplers.emplace_back(NEW_IMAGE_VIEW, shadowMapSampler, vk::ImageLayout::eShaderReadOnlyOptimal); + + static constexpr uint32_t SHADOW_MAP_DESC_SET_INDEX = 0; + uint32_t const SHADOW_MAP_DESC_ARRAY_INDEX = shadowMapImageSamplers.size() - 1; + shadowMapDescriptorSet->ModifyWriteDescImage + ( + SHADOW_MAP_DESC_SET_INDEX, + SHGraphicsConstants::DescriptorSetBindings::SHADOW_MAP_IMAGE_SAMPLER_DATA, + shadowMapImageSamplers[SHADOW_MAP_DESC_ARRAY_INDEX], + SHADOW_MAP_DESC_ARRAY_INDEX + ); + + // TODO: Definitely can be optimized by writing a function that modifies a specific descriptor in the array + shadowMapDescriptorSet->UpdateDescriptorSetImages + ( + SHADOW_MAP_DESC_SET_INDEX, + SHGraphicsConstants::DescriptorSetBindings::SHADOW_MAP_IMAGE_SAMPLER_DATA + ); + + } + Handle SHLightingSubSystem::GetLightDataDescriptorSet(void) const noexcept { return lightingDataDescSet; diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightingSubSystem.h b/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightingSubSystem.h index fa103136..ec42193a 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightingSubSystem.h +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightingSubSystem.h @@ -6,6 +6,7 @@ #include "SHLightData.h" #include #include "Graphics/MiddleEnd/Interface/SHGraphicsConstants.h" +#include "Graphics/RenderGraph/SHRenderGraphResource.h" namespace SHADE { @@ -16,6 +17,9 @@ namespace SHADE class SHVkBuffer; class SHLightComponent; class SHVkCommandBuffer; + class SHSamplerCache; + class SHVkImageView; + class SHVkSampler; // Represents how the data will be interpreted in GPU. we want to copy to a container of these before passing to GPU. struct SHDirectionalLightData @@ -69,7 +73,7 @@ namespace SHADE /*-----------------------------------------------------------------------*/ /* STATIC MEMBER VARIABLES */ /*-----------------------------------------------------------------------*/ - static constexpr uint32_t STARTING_NUM_LIGHTS = 50; + static constexpr uint32_t STARTING_NUM_LIGHTS = 50; /*-----------------------------------------------------------------------*/ /* PRIVATE MEMBER VARIABLES */ @@ -123,50 +127,78 @@ namespace SHADE }; private: + /*-----------------------------------------------------------------------*/ + /* STATIC MEMBER VARIABLES */ + /*-----------------------------------------------------------------------*/ + + static constexpr uint32_t MAX_SHADOWS = 200; //! logical device used for creation - Handle logicalDevice; + Handle logicalDevice; //! The descriptor set that will hold the lighting data. Each binding will hold a buffer, NUM_FRAMES times the size required. - Handle lightingDataDescSet; - - //! Each type will have some data associated with it for processing - std::array(SH_LIGHT_TYPE::NUM_TYPES)> perTypeData; - - //! Container to store dynamic offsets for binding descriptor sets - DynamicOffsetArray dynamicOffsets; - - //! holds the data that represents how many lights are in the scene - std::array(SH_LIGHT_TYPE::NUM_TYPES)> lightCountsData; - - //! GPU buffer to hold lightCountData - Handle lightCountsBuffer; - - //! For padding in the buffer - uint32_t lightCountsAlignedSize; + Handle lightingDataDescSet; + + //! Each type will have some data associated with it for processing + std::array(SH_LIGHT_TYPE::NUM_TYPES)> perTypeData; + + //! Container to store dynamic offsets for binding descriptor sets + DynamicOffsetArray dynamicOffsets; + + //! holds the data that represents how many lights are in the scene + std::array(SH_LIGHT_TYPE::NUM_TYPES)> lightCountsData; + + //! GPU buffer to hold lightCountData + Handle lightCountsBuffer; + + //! For padding in the buffer + uint32_t lightCountsAlignedSize; //! Number of SHLightComponents recorded. If at the beginning of the run function the size returned by the dense //! set is less than the size recorded, rewrite all light components into the its respective buffers. If its more, //! don't do anything. //uint32_t numLightComponents; + //! Handle to sampler that all shadow map descriptors will use + Handle shadowMapSampler; + + //! Shadow maps for every light that casts a shadow + std::vector> shadowMaps; + + //! Descriptor sets required to be given to the compute shader for shadow calculation. This will be a descriptor array. + //! It will also be preallocated. + Handle shadowMapDescriptorSet; + + //! Combined image samplers for the texture descriptors + std::vector, Handle, vk::ImageLayout>> shadowMapImageSamplers; + + //! Barriers required to transition the resources from whatever layout they are in (probably from VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL) + //! to VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL) + std::vector shadowMapMemoryBarriers; + /*-----------------------------------------------------------------------*/ /* PRIVATE MEMBER FUNCTIONS */ /*-----------------------------------------------------------------------*/ void UpdateDescSet (uint32_t binding) noexcept; void ComputeDynamicOffsets (void) noexcept; void ResetNumLights (void) noexcept; + void UpdateShadowMapDesc (void) noexcept; public: /*-----------------------------------------------------------------------*/ /* PUBLIC MEMBER FUNCTIONS */ /*-----------------------------------------------------------------------*/ - void Init (Handle device, Handle descPool) noexcept; - void Run (SHMatrix const& viewMat, uint32_t frameIndex) noexcept; - void Exit (void) noexcept; + void Init (Handle device, Handle descPool, Handle inShadowMapSampler) noexcept; + void Run (SHMatrix const& viewMat, uint32_t frameIndex) noexcept; + void Exit (void) noexcept; + void BindDescSet (Handle cmdBuffer, uint32_t setIndex, uint32_t frameIndex) noexcept; + void AddShadowMap (Handle newShadowMap) noexcept; + //void RemoveShadowMap (uint32_t index) noexcept; - void BindDescSet (Handle cmdBuffer, uint32_t setIndex, uint32_t frameIndex) noexcept; + /*-----------------------------------------------------------------------*/ + /* SETTERS AND GETTERS */ + /*-----------------------------------------------------------------------*/ Handle GetLightDataDescriptorSet (void) const noexcept; }; From b771cdbfc6a0f0a96fba73a1e69d85c18d69af48 Mon Sep 17 00:00:00 2001 From: Brandon Mak Date: Tue, 3 Jan 2023 07:41:37 +0800 Subject: [PATCH 04/45] Added barrier for shadow maps --- .../MiddleEnd/Lights/SHLightingSubSystem.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightingSubSystem.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightingSubSystem.cpp index 7a4a3203..87b2ab62 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightingSubSystem.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightingSubSystem.cpp @@ -560,6 +560,7 @@ namespace SHADE // Prepare to write to descriptor shadowMapImageSamplers.emplace_back(NEW_IMAGE_VIEW, shadowMapSampler, vk::ImageLayout::eShaderReadOnlyOptimal); + // Update descriptor set static constexpr uint32_t SHADOW_MAP_DESC_SET_INDEX = 0; uint32_t const SHADOW_MAP_DESC_ARRAY_INDEX = shadowMapImageSamplers.size() - 1; shadowMapDescriptorSet->ModifyWriteDescImage @@ -577,6 +578,23 @@ namespace SHADE SHGraphicsConstants::DescriptorSetBindings::SHADOW_MAP_IMAGE_SAMPLER_DATA ); + // add to barriers + shadowMapMemoryBarriers.push_back (vk::ImageMemoryBarrier + { + .oldLayout = vk::ImageLayout::eDepthAttachmentOptimal, + .newLayout = vk::ImageLayout::eShaderReadOnlyOptimal, + .srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED, + .dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED, + .image = newShadowMap->GetImage()->GetVkImage(), + .subresourceRange = vk::ImageSubresourceRange + { + .aspectMask = vk::ImageAspectFlagBits::eDepth, + .baseMipLevel = 0, + .levelCount = 1, + .baseArrayLayer = 0, + .layerCount = 1, + } + }); } Handle SHLightingSubSystem::GetLightDataDescriptorSet(void) const noexcept From 87b2103f6eb48b02ff95c449b28c52599e33cdf6 Mon Sep 17 00:00:00 2001 From: Brandon Mak Date: Tue, 3 Jan 2023 22:05:36 +0800 Subject: [PATCH 05/45] Shadows WIP --- .../MiddleEnd/Interface/SHGraphicsSystem.cpp | 7 +++++++ .../MiddleEnd/Lights/SHLightingSubSystem.cpp | 11 ++++++++--- .../MiddleEnd/Lights/SHLightingSubSystem.h | 17 ++++++++++------- .../RenderGraph/SHRenderGraphNode.cpp | 4 ++-- .../Graphics/RenderGraph/SHRenderGraphNode.h | 2 +- .../RenderGraph/SHRenderGraphNodeCompute.cpp | 19 ++++++++++++++++--- .../RenderGraph/SHRenderGraphNodeCompute.h | 2 +- 7 files changed, 45 insertions(+), 17 deletions(-) diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp index 6647ea74..98c897f3 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp @@ -279,6 +279,13 @@ namespace SHADE }, { SHGraphicsConstants::RenderGraphNodeNames::GBUFFER_PASS .data()}); + // Add subpass with exterior draw call to transition shadow maps + //auto shadowMapTransitionSubpass = deferredCompositeNode->AddSubpass("Shadow Map Transition", {}, {}); + //shadowMapTransitionSubpass->AddExteriorDrawCalls([=](Handle cmdBuffer, Handle renderer, uint32_t frameIndex) + // { + // lightingSubSystem->PrepareShadowMapsForRead(cmdBuffer); + // }); + /*-----------------------------------------------------------------------*/ /* DEFERRED COMPOSITE SUBPASS INIT */ /*-----------------------------------------------------------------------*/ diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightingSubSystem.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightingSubSystem.cpp index 87b2ab62..997fe68a 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightingSubSystem.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightingSubSystem.cpp @@ -526,7 +526,6 @@ namespace SHADE // so we do it anyway. #NoteToSelf: if at any point it affects performance, do a check before computing. ComputeDynamicOffsets(); - } /***************************************************************************/ @@ -549,10 +548,10 @@ namespace SHADE } - void SHLightingSubSystem::AddShadowMap(Handle newShadowMap) noexcept + void SHLightingSubSystem::AddShadowMap(Handle newShadowMap, EntityID lightEntity) noexcept { // Add to container of shadow maps - shadowMaps.emplace_back(newShadowMap); + shadowMaps.emplace(lightEntity, newShadowMap); // Just use the image view stored in the resource Handle const NEW_IMAGE_VIEW = newShadowMap->GetImageView(); @@ -597,6 +596,12 @@ namespace SHADE }); } + void SHLightingSubSystem::PrepareShadowMapsForRead(Handle cmdBuffer) noexcept + { + // Issue barrier to transition shadow maps for reading in compute shader + cmdBuffer->PipelineBarrier(vk::PipelineStageFlagBits::eEarlyFragmentTests | vk::PipelineStageFlagBits::eLateFragmentTests, vk::PipelineStageFlagBits::eComputeShader, {}, {}, {}, shadowMapMemoryBarriers); + } + Handle SHLightingSubSystem::GetLightDataDescriptorSet(void) const noexcept { return lightingDataDescSet; diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightingSubSystem.h b/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightingSubSystem.h index ec42193a..65b58174 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightingSubSystem.h +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightingSubSystem.h @@ -7,6 +7,7 @@ #include #include "Graphics/MiddleEnd/Interface/SHGraphicsConstants.h" #include "Graphics/RenderGraph/SHRenderGraphResource.h" +#include "ECS_Base/SHECSMacros.h" namespace SHADE { @@ -162,8 +163,9 @@ namespace SHADE //! Handle to sampler that all shadow map descriptors will use Handle shadowMapSampler; - //! Shadow maps for every light that casts a shadow - std::vector> shadowMaps; + //std::vector> shadowMaps; + //! Shadow maps for every light that casts a shadow Order here doesn't matter. We just want to store it + std::unordered_map> shadowMaps; //! Descriptor sets required to be given to the compute shader for shadow calculation. This will be a descriptor array. //! It will also be preallocated. @@ -189,11 +191,12 @@ namespace SHADE /*-----------------------------------------------------------------------*/ /* PUBLIC MEMBER FUNCTIONS */ /*-----------------------------------------------------------------------*/ - void Init (Handle device, Handle descPool, Handle inShadowMapSampler) noexcept; - void Run (SHMatrix const& viewMat, uint32_t frameIndex) noexcept; - void Exit (void) noexcept; - void BindDescSet (Handle cmdBuffer, uint32_t setIndex, uint32_t frameIndex) noexcept; - void AddShadowMap (Handle newShadowMap) noexcept; + void Init (Handle device, Handle descPool, Handle inShadowMapSampler) noexcept; + void Run (SHMatrix const& viewMat, uint32_t frameIndex) noexcept; + void Exit (void) noexcept; + void BindDescSet (Handle cmdBuffer, uint32_t setIndex, uint32_t frameIndex) noexcept; + void AddShadowMap (Handle newShadowMap, EntityID lightEntity) noexcept; + void PrepareShadowMapsForRead (Handle cmdBuffer) noexcept; //void RemoveShadowMap (uint32_t index) noexcept; /*-----------------------------------------------------------------------*/ diff --git a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNode.cpp b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNode.cpp index cc9d61a9..122f41da 100644 --- a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNode.cpp +++ b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNode.cpp @@ -431,7 +431,7 @@ namespace SHADE return subpass; } - Handle SHRenderGraphNode::AddNodeCompute(std::string nodeName, Handle computeShaderModule, std::initializer_list resources, std::unordered_set&& dynamicBufferBindings, float numWorkGroupScale/* = 1.0f*/) noexcept + Handle SHRenderGraphNode::AddNodeCompute(std::string nodeName, Handle computeShaderModule, std::initializer_list resources, std::unordered_set&& dynamicBufferBindings, Handle customComputeLayout/* = {}*/, float numWorkGroupScale/* = 1.0f*/) noexcept { // Look for the required resources in the graph std::vector> nodeComputeResources{}; @@ -447,7 +447,7 @@ namespace SHADE std::vector> temp (nodeComputeResources); // Create the subpass compute with the resources - auto nodeCompute = graphStorage->resourceHub->Create(std::move(nodeName), graphStorage, computeShaderModule, std::move(nodeComputeResources), std::move (dynamicBufferBindings), nodeComputes.empty()); + auto nodeCompute = graphStorage->resourceHub->Create(std::move(nodeName), graphStorage, computeShaderModule, std::move(nodeComputeResources), std::move (dynamicBufferBindings), nodeComputes.empty(), customComputeLayout); nodeComputes.push_back(nodeCompute); for (auto& resource : temp) diff --git a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNode.h b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNode.h index d8e4caa4..8744184f 100644 --- a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNode.h +++ b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNode.h @@ -109,7 +109,7 @@ namespace SHADE /* PUBLIC MEMBER FUNCTIONS */ /*-----------------------------------------------------------------------*/ Handle AddSubpass(std::string subpassName, Handle viewport, Handle renderer) noexcept; - Handle AddNodeCompute(std::string nodeName, Handle computeShaderModule, std::initializer_list resources, std::unordered_set&& dynamicBufferBindings = {}, float numWorkGroupScale = 1.0f) noexcept; + Handle AddNodeCompute(std::string nodeName, Handle computeShaderModule, std::initializer_list resources, std::unordered_set&& dynamicBufferBindings = {}, Handle customComputeLayout = {}, float numWorkGroupScale = 1.0f) noexcept; void Execute(Handle commandBuffer, Handle descPool, uint32_t frameIndex) noexcept; Handle GetOrCreatePipeline(std::pair, Handle> const& vsFsPair, Handle subpass) noexcept; diff --git a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNodeCompute.cpp b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNodeCompute.cpp index e1bc3842..fd46cfe7 100644 --- a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNodeCompute.cpp +++ b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNodeCompute.cpp @@ -62,7 +62,8 @@ namespace SHADE followingEndRenderpass = flag; } - SHRenderGraphNodeCompute::SHRenderGraphNodeCompute(std::string nodeName, Handle graphStorage, Handle computeShaderModule, std::vector>&& subpassComputeResources, std::unordered_set&& dynamicBufferBindings, bool followingEndRP, float inNumWorkGroupScale/* = 1.0f*/) noexcept + + SHRenderGraphNodeCompute::SHRenderGraphNodeCompute(std::string nodeName, Handle graphStorage, Handle computeShaderModule, std::vector>&& subpassComputeResources, std::unordered_set&& dynamicBufferBindings, bool followingEndRP, Handle customComputeLayout, float inNumWorkGroupScale/* = 1.0f*/) noexcept : computePipeline{} , pipelineLayout{} , resources{} @@ -116,10 +117,22 @@ namespace SHADE // check if all layouts are there if (layouts.size() == descMappings.at(SHPredefinedDescriptorTypes::RENDER_GRAPH_NODE_COMPUTE_RESOURCE) + 1) { + Handle computeResourceLayout = {}; + uint32_t variableCounts = 0; + if (customComputeLayout) + { + // Just use the descriptor counts in bindings as the variable descriptor counts + auto const& bindings = customComputeLayout->GetBindings(); + variableCounts = bindings.back().DescriptorCount; + computeResourceLayout = customComputeLayout; + } + else + computeResourceLayout = layouts[descMappings.at(SHPredefinedDescriptorTypes::RENDER_GRAPH_NODE_COMPUTE_RESOURCE)]; + + // create compute resources computeResource = graphStorage->resourceHub->Create(); - auto computeResourceLayout = layouts[descMappings.at(SHPredefinedDescriptorTypes::RENDER_GRAPH_NODE_COMPUTE_RESOURCE)]; - computeResource->descSet = graphStorage->descriptorPool->Allocate({ computeResourceLayout }, { 1 }); + computeResource->descSet = graphStorage->descriptorPool->Allocate({ computeResourceLayout }, {variableCounts}); #ifdef _DEBUG for (auto set : computeResource->descSet->GetVkHandle()) SET_VK_OBJ_NAME(graphStorage->logicalDevice, vk::ObjectType::eDescriptorSet, set, "[Descriptor Set] " + name + " Resources"); diff --git a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNodeCompute.h b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNodeCompute.h index 476099c7..5f68cf2c 100644 --- a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNodeCompute.h +++ b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNodeCompute.h @@ -86,7 +86,7 @@ namespace SHADE void SetFollowingEndRenderpass (uint32_t flag) noexcept; public: - SHRenderGraphNodeCompute(std::string nodeName, Handle graphStorage, Handle computeShaderModule, std::vector>&& subpassComputeResources, std::unordered_set&& dynamicBufferBindings, bool followingEndRP, float inNumWorkGroupScale = 1.0f) noexcept; + SHRenderGraphNodeCompute(std::string nodeName, Handle graphStorage, Handle computeShaderModule, std::vector>&& subpassComputeResources, std::unordered_set&& dynamicBufferBindings, bool followingEndRP, Handle customComputeLayout, float inNumWorkGroupScale = 1.0f) noexcept; void Execute (Handle cmdBuffer, uint32_t frameIndex) noexcept; void HandleResize (void) noexcept; From db87bea002395ecfc632d240b602c9a39aedb52c Mon Sep 17 00:00:00 2001 From: Brandon Mak Date: Wed, 4 Jan 2023 09:58:29 +0800 Subject: [PATCH 06/45] Added pre compute functions for render graph node compute --- .../MiddleEnd/Interface/SHGraphicsSystem.cpp | 15 ++++---- .../RenderGraph/SHRenderGraphNode.cpp | 22 ++++++++---- .../RenderGraph/SHRenderGraphNodeCompute.cpp | 10 ++++++ .../RenderGraph/SHRenderGraphNodeCompute.h | 8 +++++ .../src/Graphics/RenderGraph/SHSubpass.cpp | 35 ++++++++++--------- 5 files changed, 60 insertions(+), 30 deletions(-) diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp index 98c897f3..19a24e0c 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp @@ -262,7 +262,7 @@ namespace SHADE /*-----------------------------------------------------------------------*/ // Shadow map pass will have no resources bound at first. Lighting system will add resources to the node. // It will initially also not have any subpasses since they will be added for each light that casts shadows. - auto shadowMapPass = renderGraph->AddNode(SHGraphicsConstants::RenderGraphNodeNames::SHADOW_MAP_PASS.data(), {}, {}); + auto shadowMapPassNode = renderGraph->AddNode(SHGraphicsConstants::RenderGraphNodeNames::SHADOW_MAP_PASS.data(), {}, {}); /*-----------------------------------------------------------------------*/ /* DEFERRED COMPOSITE NODE */ @@ -279,17 +279,16 @@ namespace SHADE }, { SHGraphicsConstants::RenderGraphNodeNames::GBUFFER_PASS .data()}); - // Add subpass with exterior draw call to transition shadow maps - //auto shadowMapTransitionSubpass = deferredCompositeNode->AddSubpass("Shadow Map Transition", {}, {}); - //shadowMapTransitionSubpass->AddExteriorDrawCalls([=](Handle cmdBuffer, Handle renderer, uint32_t frameIndex) - // { - // lightingSubSystem->PrepareShadowMapsForRead(cmdBuffer); - // }); /*-----------------------------------------------------------------------*/ /* DEFERRED COMPOSITE SUBPASS INIT */ /*-----------------------------------------------------------------------*/ - deferredCompositeNode->AddNodeCompute("Deferred Composite", deferredCompositeShader, { "Position", "Normals", "Albedo", "Light Layer Indices", "SSAO Blur", "Scene" }); + auto deferredCompositeCompute = deferredCompositeNode->AddNodeCompute("Deferred Composite", deferredCompositeShader, { "Position", "Normals", "Albedo", "Light Layer Indices", "SSAO Blur", "Scene" }); + deferredCompositeCompute->AddPreComputeFunction([=](Handle cmdBuffer, uint32_t frameIndex) + { + lightingSubSystem->PrepareShadowMapsForRead(cmdBuffer); + }); + /*-----------------------------------------------------------------------*/ /* DEBUG DRAW PASS INIT */ diff --git a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNode.cpp b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNode.cpp index 122f41da..cf4623e6 100644 --- a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNode.cpp +++ b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNode.cpp @@ -129,20 +129,25 @@ namespace SHADE if (subpasses.empty()) return; + uint32_t numValidSubpasses = std::count_if(subpasses.begin(), subpasses.end(), [](Handle subpass) {return !subpass->HasNoAttachments();}); + // Create subpass description and dependencies based on number of subpasses - spDescs.resize(subpasses.size()); - spDeps.resize(subpasses.size()); + spDescs.resize(numValidSubpasses); + spDeps.resize(numValidSubpasses); // Now we want to loop through all attachments in all subpasses in the node and query // the resources being used. For each resource we want to query the type and record it // in bit fields (1 bit for each subpass). uint32_t colorRead = 0, colorWrite = 0, depthRead = 0, depthWrite = 0, inputDependencies = 0; - uint32_t i = 0; // For all subpasses (see above description about bit field for this). - for (auto& subpass : subpasses) + for (uint32_t i = 0; auto& subpass : subpasses) { + // skip if subpass is not valid + if (subpass->HasNoAttachments()) + continue; + // Configure subpass description auto& desc = spDescs[i]; desc.pColorAttachments = subpass->colorReferences.data(); @@ -198,8 +203,11 @@ namespace SHADE // Loop through all subpasses again but this time we use the bit field to initialize // the dependencies. - for (i = 0; i < subpasses.size(); ++i) + for (uint32_t i = 0; auto & subpass : subpasses) { + if (subpass->HasNoAttachments()) + continue; + vk::PipelineStageFlags srcStage; vk::PipelineStageFlags dstStage; vk::AccessFlags srcAccess; @@ -257,6 +265,8 @@ namespace SHADE // initialize input descriptors subpasses[i]->CreateInputDescriptors(); + + ++i; } } @@ -639,7 +649,7 @@ namespace SHADE subpasses[i]->Execute(commandBuffer, descPool, frameIndex); // Go to next subpass if not last subpass - if (i != static_cast(subpasses.size()) - 1u) + if (i != static_cast(subpasses.size()) - 1u && !subpasses[i]->HasNoAttachments()) commandBuffer->NextSubpass(); } diff --git a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNodeCompute.cpp b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNodeCompute.cpp index fd46cfe7..55f8a9c9 100644 --- a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNodeCompute.cpp +++ b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNodeCompute.cpp @@ -152,6 +152,11 @@ namespace SHADE void SHRenderGraphNodeCompute::Execute(Handle cmdBuffer, uint32_t frameIndex) noexcept { + for (auto& fn : preComputeFunctions) + { + fn (cmdBuffer, frameIndex); + } + // bind the compute pipeline cmdBuffer->BindPipeline(computePipeline); @@ -252,4 +257,9 @@ namespace SHADE } + void SHRenderGraphNodeCompute::AddPreComputeFunction(PreComputeFunction const& fn) noexcept + { + preComputeFunctions.push_back(fn); + } + } diff --git a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNodeCompute.h b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNodeCompute.h index 5f68cf2c..9352f1d9 100644 --- a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNodeCompute.h +++ b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNodeCompute.h @@ -25,6 +25,10 @@ namespace SHADE class SHRenderGraphNodeCompute { + public: + using PreComputeFunction = std::function, uint32_t)>; + + private: // Binding of set SHGraphicsConstants::DescriptorSetIndex::RENDERGRAPH_NODE_COMPUTE_RESOURCE struct ComputeResource @@ -73,6 +77,9 @@ namespace SHADE //! Name of this node std::string name; + std::vector preComputeFunctions; + + private: /*-----------------------------------------------------------------------*/ /* PRIVATE MEMBER FUNCTIONS */ @@ -97,6 +104,7 @@ namespace SHADE void ModifyWriteDescBufferComputeResource (uint32_t binding, std::span> const& buffers, uint32_t offset, uint32_t range) noexcept; void ModifyWriteDescImageComputeResource(uint32_t binding, std::span const& viewSamplerLayouts) noexcept; + void AddPreComputeFunction (PreComputeFunction const& fn) noexcept; friend class SHRenderGraph; friend class SHRenderGraphNode; diff --git a/SHADE_Engine/src/Graphics/RenderGraph/SHSubpass.cpp b/SHADE_Engine/src/Graphics/RenderGraph/SHSubpass.cpp index 1f03bbc4..c7982906 100644 --- a/SHADE_Engine/src/Graphics/RenderGraph/SHSubpass.cpp +++ b/SHADE_Engine/src/Graphics/RenderGraph/SHSubpass.cpp @@ -211,25 +211,28 @@ namespace SHADE { commandBuffer->BeginLabeledSegment(name); - // Ensure correct transforms are provided - superBatch->UpdateBuffers(frameIndex, descPool); - - if (viewport) + if (!HasNoAttachments()) { - // set viewport and scissor - uint32_t w = static_cast(viewport->GetWidth()); - uint32_t h = static_cast(viewport->GetHeight()); - commandBuffer->SetViewportScissor(static_cast(w), static_cast(h), w, h); + // Ensure correct transforms are provided + superBatch->UpdateBuffers(frameIndex, descPool); + + if (viewport) + { + // set viewport and scissor + uint32_t w = static_cast(viewport->GetWidth()); + uint32_t h = static_cast(viewport->GetHeight()); + commandBuffer->SetViewportScissor(static_cast(w), static_cast(h), w, h); + } + + auto const& descMappings = SHGraphicsPredefinedData::GetMappings(SHGraphicsPredefinedData::SystemType::BATCHING); + + if (renderer) + renderer->BindDescriptorSet(commandBuffer, SH_PIPELINE_TYPE::GRAPHICS, descMappings.at(SHPredefinedDescriptorTypes::CAMERA), frameIndex); + + // Draw all the batches + superBatch->Draw(commandBuffer, frameIndex); } - auto const& descMappings = SHGraphicsPredefinedData::GetMappings(SHGraphicsPredefinedData::SystemType::BATCHING); - - if (renderer) - renderer->BindDescriptorSet(commandBuffer, SH_PIPELINE_TYPE::GRAPHICS, descMappings.at(SHPredefinedDescriptorTypes::CAMERA), frameIndex); - - // Draw all the batches - superBatch->Draw(commandBuffer, frameIndex); - // Draw all the exterior draw calls for (auto& drawCall : exteriorDrawCalls) { From 19f9b67550a53b8e2f660e59053a86a42882c64c Mon Sep 17 00:00:00 2001 From: Brandon Mak Date: Fri, 6 Jan 2023 10:40:19 +0800 Subject: [PATCH 07/45] Shadow map WIP - Added companion subpass object to subpass - Lighting sub system updates a light's renderer when it is a valid handle - Light component's renderer will be created in the graphics system event when a light's shadow is enabled --- Assets/Shaders/ShadowMap_VS.glsl | 21 +++++++++++ .../src/Graphics/Events/SHGraphicsEvents.h | 3 ++ .../MiddleEnd/Interface/SHGraphicsSystem.cpp | 26 +++++++++++-- .../Graphics/MiddleEnd/Interface/SHRenderer.h | 2 +- .../MiddleEnd/Lights/SHLightComponent.cpp | 13 +++++++ .../MiddleEnd/Lights/SHLightComponent.h | 7 ++++ .../MiddleEnd/Lights/SHLightingSubSystem.cpp | 37 ++++++++++++++++++- .../MiddleEnd/Lights/SHLightingSubSystem.h | 7 +++- .../RenderGraph/SHRenderGraphNode.cpp | 4 +- .../Graphics/RenderGraph/SHRenderGraphNode.h | 2 +- .../src/Graphics/RenderGraph/SHSubpass.cpp | 6 +++ .../src/Graphics/RenderGraph/SHSubpass.h | 35 ++++++++++++++---- 12 files changed, 144 insertions(+), 19 deletions(-) create mode 100644 Assets/Shaders/ShadowMap_VS.glsl diff --git a/Assets/Shaders/ShadowMap_VS.glsl b/Assets/Shaders/ShadowMap_VS.glsl new file mode 100644 index 00000000..bf353eb5 --- /dev/null +++ b/Assets/Shaders/ShadowMap_VS.glsl @@ -0,0 +1,21 @@ +#version 450 +#extension GL_KHR_vulkan_glsl : enable + +//#include "ShaderDescriptorDefinitions.glsl" + + +layout(location = 0) in vec3 aVertexPos; + +layout(set = 1, binding = 0) uniform CameraData +{ + vec4 position; + mat4 vpMat; + mat4 viewMat; + mat4 projMat; +} cameraData; + +void main() +{ + // clip space for rendering + gl_Position = cameraData.vpMat * worldTransform * vec4 (aVertexPos, 1.0f); +} \ No newline at end of file diff --git a/SHADE_Engine/src/Graphics/Events/SHGraphicsEvents.h b/SHADE_Engine/src/Graphics/Events/SHGraphicsEvents.h index ab120a1f..06c480ef 100644 --- a/SHADE_Engine/src/Graphics/Events/SHGraphicsEvents.h +++ b/SHADE_Engine/src/Graphics/Events/SHGraphicsEvents.h @@ -10,5 +10,8 @@ namespace SHADE { //! We need to get the light component and initialize the relevant variables. EntityID lightEntity; + + //! Generate a renderer for the light component + bool generateRenderer; }; } diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp index 19a24e0c..19ad5473 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp @@ -46,6 +46,7 @@ of DigiPen Institute of Technology is prohibited. #include "Graphics/MiddleEnd/GlobalData/SHGlobalDescriptorSets.h" #include "Events/SHEvent.h" #include "Graphics/MiddleEnd/Lights/SHLightComponent.h" +#include "Input/SHInputManager.h" namespace SHADE { @@ -400,7 +401,7 @@ namespace SHADE postOffscreenRenderSubSystem->Init(device, renderGraph->GetRenderGraphResource("Scene"), descPool); lightingSubSystem = resourceManager.Create(); - lightingSubSystem->Init(device, descPool, samplerCache.GetSampler (device, SHVkSamplerParams + lightingSubSystem->Init(device, descPool, &resourceManager, samplerCache.GetSampler (device, SHVkSamplerParams { // nothing for now }) @@ -557,6 +558,15 @@ namespace SHADE #endif } + if (SHInputManager::GetKeyDown(SHInputManager::SH_KEYCODE::B)) + { + auto& lightComps = SHComponentManager::GetDense(); + for (auto& comp : lightComps) + { + comp.SetEnableShadow(true); + } + } + renderGraph->Begin(frameIndex); auto cmdBuffer = renderGraph->GetCommandBuffer(frameIndex); @@ -746,18 +756,26 @@ namespace SHADE auto* lightComp = SHComponentManager::GetComponent(EVENT_DATA->lightEntity); std::string resourceName = "ShadowMap " + std::to_string(EVENT_DATA->lightEntity); + if (EVENT_DATA->generateRenderer) + { + // Create new renderer for the light component and give it to the light component + Handle newRenderer = resourceManager.Create(device, swapchain->GetNumImages(), descPool, SHRenderer::PROJECTION_TYPE::ORTHOGRAPHIC); + lightComp->SetRenderer (newRenderer); + } + // Add the shadow map resource to the graph - renderGraph->AddResource(resourceName, {SH_RENDER_GRAPH_RESOURCE_FLAGS::COLOR, SH_RENDER_GRAPH_RESOURCE_FLAGS::INPUT, SH_RENDER_GRAPH_RESOURCE_FLAGS::STORAGE}, resizeWidth, resizeHeight, vk::Format::eD24UnormS8Uint); + renderGraph->AddResource(resourceName, {SH_RENDER_GRAPH_RESOURCE_FLAGS::DEPTH_STENCIL, SH_RENDER_GRAPH_RESOURCE_FLAGS::INPUT}, resizeWidth, resizeHeight, vk::Format::eD24UnormS8Uint); // link resource to node. This means linking the resource and regenerating the node's renderpass and framebuffer. auto shadowMapNode = renderGraph->GetNode(SHGraphicsConstants::RenderGraphNodeNames::SHADOW_MAP_PASS.data()); shadowMapNode->RuntimeLinkResource(resourceName); // Add a subpass to render to that shadow map - shadowMapNode->RuntimeAddSubpass(resourceName + " Subpass", worldViewport, worldRenderer); + auto newSubpass = shadowMapNode->RuntimeAddSubpass(resourceName + " Subpass", worldViewport, lightComp->GetRenderer()); + newSubpass->AddDepthOutput(resourceName, SH_RENDER_GRAPH_RESOURCE_FLAGS::DEPTH_STENCIL); // regenerate the node - //shadowMapNode->RuntimeStandaloneRegenerate(); + shadowMapNode->RuntimeStandaloneRegenerate(); return eventPtr->handle; } diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHRenderer.h b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHRenderer.h index baf76187..a17ab1a9 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHRenderer.h +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHRenderer.h @@ -18,9 +18,9 @@ of DigiPen Institute of Technology is prohibited. // Project Includes #include "SHCamera.h" #include "Resource/SHHandle.h" -#include "Graphics/RenderGraph/SHRenderGraph.h" #include "Math/SHMath.h" #include +#include "Graphics/Pipeline/SHPipelineType.h" namespace SHADE { diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightComponent.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightComponent.cpp index 362b0e8f..4dc6e83e 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightComponent.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightComponent.cpp @@ -2,6 +2,7 @@ #include "SHLightComponent.h" #include "Graphics/Events/SHGraphicsEvents.h" #include "Events/SHEventManager.hpp" +#include "Graphics/MiddleEnd/Interface/SHRenderer.h" namespace SHADE { @@ -14,6 +15,7 @@ namespace SHADE //indexInBuffer = std::numeric_limits::max(); isActive = true; //Unbind(); + renderer = {}; } @@ -116,11 +118,17 @@ namespace SHADE // Create new event and broadcast it SHLightEnableShadowEvent newEvent; newEvent.lightEntity = GetEID(); + newEvent.generateRenderer = static_cast(!renderer); SHEventManager::BroadcastEvent(newEvent, SH_GRAPHICS_LIGHT_ENABLE_SHADOW_EVENT); } } + void SHLightComponent::SetRenderer(Handle newRenderer) noexcept + { + renderer = newRenderer; + } + SHLightData const& SHLightComponent::GetLightData(void) const noexcept { return lightData; @@ -172,6 +180,11 @@ namespace SHADE return lightData.strength; } + Handle SHLightComponent::GetRenderer(void) const noexcept + { + return renderer; + } + } RTTR_REGISTRATION diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightComponent.h b/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightComponent.h index 1d636595..4019d2f4 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightComponent.h +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightComponent.h @@ -3,9 +3,11 @@ #include #include "ECS_Base/Components/SHComponent.h" #include "SHLightData.h" +#include "Resource/SHHandle.h" namespace SHADE { + class SHRenderer; class SH_API SHLightComponent final : public SHComponent { @@ -14,6 +16,9 @@ namespace SHADE //! GPU depends on the type of the light. SHLightData lightData; + //! Renderer to calculate light world to projection matrix + Handle renderer; + //! Since the lighting system is gonna be self contained and light weight, we store this //! so that we only write this to the CPU buffer when this light component change, we don't //! rewrite everything. However we still write to the GPU buffer when everything changes. @@ -49,6 +54,7 @@ namespace SHADE //void SetBound (uint32_t inIndexInBuffer) noexcept; void SetStrength (float value) noexcept; // serialized void SetEnableShadow (bool flag) noexcept; + void SetRenderer (Handle newRenderer) noexcept; SHLightData const& GetLightData (void) const noexcept; @@ -61,6 +67,7 @@ namespace SHADE //bool GetBound (void) const noexcept; //uint32_t GetIndexInBuffer (void) const noexcept; float GetStrength (void) const noexcept; + Handle GetRenderer (void) const noexcept; RTTR_ENABLE() }; } diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightingSubSystem.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightingSubSystem.cpp index 997fe68a..31512f9b 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightingSubSystem.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightingSubSystem.cpp @@ -13,6 +13,9 @@ #include "Graphics/Images/SHVkImageView.h" #include "Graphics/MiddleEnd/Textures/SHVkSamplerCache.h" #include "Graphics/Images/SHVkSampler.h" +#include "Graphics/Events/SHGraphicsEvents.h" +#include "Graphics/MiddleEnd/Interface/SHRenderer.h" +#include "Math/Transform/SHTransformComponent.h" namespace SHADE { @@ -373,6 +376,27 @@ namespace SHADE } + SHMatrix SHLightingSubSystem::GetViewMatrix(SHLightComponent* lightComp) noexcept + { + SHTransformComponent* transform = SHComponentManager::GetComponent(lightComp->GetEID()); + switch (lightComp->GetLightData().type) + { + case SH_LIGHT_TYPE::DIRECTIONAL: + return SHMatrix::LookAtRH(transform->GetLocalPosition(), lightComp->GetLightData().position, SHVec3(0.0f, 1.0f, 0.0f)); + case SH_LIGHT_TYPE::POINT: + return {}; + case SH_LIGHT_TYPE::SPOT: + return {}; + case SH_LIGHT_TYPE::AMBIENT: + return {}; + case SH_LIGHT_TYPE::NUM_TYPES: + return {}; + default: + return {}; + + } + } + /***************************************************************************/ /*! @@ -383,11 +407,12 @@ namespace SHADE */ /***************************************************************************/ - void SHLightingSubSystem::Init(Handle device, Handle descPool, Handle inShadowMapSampler) noexcept + void SHLightingSubSystem::Init(Handle device, Handle descPool, SHResourceHub* rh, Handle inShadowMapSampler) noexcept { SHComponentManager::CreateComponentSparseSet(); logicalDevice = device; + resourceHub = rh; uint32_t constexpr NUM_LIGHT_TYPES = SHUtilities::ConvertEnum(SH_LIGHT_TYPE::NUM_TYPES); #pragma region LIGHTING @@ -496,6 +521,14 @@ namespace SHADE // Light is now updated in the container //light.ClearDirtyFlag(); } + + + if (auto renderer = light.GetRenderer()) + { + //SHMatrix orthoMatrix = SHMatrix::OrthographicRH() + renderer->UpdateDataManual (frameIndex, GetViewMatrix(&light), SHMatrix::OrthographicRH(80.0f, 80.0f, 0.01f, 10000.0f)); + + } } // Write data to GPU @@ -561,7 +594,7 @@ namespace SHADE // Update descriptor set static constexpr uint32_t SHADOW_MAP_DESC_SET_INDEX = 0; - uint32_t const SHADOW_MAP_DESC_ARRAY_INDEX = shadowMapImageSamplers.size() - 1; + uint32_t const SHADOW_MAP_DESC_ARRAY_INDEX = static_cast(shadowMapImageSamplers.size()) - 1u; shadowMapDescriptorSet->ModifyWriteDescImage ( SHADOW_MAP_DESC_SET_INDEX, diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightingSubSystem.h b/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightingSubSystem.h index 65b58174..320c18b7 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightingSubSystem.h +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightingSubSystem.h @@ -178,6 +178,10 @@ namespace SHADE //! to VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL) std::vector shadowMapMemoryBarriers; + //! Resource hub from Graphics System + SHResourceHub* resourceHub; + + /*-----------------------------------------------------------------------*/ /* PRIVATE MEMBER FUNCTIONS */ /*-----------------------------------------------------------------------*/ @@ -185,13 +189,14 @@ namespace SHADE void ComputeDynamicOffsets (void) noexcept; void ResetNumLights (void) noexcept; void UpdateShadowMapDesc (void) noexcept; + SHMatrix GetViewMatrix (SHLightComponent* lightComp) noexcept; public: /*-----------------------------------------------------------------------*/ /* PUBLIC MEMBER FUNCTIONS */ /*-----------------------------------------------------------------------*/ - void Init (Handle device, Handle descPool, Handle inShadowMapSampler) noexcept; + void Init (Handle device, Handle descPool, SHResourceHub* rh, Handle inShadowMapSampler) noexcept; void Run (SHMatrix const& viewMat, uint32_t frameIndex) noexcept; void Exit (void) noexcept; void BindDescSet (Handle cmdBuffer, uint32_t setIndex, uint32_t frameIndex) noexcept; diff --git a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNode.cpp b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNode.cpp index cf4623e6..2f498d5a 100644 --- a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNode.cpp +++ b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNode.cpp @@ -743,9 +743,9 @@ namespace SHADE resourceAttachmentMapping->try_emplace(newResource.GetId().Raw, attachmentDescriptions.size() - 1); } - void SHRenderGraphNode::RuntimeAddSubpass(std::string subpassName, Handle viewport, Handle renderer) noexcept + Handle SHRenderGraphNode::RuntimeAddSubpass(std::string subpassName, Handle viewport, Handle renderer) noexcept { - AddSubpass(std::move (subpassName), viewport, renderer); + return AddSubpass(std::move (subpassName), viewport, renderer); } /***************************************************************************/ diff --git a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNode.h b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNode.h index 8744184f..27fdaa19 100644 --- a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNode.h +++ b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNode.h @@ -117,7 +117,7 @@ namespace SHADE // Runtime functions that don't affect the renderpass void RuntimeLinkResource(std::string resourceName) noexcept; - void RuntimeAddSubpass(std::string subpassName, Handle viewport, Handle renderer) noexcept; + Handle RuntimeAddSubpass(std::string subpassName, Handle viewport, Handle renderer) noexcept; void RuntimeStandaloneRegenerate (void) noexcept; /*-----------------------------------------------------------------------*/ diff --git a/SHADE_Engine/src/Graphics/RenderGraph/SHSubpass.cpp b/SHADE_Engine/src/Graphics/RenderGraph/SHSubpass.cpp index c7982906..cd5bae58 100644 --- a/SHADE_Engine/src/Graphics/RenderGraph/SHSubpass.cpp +++ b/SHADE_Engine/src/Graphics/RenderGraph/SHSubpass.cpp @@ -443,6 +443,12 @@ namespace SHADE subpassIndex = index; } + void SHSubpass::SetCompanionSubpass(Handle companion, Handle pipeline) noexcept + { + companionSubpass.companion = companion; + companionSubpass.pipeline = pipeline; + } + /***************************************************************************/ /*! diff --git a/SHADE_Engine/src/Graphics/RenderGraph/SHSubpass.h b/SHADE_Engine/src/Graphics/RenderGraph/SHSubpass.h index 7f1bd3da..f84d4dee 100644 --- a/SHADE_Engine/src/Graphics/RenderGraph/SHSubpass.h +++ b/SHADE_Engine/src/Graphics/RenderGraph/SHSubpass.h @@ -21,12 +21,23 @@ namespace SHADE class SHVkSampler; class SHRenderer; class SHViewport; + class SHVkPipeline; class SH_API SHSubpass : public ISelfHandle { public: using ExteriorDrawCallFunction = std::function, Handle, uint32_t)>; + // Allows for subpasses to run using a companions data + struct CompanionSubpass + { + // subpass whose data will be borrowed to draw + Handle companion; + + // Pipeline that will be used for all the draw calls from all batches of the companion subpass + Handle pipeline; + }; + private: /*---------------------------------------------------------------------*/ /* PRIVATE MEMBER VARIABLES */ @@ -94,6 +105,9 @@ namespace SHADE // For identifying subpasses std::string name; + //! Optional component to a companion subpass. If the subpass handle of this object + //! is valid, the subpass will be drawn using this companion's data. + CompanionSubpass companionSubpass; private: /*-----------------------------------------------------------------------*/ @@ -133,19 +147,24 @@ namespace SHADE void CreateInputDescriptors (void) noexcept; void UpdateWriteDescriptors (void) noexcept; - /*-----------------------------------------------------------------------*/ - /* GETTERS AND SETTERS */ - /*-----------------------------------------------------------------------*/ private: + /*-----------------------------------------------------------------------*/ + /* PRIVATE GETTERS AND SETTERS */ + /*-----------------------------------------------------------------------*/ void SetIndex (uint32_t index) noexcept; public: - Handle const& GetParentNode(void) const noexcept; - SHSubPassIndex GetIndex() const noexcept; - Handle GetSuperBatch(void) const noexcept; + /*-----------------------------------------------------------------------*/ + /* PUBLIC SETTERS AND GETTERS */ + /*-----------------------------------------------------------------------*/ + void SetCompanionSubpass (Handle companion, Handle pipeline) noexcept; + + Handle const& GetParentNode(void) const noexcept; + SHSubPassIndex GetIndex() const noexcept; + Handle GetSuperBatch(void) const noexcept; std::vector const& GetColorAttachmentReferences (void) const noexcept; - vk::Format GetFormatFromAttachmentReference (uint32_t attachmentReference) const noexcept; - const std::string& GetName() const; + vk::Format GetFormatFromAttachmentReference (uint32_t attachmentReference) const noexcept; + const std::string& GetName() const; friend class SHRenderGraphNode; friend class SHRenderGraph; From d3cd36984d879f63ee812b24e803a72d76c8094b Mon Sep 17 00:00:00 2001 From: Brandon Mak Date: Sat, 7 Jan 2023 07:42:42 +0800 Subject: [PATCH 08/45] Shadow map WIP --- Assets/Shaders/ShadowMap_VS.glsl | 1 + Assets/Shaders/ShadowMap_VS.shshaderb | Bin 0 -> 1537 bytes Assets/Shaders/ShadowMap_VS.shshaderb.shmeta | 3 + .../Graphics/MiddleEnd/Batching/SHBatch.cpp | 7 +- .../src/Graphics/MiddleEnd/Batching/SHBatch.h | 2 +- .../MiddleEnd/Batching/SHSuperBatch.cpp | 4 +- .../MiddleEnd/Batching/SHSuperBatch.h | 2 +- .../MiddleEnd/Interface/SHGraphicsSystem.cpp | 22 +++- .../MiddleEnd/Interface/SHGraphicsSystem.h | 2 + .../MiddleEnd/Lights/SHLightingSubSystem.cpp | 3 +- .../MiddleEnd/Pipeline/SHPipelineLibrary.cpp | 8 +- .../Graphics/Pipeline/SHVkPipelineLayout.cpp | 112 +++++++++--------- .../src/Graphics/RenderGraph/SHSubpass.cpp | 13 +- 13 files changed, 111 insertions(+), 68 deletions(-) create mode 100644 Assets/Shaders/ShadowMap_VS.shshaderb create mode 100644 Assets/Shaders/ShadowMap_VS.shshaderb.shmeta diff --git a/Assets/Shaders/ShadowMap_VS.glsl b/Assets/Shaders/ShadowMap_VS.glsl index bf353eb5..e078679e 100644 --- a/Assets/Shaders/ShadowMap_VS.glsl +++ b/Assets/Shaders/ShadowMap_VS.glsl @@ -5,6 +5,7 @@ layout(location = 0) in vec3 aVertexPos; +layout(location = 4) in mat4 worldTransform; layout(set = 1, binding = 0) uniform CameraData { diff --git a/Assets/Shaders/ShadowMap_VS.shshaderb b/Assets/Shaders/ShadowMap_VS.shshaderb new file mode 100644 index 0000000000000000000000000000000000000000..3a8734c9daf1a50b7a6993c299eb04bab307964a GIT binary patch literal 1537 zcmZ9LTW`}q5QVq7wY0RQlwN>Rl7^dvRPg`^2?0Vaavy>kRK%-gB?c{W9LsT2;Hf{M z@RRseeL>=Uwl}i6)nshUe|`(gSeOtbKZLZJoDp4@n1 zGdqrj&gXpe=eUit6Z=b@sVQ=3R_-9O$)TNOK|Ba&Ic`txG>T@qrtZnTSxx<|$sYux zFbxiaEGV>qu@Wal`&P+C%QX2IWEBhzQyZRvIv%}~bo?ERKI@7Hl|IaZ*`JNmX!tn| z;>p)>Iw~~rJ%VC9nuRe(s%LI2=N*O~FucRi1BM2Nu?OROc*?McN8a7HtC)2p78qyp z{2YfE&W$UW9%hLZb(~wRBc`q|b7z5FtwUqAj+nX&nX3bHb=(7;oaIR~Gv1S-)5RU_ zS;X$G7c*$&@19w+)^!T!baW;?*l%jrl5fklR8L=G>NoVue^gt>dRoTUw5R`$;zfD* zV7uBeb9V+gtS#Pkd3ut6UB>w`H75AL3ORYg;kjgLBbEA7hH;u1BXw{yus+_W^2s(JNS=; zQ;YVOdI{*_PAu?CA-s?G`bFEO4E<<+BPP1GWZ*8oqdgk`sD}Jq860ppXuB^%*C%n% z)G0B!8MaqqXm`ABiJ`ME)#!d8qaHr_w(PggCHGK9e>mKM`#zTOt@)mBbxUG+|1_mn Fvi~Asj5 literal 0 HcmV?d00001 diff --git a/Assets/Shaders/ShadowMap_VS.shshaderb.shmeta b/Assets/Shaders/ShadowMap_VS.shshaderb.shmeta new file mode 100644 index 00000000..837cec19 --- /dev/null +++ b/Assets/Shaders/ShadowMap_VS.shshaderb.shmeta @@ -0,0 +1,3 @@ +Name: ShadowMap_VS +ID: 44646107 +Type: 2 diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Batching/SHBatch.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Batching/SHBatch.cpp index 7e4069f6..fd2ccd3b 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Batching/SHBatch.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Batching/SHBatch.cpp @@ -551,7 +551,7 @@ namespace SHADE /*---------------------------------------------------------------------------------*/ /* SHBatch - Usage Functions */ /*---------------------------------------------------------------------------------*/ - void SHBatch::Draw(Handle cmdBuffer, uint32_t frameIndex) + void SHBatch::Draw(Handle cmdBuffer, uint32_t frameIndex, bool bindBatchPipeline/* = true*/) { if (frameIndex >= SHGraphicsConstants::NUM_FRAME_BUFFERS) { @@ -566,7 +566,10 @@ namespace SHADE // Bind all required objects before drawing static std::array dynamicOffset{ 0 }; cmdBuffer->BeginLabeledSegment("SHBatch for Pipeline #" + std::to_string(pipeline.GetId().Data.Index)); - cmdBuffer->BindPipeline(pipeline); + + if (bindBatchPipeline) + cmdBuffer->BindPipeline(pipeline); + cmdBuffer->BindVertexBuffer(SHGraphicsConstants::VertexBufferBindings::TRANSFORM, transformDataBuffer[frameIndex], 0); cmdBuffer->BindVertexBuffer(SHGraphicsConstants::VertexBufferBindings::INTEGER_DATA, instancedIntegerBuffer[frameIndex], 0); if (matPropsDescSet[frameIndex]) diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Batching/SHBatch.h b/SHADE_Engine/src/Graphics/MiddleEnd/Batching/SHBatch.h index d4ce068e..6d1f775f 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Batching/SHBatch.h +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Batching/SHBatch.h @@ -87,7 +87,7 @@ namespace SHADE void UpdateTransformBuffer(uint32_t frameIndex); void UpdateInstancedIntegerBuffer(uint32_t frameIndex); void Build(Handle device, Handle descPool, uint32_t frameIndex) ; - void Draw(Handle cmdBuffer, uint32_t frameIndex); + void Draw(Handle cmdBuffer, uint32_t frameIndex, bool bindBatchPipeline = true); /*-----------------------------------------------------------------------------*/ /* Getter Functions */ diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Batching/SHSuperBatch.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Batching/SHSuperBatch.cpp index 58993026..8006d0be 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Batching/SHSuperBatch.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Batching/SHSuperBatch.cpp @@ -107,12 +107,12 @@ namespace SHADE } } - void SHSuperBatch::Draw(Handle cmdBuffer, uint32_t frameIndex) noexcept + void SHSuperBatch::Draw(Handle cmdBuffer, uint32_t frameIndex, bool bindBatchPipeline /*= true*/) noexcept { // Build all batches for (auto& batch : batches) { - batch.Draw(cmdBuffer, frameIndex); + batch.Draw(cmdBuffer, frameIndex, bindBatchPipeline); } } diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Batching/SHSuperBatch.h b/SHADE_Engine/src/Graphics/MiddleEnd/Batching/SHSuperBatch.h index 75bd1829..4d831b9c 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Batching/SHSuperBatch.h +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Batching/SHSuperBatch.h @@ -57,7 +57,7 @@ namespace SHADE void Clear() noexcept; void UpdateBuffers(uint32_t frameIndex, Handle descPool); void Build(Handle device, Handle descPool, uint32_t frameIndex) noexcept; - void Draw(Handle cmdBuffer, uint32_t frameIndex) noexcept; + void Draw(Handle cmdBuffer, uint32_t frameIndex, bool bindBatchPipeline = true) noexcept; /*-----------------------------------------------------------------------------*/ /* Getter Functions */ diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp index 19ad5473..ec592522 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp @@ -127,6 +127,8 @@ namespace SHADE SHFreetypeInstance::Init(); + SHAssetManager::CompileAsset("../../Assets/Shaders/ShadowMap_VS.glsl", false); + // Load Built In Shaders static constexpr AssetID VS_DEFAULT = 39210065; defaultVertShader = SHResourceManager::LoadOrGet(VS_DEFAULT); static constexpr AssetID FS_DEFAULT = 46377769; defaultFragShader = SHResourceManager::LoadOrGet(FS_DEFAULT); @@ -140,6 +142,8 @@ namespace SHADE static constexpr AssetID TEXT_FS = 38024754; textFS = SHResourceManager::LoadOrGet(TEXT_FS); static constexpr AssetID RENDER_SC_VS = 48082949; renderToSwapchainVS = SHResourceManager::LoadOrGet(RENDER_SC_VS); static constexpr AssetID RENDER_SC_FS = 36869006; renderToSwapchainFS = SHResourceManager::LoadOrGet(RENDER_SC_FS); + static constexpr AssetID SHADOW_MAP_VS = 44646107; shadowMapVS = SHResourceManager::LoadOrGet(SHADOW_MAP_VS); + } void SHGraphicsSystem::InitRenderGraph(void) noexcept @@ -752,9 +756,20 @@ namespace SHADE // we need to wait for the device to finish using the graph first device->WaitIdle(); - auto const& EVENT_DATA = reinterpret_cast*>(eventPtr.get())->data; - auto* lightComp = SHComponentManager::GetComponent(EVENT_DATA->lightEntity); - std::string resourceName = "ShadowMap " + std::to_string(EVENT_DATA->lightEntity); + auto const& EVENT_DATA = reinterpret_cast*>(eventPtr.get())->data; + auto* lightComp = SHComponentManager::GetComponent(EVENT_DATA->lightEntity); + std::string resourceName = "ShadowMap " + std::to_string(EVENT_DATA->lightEntity); + Handle companionSubpass = renderGraph->GetNode(SHGraphicsConstants::RenderGraphNodeNames::GBUFFER_PASS.data())->GetSubpass("G-Buffer Write"); + + if (!shadowMapPipeline) + { + SHPipelineLibrary tempLibrary{}; + Handle rgNode = renderGraph->GetNode(SHGraphicsConstants::RenderGraphNodeNames::SHADOW_MAP_PASS.data()); + + tempLibrary.Init(device); + tempLibrary.CreateGraphicsPipelines({ shadowMapVS, {} }, rgNode->GetRenderpass(), companionSubpass); + shadowMapPipeline = tempLibrary.GetGraphicsPipeline({ shadowMapVS, {} }); + } if (EVENT_DATA->generateRenderer) { @@ -773,6 +788,7 @@ namespace SHADE // Add a subpass to render to that shadow map auto newSubpass = shadowMapNode->RuntimeAddSubpass(resourceName + " Subpass", worldViewport, lightComp->GetRenderer()); newSubpass->AddDepthOutput(resourceName, SH_RENDER_GRAPH_RESOURCE_FLAGS::DEPTH_STENCIL); + newSubpass->SetCompanionSubpass(companionSubpass, shadowMapPipeline); // set companion subpass and pipeline // regenerate the node shadowMapNode->RuntimeStandaloneRegenerate(); diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.h b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.h index 88d66ded..b8c43c75 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.h +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.h @@ -464,6 +464,7 @@ namespace SHADE Handle textFS; Handle renderToSwapchainVS; Handle renderToSwapchainFS; + Handle shadowMapVS; // Fonts Handle testFont; @@ -478,6 +479,7 @@ namespace SHADE Handle debugDrawWireMeshDepthPipeline; Handle debugDrawFilledPipeline; Handle debugDrawFilledDepthPipeline; + Handle shadowMapPipeline; // initialized only when a shadow map is needed // Built-In Textures Handle defaultTexture; diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightingSubSystem.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightingSubSystem.cpp index 31512f9b..17cffe17 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightingSubSystem.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightingSubSystem.cpp @@ -378,11 +378,10 @@ namespace SHADE SHMatrix SHLightingSubSystem::GetViewMatrix(SHLightComponent* lightComp) noexcept { - SHTransformComponent* transform = SHComponentManager::GetComponent(lightComp->GetEID()); switch (lightComp->GetLightData().type) { case SH_LIGHT_TYPE::DIRECTIONAL: - return SHMatrix::LookAtRH(transform->GetLocalPosition(), lightComp->GetLightData().position, SHVec3(0.0f, 1.0f, 0.0f)); + return SHMatrix::LookAtRH(lightComp->GetLightData().position, lightComp->GetLightData().position + lightComp->GetLightData().direction, SHVec3(0.0f, 1.0f, 0.0f)); case SH_LIGHT_TYPE::POINT: return {}; case SH_LIGHT_TYPE::SPOT: diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Pipeline/SHPipelineLibrary.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Pipeline/SHPipelineLibrary.cpp index baf09a2d..daa4d154 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Pipeline/SHPipelineLibrary.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Pipeline/SHPipelineLibrary.cpp @@ -10,9 +10,15 @@ namespace SHADE Handle SHPipelineLibrary::CreateGraphicsPipelines(std::pair, Handle> const& vsFsPair, Handle renderpass, Handle subpass) noexcept { + std::vector> modules{}; + if (vsFsPair.first) + modules.push_back(vsFsPair.first); + if (vsFsPair.second) + modules.push_back(vsFsPair.second); + SHPipelineLayoutParams params { - .shaderModules = {vsFsPair.first, vsFsPair.second}, + .shaderModules = std::move (modules), .predefinedDescSetLayouts = SHGraphicsPredefinedData::GetSystemData(SHGraphicsPredefinedData::SystemType::BATCHING).descSetLayouts }; diff --git a/SHADE_Engine/src/Graphics/Pipeline/SHVkPipelineLayout.cpp b/SHADE_Engine/src/Graphics/Pipeline/SHVkPipelineLayout.cpp index c2d83052..325b3f56 100644 --- a/SHADE_Engine/src/Graphics/Pipeline/SHVkPipelineLayout.cpp +++ b/SHADE_Engine/src/Graphics/Pipeline/SHVkPipelineLayout.cpp @@ -19,69 +19,71 @@ namespace SHADE for (auto& shaderModule : shaderModules) { - // References for convenience - auto const& reflectedData = shaderModule->GetReflectedData(); - auto const& pcInfo = reflectedData.GetPushConstantInfo(); - - // If a push constant block exists for the shader module - if (pcInfo.memberCount != 0) + if (shaderModule) { - bool exists = false; + // References for convenience + auto const& reflectedData = shaderModule->GetReflectedData(); + auto const& pcInfo = reflectedData.GetPushConstantInfo(); - // Check if push constant block already exists - for (uint32_t i = 0; i < pcInfos.size(); ++i) + // If a push constant block exists for the shader module + if (pcInfo.memberCount != 0) { - // If there is a block with the same name, member count and size - if (std::strcmp(pcInfos[i]->name, pcInfo.name) == 0 && pcInfos[i]->memberCount == pcInfo.memberCount && pcInfos[i]->size == pcInfo.size) + bool exists = false; + + // Check if push constant block already exists + for (uint32_t i = 0; i < pcInfos.size(); ++i) { - // We just take the existing pc range we built earlier, and allow it to be accessed in potentially other shader stages - vkPcRanges[i].stageFlags |= shaderModule->GetShaderStageFlagBits(); + // If there is a block with the same name, member count and size + if (std::strcmp(pcInfos[i]->name, pcInfo.name) == 0 && pcInfos[i]->memberCount == pcInfo.memberCount && pcInfos[i]->size == pcInfo.size) + { + // We just take the existing pc range we built earlier, and allow it to be accessed in potentially other shader stages + vkPcRanges[i].stageFlags |= shaderModule->GetShaderStageFlagBits(); - // Set flag and stop checking - exists = true; - break; - } - } - - // If the block doesn't exist yet - if (!exists) - { - // Loop through all member variables of the new push constant block - for (uint32_t i = 0; i < pcInfo.memberCount; ++i) - { - std::string variableName; - variableName.reserve(50); - variableName += pcInfo.name; - variableName += "."; - variableName += pcInfo.members[i].name; - - // Add the variable's offset info to the interface - pushConstantInterface.AddOffset(std::move(variableName), startOffset + pcInfo.members[i].offset); + // Set flag and stop checking + exists = true; + break; + } } - // New push constant range - vk::PushConstantRange newRange; + // If the block doesn't exist yet + if (!exists) + { + // Loop through all member variables of the new push constant block + for (uint32_t i = 0; i < pcInfo.memberCount; ++i) + { + std::string variableName; + variableName.reserve(50); + variableName += pcInfo.name; + variableName += "."; + variableName += pcInfo.members[i].name; - // set offset and size - newRange.offset = startOffset; - newRange.size = pcInfo.size; + // Add the variable's offset info to the interface + pushConstantInterface.AddOffset(std::move(variableName), startOffset + pcInfo.members[i].offset); + } - // Stage flags will be whatever shader stage of the shader that contains the push constant block - newRange.stageFlags = shaderModule->GetShaderStageFlagBits(); + // New push constant range + vk::PushConstantRange newRange; - // Add to the list foe checking later - pcInfos.push_back(&pcInfo); + // set offset and size + newRange.offset = startOffset; + newRange.size = pcInfo.size; - // For pipeline layout to consume - vkPcRanges.push_back(newRange); + // Stage flags will be whatever shader stage of the shader that contains the push constant block + newRange.stageFlags = shaderModule->GetShaderStageFlagBits(); - // Next push constant block will start next to the previous push constant block - startOffset += pcInfo.size; + // Add to the list foe checking later + pcInfos.push_back(&pcInfo); + + // For pipeline layout to consume + vkPcRanges.push_back(newRange); + + // Next push constant block will start next to the previous push constant block + startOffset += pcInfo.size; + } + + stageFlags |= shaderModule->GetShaderStageFlagBits(); } - - stageFlags |= shaderModule->GetShaderStageFlagBits(); } - } // After all the sizes of the push constant blocks have been added, record the size in the interface @@ -132,6 +134,9 @@ namespace SHADE //! Now we take descriptor set info from all shaders and prepare some bindings for the descriptor set for (auto& shaderModule : shaderModules) { + if (!shaderModule) + continue; + auto const& descBindingInfo = shaderModule->GetReflectedData().GetDescriptorBindingInfo(); auto const& reflectedSets = descBindingInfo.GetReflectedSets(); @@ -326,11 +331,10 @@ namespace SHADE { for (auto& mod : shaderModules) { - mod->AddCallback([this]() - { - RecreateIfNeeded(); - } - ); + if (mod) + { + mod->AddCallback([this]() { RecreateIfNeeded(); }); + } } RecreateIfNeeded (); diff --git a/SHADE_Engine/src/Graphics/RenderGraph/SHSubpass.cpp b/SHADE_Engine/src/Graphics/RenderGraph/SHSubpass.cpp index cd5bae58..e1277953 100644 --- a/SHADE_Engine/src/Graphics/RenderGraph/SHSubpass.cpp +++ b/SHADE_Engine/src/Graphics/RenderGraph/SHSubpass.cpp @@ -229,8 +229,17 @@ namespace SHADE if (renderer) renderer->BindDescriptorSet(commandBuffer, SH_PIPELINE_TYPE::GRAPHICS, descMappings.at(SHPredefinedDescriptorTypes::CAMERA), frameIndex); - // Draw all the batches - superBatch->Draw(commandBuffer, frameIndex); + // If companion subpass is not a valid handle, render super batch normally + if (!companionSubpass.companion) + { + // Draw all the batches + superBatch->Draw(commandBuffer, frameIndex); + } + else + { + commandBuffer->BindPipeline(companionSubpass.pipeline); + companionSubpass.companion->superBatch->Draw(commandBuffer, frameIndex, false); + } } // Draw all the exterior draw calls From 3e01c9e80a18870ddb1411aeae13396a7c5753f0 Mon Sep 17 00:00:00 2001 From: Brandon Mak Date: Sat, 7 Jan 2023 12:01:09 +0800 Subject: [PATCH 09/45] shadows WIP --- .../GlobalData/SHGraphicsPredefinedData.cpp | 14 +++- .../GlobalData/SHGraphicsPredefinedData.h | 6 +- .../MiddleEnd/Interface/SHGraphicsSystem.cpp | 33 +++++---- .../MiddleEnd/Pipeline/SHPipelineLibrary.cpp | 5 +- .../MiddleEnd/Pipeline/SHPipelineLibrary.h | 4 +- .../src/Graphics/Pipeline/SHPipelineState.cpp | 7 +- .../src/Graphics/Pipeline/SHPipelineState.h | 2 +- .../Graphics/RenderGraph/SHRenderGraph.cpp | 70 +++++++++++++++++++ .../src/Graphics/RenderGraph/SHRenderGraph.h | 7 ++ .../RenderGraph/SHRenderGraphNode.cpp | 1 + .../src/Graphics/RenderGraph/SHSubpass.cpp | 3 + 11 files changed, 126 insertions(+), 26 deletions(-) diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/GlobalData/SHGraphicsPredefinedData.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/GlobalData/SHGraphicsPredefinedData.cpp index d09ec5b4..4082ba0f 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/GlobalData/SHGraphicsPredefinedData.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/GlobalData/SHGraphicsPredefinedData.cpp @@ -13,6 +13,8 @@ namespace SHADE /*-----------------------------------------------------------------------------------*/ std::vector> SHGraphicsPredefinedData::predefinedLayouts; SHVertexInputState SHGraphicsPredefinedData::defaultVertexInputState; + SHVertexInputState SHGraphicsPredefinedData::shadowMapVertexInputState; + std::vector SHGraphicsPredefinedData::perSystemData; //SHGraphicsPredefinedData::PerSystem SHGraphicsPredefinedData::batchingSystemData; @@ -193,7 +195,7 @@ namespace SHADE ); } - void SHGraphicsPredefinedData::InitDefaultVertexInputState(void) noexcept + void SHGraphicsPredefinedData::InitPredefinedVertexInputState(void) noexcept { defaultVertexInputState.AddBinding(false, false, { SHVertexAttribute(SHAttribFormat::FLOAT_3D) }); // positions at binding 0 defaultVertexInputState.AddBinding(false, false, { SHVertexAttribute(SHAttribFormat::FLOAT_2D) }); // UVs at binding 1 @@ -201,13 +203,16 @@ namespace SHADE defaultVertexInputState.AddBinding(false, false, { SHVertexAttribute(SHAttribFormat::FLOAT_3D) }); // Tangents at binding 3 defaultVertexInputState.AddBinding(true, true, { SHVertexAttribute(SHAttribFormat::MAT_4D) }); // Transform at binding 4 - 7 (4 slots) defaultVertexInputState.AddBinding(true, true, { SHVertexAttribute(SHAttribFormat::UINT32_2D) }); // Instanced integer data at index 8 + + shadowMapVertexInputState.AddBinding(false, false, { SHVertexAttribute(SHAttribFormat::FLOAT_3D)}); + shadowMapVertexInputState.AddBinding(true, true, { SHVertexAttribute(SHAttribFormat::MAT_4D) }, 4); // Transform at binding 4 - 7 (4 slots) } void SHGraphicsPredefinedData::Init(Handle logicalDevice) noexcept { perSystemData.resize(SHUtilities::ConvertEnum(SystemType::NUM_TYPES)); InitDescSetLayouts(logicalDevice); - InitDefaultVertexInputState(); + InitPredefinedVertexInputState(); InitDescMappings(); InitDummyPipelineLayouts (logicalDevice); } @@ -231,6 +236,11 @@ namespace SHADE } + SHVertexInputState const& SHGraphicsPredefinedData::GetShadowMapViState(void) noexcept + { + return shadowMapVertexInputState; + } + SHGraphicsPredefinedData::PerSystem const& SHGraphicsPredefinedData::GetSystemData(SystemType systemType) noexcept { return perSystemData[static_cast(systemType)]; diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/GlobalData/SHGraphicsPredefinedData.h b/SHADE_Engine/src/Graphics/MiddleEnd/GlobalData/SHGraphicsPredefinedData.h index b4004d5a..9331ed01 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/GlobalData/SHGraphicsPredefinedData.h +++ b/SHADE_Engine/src/Graphics/MiddleEnd/GlobalData/SHGraphicsPredefinedData.h @@ -58,6 +58,9 @@ namespace SHADE //! Default vertex input state (used by everything). static SHVertexInputState defaultVertexInputState; + //! vertex input state for shadow mapping + static SHVertexInputState shadowMapVertexInputState; + //! Predefined data for each type of system static std::vector perSystemData; @@ -73,7 +76,7 @@ namespace SHADE static void InitDescMappings (void) noexcept; static void InitDummyPipelineLayouts (Handle logicalDevice) noexcept; static void InitDescSetLayouts (Handle logicalDevice) noexcept; - static void InitDefaultVertexInputState (void) noexcept; + static void InitPredefinedVertexInputState (void) noexcept; public: /*-----------------------------------------------------------------------*/ @@ -91,6 +94,7 @@ namespace SHADE /*-----------------------------------------------------------------------*/ static std::vector> GetPredefinedDescSetLayouts (SHGraphicsPredefinedData::PredefinedDescSetLayoutTypes types) noexcept; static SHVertexInputState const& GetDefaultViState (void) noexcept; + static SHVertexInputState const& GetShadowMapViState (void) noexcept; static PerSystem const& GetSystemData (SystemType systemType) noexcept; static SHDescriptorMappings::MapType const& GetMappings (SystemType systemType) noexcept; //static PerSystem const& GetBatchingSystemData(void) noexcept; diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp index ec592522..e682e0a1 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp @@ -267,7 +267,7 @@ namespace SHADE /*-----------------------------------------------------------------------*/ // Shadow map pass will have no resources bound at first. Lighting system will add resources to the node. // It will initially also not have any subpasses since they will be added for each light that casts shadows. - auto shadowMapPassNode = renderGraph->AddNode(SHGraphicsConstants::RenderGraphNodeNames::SHADOW_MAP_PASS.data(), {}, {}); + //auto shadowMapPassNode = renderGraph->AddNode(SHGraphicsConstants::RenderGraphNodeNames::SHADOW_MAP_PASS.data(), {}, {}); /*-----------------------------------------------------------------------*/ /* DEFERRED COMPOSITE NODE */ @@ -760,16 +760,6 @@ namespace SHADE auto* lightComp = SHComponentManager::GetComponent(EVENT_DATA->lightEntity); std::string resourceName = "ShadowMap " + std::to_string(EVENT_DATA->lightEntity); Handle companionSubpass = renderGraph->GetNode(SHGraphicsConstants::RenderGraphNodeNames::GBUFFER_PASS.data())->GetSubpass("G-Buffer Write"); - - if (!shadowMapPipeline) - { - SHPipelineLibrary tempLibrary{}; - Handle rgNode = renderGraph->GetNode(SHGraphicsConstants::RenderGraphNodeNames::SHADOW_MAP_PASS.data()); - - tempLibrary.Init(device); - tempLibrary.CreateGraphicsPipelines({ shadowMapVS, {} }, rgNode->GetRenderpass(), companionSubpass); - shadowMapPipeline = tempLibrary.GetGraphicsPipeline({ shadowMapVS, {} }); - } if (EVENT_DATA->generateRenderer) { @@ -782,16 +772,29 @@ namespace SHADE renderGraph->AddResource(resourceName, {SH_RENDER_GRAPH_RESOURCE_FLAGS::DEPTH_STENCIL, SH_RENDER_GRAPH_RESOURCE_FLAGS::INPUT}, resizeWidth, resizeHeight, vk::Format::eD24UnormS8Uint); // link resource to node. This means linking the resource and regenerating the node's renderpass and framebuffer. - auto shadowMapNode = renderGraph->GetNode(SHGraphicsConstants::RenderGraphNodeNames::SHADOW_MAP_PASS.data()); - shadowMapNode->RuntimeLinkResource(resourceName); + //auto shadowMapNode = renderGraph->GetNode(SHGraphicsConstants::RenderGraphNodeNames::SHADOW_MAP_PASS.data()); + auto shadowMapNode = renderGraph->AddNodeAfter(SHGraphicsConstants::RenderGraphNodeNames::SHADOW_MAP_PASS.data() + resourceName, {resourceName.c_str()}, SHGraphicsConstants::RenderGraphNodeNames::GBUFFER_PASS.data()); // Add a subpass to render to that shadow map - auto newSubpass = shadowMapNode->RuntimeAddSubpass(resourceName + " Subpass", worldViewport, lightComp->GetRenderer()); + auto newSubpass = shadowMapNode->RuntimeAddSubpass(resourceName + " Subpass", worldViewport, worldRenderer); + //auto newSubpass = shadowMapNode->RuntimeAddSubpass(resourceName + " Subpass", worldViewport, lightComp->GetRenderer()); newSubpass->AddDepthOutput(resourceName, SH_RENDER_GRAPH_RESOURCE_FLAGS::DEPTH_STENCIL); - newSubpass->SetCompanionSubpass(companionSubpass, shadowMapPipeline); // set companion subpass and pipeline // regenerate the node shadowMapNode->RuntimeStandaloneRegenerate(); + + + // Create pipeline from new renderpass and subpass if it's not created yet + if (!shadowMapPipeline) + { + SHPipelineLibrary tempLibrary{}; + Handle rgNode = renderGraph->GetNode(SHGraphicsConstants::RenderGraphNodeNames::SHADOW_MAP_PASS.data()); + + tempLibrary.Init(device); + tempLibrary.CreateGraphicsPipelines({ shadowMapVS, {} }, shadowMapNode->GetRenderpass(), newSubpass, SHGraphicsPredefinedData::GetShadowMapViState()); + shadowMapPipeline = tempLibrary.GetGraphicsPipeline({ shadowMapVS, {} }); + } + newSubpass->SetCompanionSubpass(companionSubpass, shadowMapPipeline); // set companion subpass and pipeline return eventPtr->handle; } diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Pipeline/SHPipelineLibrary.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Pipeline/SHPipelineLibrary.cpp index daa4d154..6d7e6104 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Pipeline/SHPipelineLibrary.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Pipeline/SHPipelineLibrary.cpp @@ -1,14 +1,13 @@ #include "SHpch.h" #include "SHPipelineLibrary.h" #include "Graphics/Devices/SHVkLogicalDevice.h" -#include "Graphics/MiddleEnd/GlobalData/SHGraphicsPredefinedData.h" #include "Graphics/RenderGraph/SHSubpass.h" #include "Graphics/SHVkUtil.h" namespace SHADE { - Handle SHPipelineLibrary::CreateGraphicsPipelines(std::pair, Handle> const& vsFsPair, Handle renderpass, Handle subpass) noexcept + Handle SHPipelineLibrary::CreateGraphicsPipelines(std::pair, Handle> const& vsFsPair, Handle renderpass, Handle subpass, SHVertexInputState const& viState/* = SHGraphicsPredefinedData::GetDefaultViState()*/) noexcept { std::vector> modules{}; if (vsFsPair.first) @@ -27,7 +26,7 @@ namespace SHADE // Create the pipeline and configure the default vertex input state auto newPipeline = logicalDevice->CreateGraphicsPipeline(pipelineLayout, nullptr, renderpass, subpass); - newPipeline->GetPipelineState().SetVertexInputState(SHGraphicsPredefinedData::GetDefaultViState()); + newPipeline->GetPipelineState().SetVertexInputState(viState); SHColorBlendState colorBlendState{}; colorBlendState.logic_op_enable = VK_FALSE; diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Pipeline/SHPipelineLibrary.h b/SHADE_Engine/src/Graphics/MiddleEnd/Pipeline/SHPipelineLibrary.h index 5085f21f..b7485e50 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Pipeline/SHPipelineLibrary.h +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Pipeline/SHPipelineLibrary.h @@ -3,6 +3,7 @@ #include #include "Graphics/Shaders/SHVkShaderModule.h" #include "Graphics/Pipeline/SHVkPipeline.h" +#include "Graphics/MiddleEnd/GlobalData/SHGraphicsPredefinedData.h" namespace SHADE { @@ -32,7 +33,8 @@ namespace SHADE Handle CreateGraphicsPipelines ( std::pair, Handle> const& vsFsPair, Handle renderpass, - Handle subpass + Handle subpass, + SHVertexInputState const& viState = SHGraphicsPredefinedData::GetDefaultViState() ) noexcept; Handle GetGraphicsPipeline (std::pair, Handle> const& vsFsPair) noexcept; bool CheckGraphicsPipelineExistence (std::pair, Handle> const& vsFsPair) noexcept; diff --git a/SHADE_Engine/src/Graphics/Pipeline/SHPipelineState.cpp b/SHADE_Engine/src/Graphics/Pipeline/SHPipelineState.cpp index c7ada11f..49fa9086 100644 --- a/SHADE_Engine/src/Graphics/Pipeline/SHPipelineState.cpp +++ b/SHADE_Engine/src/Graphics/Pipeline/SHPipelineState.cpp @@ -195,7 +195,7 @@ namespace SHADE return *this; } - void SHVertexInputState::AddBinding(bool instanced, bool calcOffset, std::initializer_list inAttribs) noexcept + void SHVertexInputState::AddBinding(bool instanced, bool calcOffset, std::initializer_list inAttribs, uint32_t fixedAttributeLocation/* = static_cast(-1)*/) noexcept { // add a binding and get ref to it bindings.emplace_back(); @@ -228,8 +228,9 @@ namespace SHADE // The binding for that attribute description is index of the new binding created earlier in this function vertexAttrib.binding = static_cast(bindings.size() - 1); - // Attribute location. New index is simply + 1 of the previous. Starts from 0 obviously - vertexAttrib.location = static_cast(attributes.size () - 1); + //Attribute location. New index is simply + 1 of the previous. Starts from 0 obviously + vertexAttrib.location = (fixedAttributeLocation != static_cast(-1)) ? fixedAttributeLocation + i : static_cast(attributes.size () - 1); + //vertexAttrib.location = static_cast(attributes.size() - 1); // Get the vkFormat associated with the SHAttribFormat vertexAttrib.format = format; diff --git a/SHADE_Engine/src/Graphics/Pipeline/SHPipelineState.h b/SHADE_Engine/src/Graphics/Pipeline/SHPipelineState.h index 4c8d679a..380c726e 100644 --- a/SHADE_Engine/src/Graphics/Pipeline/SHPipelineState.h +++ b/SHADE_Engine/src/Graphics/Pipeline/SHPipelineState.h @@ -34,7 +34,7 @@ namespace SHADE SHVertexInputState& operator= (SHVertexInputState const& rhs) noexcept; SHVertexInputState& operator= (SHVertexInputState&& rhs) noexcept; - void AddBinding(bool instanced, bool calcOffset, std::initializer_list inAttribs) noexcept; + void AddBinding(bool instanced, bool calcOffset, std::initializer_list inAttribs, uint32_t fixedAttributeLocation = static_cast(-1)) noexcept; friend class SHVkPipelineState; friend class SHVkPipeline; diff --git a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraph.cpp b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraph.cpp index e6b9ae33..5f8b8624 100644 --- a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraph.cpp +++ b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraph.cpp @@ -275,6 +275,17 @@ namespace SHADE } } + void SHRenderGraph::ReindexNodes(void) noexcept + { + nodeIndexing.clear(); + uint32_t i = 0; + for (auto& node : nodes) + { + nodeIndexing.emplace (node->name, i); + ++i; + } + } + /***************************************************************************/ /*! @@ -415,6 +426,65 @@ namespace SHADE return node; } + /***************************************************************************/ + /*! + + \brief + This function is purely used for dynamic nodes (if such a thing were to + exist in our architecture). In other words, don't use this function unless + the new node is fully standalone and does not rely or is a prereq of + other nodes. + + \param nodeName + Name of new node + + \param resourceInstruction + Resources for the node + + \param nodeToAddAfter + The node to add the new node after. + + \return + + */ + /***************************************************************************/ + Handle SHRenderGraph::AddNodeAfter(std::string nodeName, std::initializer_list resourceInstruction, std::string nodeToAddAfter) noexcept + { + if (nodeIndexing.contains(nodeName)) + { + SHLOG_ERROR("Node already exists, cannot add node. "); + return {}; + } + + std::vector descInitParams; + for (auto const& instruction : resourceInstruction) + { + // If the resource that the new node is requesting for exists, allow the graph to reference it + if (renderGraphStorage->graphResources->contains(instruction.resourceName)) + { + descInitParams.push_back( + { + .resourceHdl = renderGraphStorage->graphResources->at(instruction.resourceName), + .dontClearOnLoad = instruction.dontClearOnLoad, + } + ); + } + else + { + SHLOG_ERROR("Resource doesn't exist in graph yet. Cannot create new node."); + return{}; + } + } + + // get target node + auto targetNode = nodes.begin() + nodeIndexing.at(nodeToAddAfter); + + auto node = nodes.insert(targetNode, renderGraphStorage->resourceHub->Create(nodeName, renderGraphStorage, std::move(descInitParams), std::vector>())); + ReindexNodes (); + return *node; + + } + void SHRenderGraph::AddRenderToSwapchainNode(std::string toSwapchainResource, std::string swapchainResource, std::initializer_list predecessorNodes, std::pair, Handle> shaderModules) noexcept { for (auto& node : predecessorNodes) diff --git a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraph.h b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraph.h index 6dbc4308..6ee181f8 100644 --- a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraph.h +++ b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraph.h @@ -55,6 +55,7 @@ namespace SHADE void ConfigureRenderpasses (void) noexcept; void ConfigureSubSystems (void) noexcept; void ConfigureFramebuffers (void) noexcept; + void ReindexNodes (void) noexcept; /*-----------------------------------------------------------------------*/ /* PRIVATE MEMBER VARIABLES */ @@ -123,6 +124,12 @@ namespace SHADE std::initializer_list resourceInstruction, std::initializer_list predecessorNodes ) noexcept; + Handle AddNodeAfter + ( + std::string nodeName, + std::initializer_list resourceInstruction, + std::string nodeToAddAfter + ) noexcept; void AddRenderToSwapchainNode ( diff --git a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNode.cpp b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNode.cpp index 2f498d5a..fca003aa 100644 --- a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNode.cpp +++ b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNode.cpp @@ -365,6 +365,7 @@ namespace SHADE , spDeps{ std::move(rhs.spDeps) } , nodeComputes{ std::move(rhs.nodeComputes) } , name { std::move(rhs.name) } + , ISelfHandle{std::move(rhs)} { rhs.renderpass = {}; diff --git a/SHADE_Engine/src/Graphics/RenderGraph/SHSubpass.cpp b/SHADE_Engine/src/Graphics/RenderGraph/SHSubpass.cpp index e1277953..c4d645db 100644 --- a/SHADE_Engine/src/Graphics/RenderGraph/SHSubpass.cpp +++ b/SHADE_Engine/src/Graphics/RenderGraph/SHSubpass.cpp @@ -77,6 +77,7 @@ namespace SHADE , name { rhs.name } , viewport {rhs.viewport} , renderer {rhs.renderer} + , companionSubpass {rhs.companionSubpass} { } @@ -113,6 +114,7 @@ namespace SHADE name = std::move(rhs.name); renderer = rhs.renderer; viewport = rhs.viewport; + companionSubpass = rhs.companionSubpass; return *this; @@ -237,6 +239,7 @@ namespace SHADE } else { + // if not bind pipeline for companion and and execute draw command commandBuffer->BindPipeline(companionSubpass.pipeline); companionSubpass.companion->superBatch->Draw(commandBuffer, frameIndex, false); } From 8bb406e17febb512748f8c608c852e2138665d4d Mon Sep 17 00:00:00 2001 From: Brandon Mak Date: Sat, 7 Jan 2023 15:27:08 +0800 Subject: [PATCH 10/45] Shadows WIP - new subpass generated for shadow maps now use light's renderer - Added support to pass in custom binding and location for vertex attributes - SHLightingSubSystem GetViewMatrix uses SHMatrix::LookAtLH but with hard-coded values for now. This will eventually be replaced with real position and target values - Created new shadow map rendering vertex input state. --- SHADE_Engine/src/Camera/SHCameraSystem.cpp | 8 ++++++-- .../MiddleEnd/GlobalData/SHGraphicsPredefinedData.cpp | 2 +- .../src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp | 2 +- .../src/Graphics/MiddleEnd/Lights/SHLightingSubSystem.cpp | 4 ++-- SHADE_Engine/src/Graphics/Pipeline/SHPipelineState.cpp | 6 +++--- SHADE_Engine/src/Graphics/Pipeline/SHPipelineState.h | 2 +- 6 files changed, 14 insertions(+), 10 deletions(-) diff --git a/SHADE_Engine/src/Camera/SHCameraSystem.cpp b/SHADE_Engine/src/Camera/SHCameraSystem.cpp index 8ef7ff64..924100d4 100644 --- a/SHADE_Engine/src/Camera/SHCameraSystem.cpp +++ b/SHADE_Engine/src/Camera/SHCameraSystem.cpp @@ -270,8 +270,12 @@ namespace SHADE camera.viewMatrix(1, 3) = -UP.Dot(camera.position + camera.offset); camera.viewMatrix(2, 3) = -view.Dot(camera.position + camera.offset); - - + //SHVec3 target{ 0.0f,0.0f,-1.0f }; + //target = SHVec3::RotateX(target, SHMath::DegreesToRadians(camera.pitch)); + //target = SHVec3::RotateY(target, SHMath::DegreesToRadians(camera.yaw)); + //target += camera.position; + + //camera.viewMatrix = SHMatrix::Transpose(SHMatrix::LookAtLH(camera.position, target, SHVec3(0.0f, -1.0f, 0.0f))); camera.dirtyView = false; } diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/GlobalData/SHGraphicsPredefinedData.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/GlobalData/SHGraphicsPredefinedData.cpp index 4082ba0f..ca68c709 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/GlobalData/SHGraphicsPredefinedData.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/GlobalData/SHGraphicsPredefinedData.cpp @@ -205,7 +205,7 @@ namespace SHADE defaultVertexInputState.AddBinding(true, true, { SHVertexAttribute(SHAttribFormat::UINT32_2D) }); // Instanced integer data at index 8 shadowMapVertexInputState.AddBinding(false, false, { SHVertexAttribute(SHAttribFormat::FLOAT_3D)}); - shadowMapVertexInputState.AddBinding(true, true, { SHVertexAttribute(SHAttribFormat::MAT_4D) }, 4); // Transform at binding 4 - 7 (4 slots) + shadowMapVertexInputState.AddBinding(true, true, { SHVertexAttribute(SHAttribFormat::MAT_4D) }, 4, 4); // Transform at binding 4 - 7 (4 slots) } void SHGraphicsPredefinedData::Init(Handle logicalDevice) noexcept diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp index e682e0a1..81d8b88e 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp @@ -776,7 +776,7 @@ namespace SHADE auto shadowMapNode = renderGraph->AddNodeAfter(SHGraphicsConstants::RenderGraphNodeNames::SHADOW_MAP_PASS.data() + resourceName, {resourceName.c_str()}, SHGraphicsConstants::RenderGraphNodeNames::GBUFFER_PASS.data()); // Add a subpass to render to that shadow map - auto newSubpass = shadowMapNode->RuntimeAddSubpass(resourceName + " Subpass", worldViewport, worldRenderer); + auto newSubpass = shadowMapNode->RuntimeAddSubpass(resourceName + " Subpass", worldViewport, lightComp->GetRenderer()); //auto newSubpass = shadowMapNode->RuntimeAddSubpass(resourceName + " Subpass", worldViewport, lightComp->GetRenderer()); newSubpass->AddDepthOutput(resourceName, SH_RENDER_GRAPH_RESOURCE_FLAGS::DEPTH_STENCIL); diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightingSubSystem.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightingSubSystem.cpp index 17cffe17..e16242cb 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightingSubSystem.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightingSubSystem.cpp @@ -381,7 +381,7 @@ namespace SHADE switch (lightComp->GetLightData().type) { case SH_LIGHT_TYPE::DIRECTIONAL: - return SHMatrix::LookAtRH(lightComp->GetLightData().position, lightComp->GetLightData().position + lightComp->GetLightData().direction, SHVec3(0.0f, 1.0f, 0.0f)); + return SHMatrix::Transpose (SHMatrix::LookAtLH(/*lightComp->GetLightData().position*/SHVec3(-0.7768f, 3.82611f, 9.23839f), SHVec3(-0.7619f, 3.30361f, 8.38588f), SHVec3(0.0f, -1.0f, 0.0f))); case SH_LIGHT_TYPE::POINT: return {}; case SH_LIGHT_TYPE::SPOT: @@ -525,7 +525,7 @@ namespace SHADE if (auto renderer = light.GetRenderer()) { //SHMatrix orthoMatrix = SHMatrix::OrthographicRH() - renderer->UpdateDataManual (frameIndex, GetViewMatrix(&light), SHMatrix::OrthographicRH(80.0f, 80.0f, 0.01f, 10000.0f)); + renderer->UpdateDataManual (frameIndex, GetViewMatrix(&light), SHMatrix::OrthographicLH(12.0f, 12.0f, 0.1f, 20.0f)); } } diff --git a/SHADE_Engine/src/Graphics/Pipeline/SHPipelineState.cpp b/SHADE_Engine/src/Graphics/Pipeline/SHPipelineState.cpp index 49fa9086..30d81d89 100644 --- a/SHADE_Engine/src/Graphics/Pipeline/SHPipelineState.cpp +++ b/SHADE_Engine/src/Graphics/Pipeline/SHPipelineState.cpp @@ -195,7 +195,7 @@ namespace SHADE return *this; } - void SHVertexInputState::AddBinding(bool instanced, bool calcOffset, std::initializer_list inAttribs, uint32_t fixedAttributeLocation/* = static_cast(-1)*/) noexcept + void SHVertexInputState::AddBinding(bool instanced, bool calcOffset, std::initializer_list inAttribs, uint32_t fixedBinding /*= static_cast(-1)*/, uint32_t fixedAttributeLocation/* = static_cast(-1)*/) noexcept { // add a binding and get ref to it bindings.emplace_back(); @@ -210,7 +210,7 @@ namespace SHADE // Offset is 0 at first (for first element) uint32_t offset = 0; - binding.binding = static_cast(bindings.size() - 1); + binding.binding = (fixedBinding != static_cast(-1)) ? fixedBinding : static_cast(bindings.size() - 1); // for every attribute passed in for (auto const& attrib : inAttribs) @@ -226,7 +226,7 @@ namespace SHADE auto& vertexAttrib = attributes.back(); // The binding for that attribute description is index of the new binding created earlier in this function - vertexAttrib.binding = static_cast(bindings.size() - 1); + vertexAttrib.binding = (fixedBinding != static_cast(-1)) ? fixedBinding : static_cast(bindings.size() - 1); //Attribute location. New index is simply + 1 of the previous. Starts from 0 obviously vertexAttrib.location = (fixedAttributeLocation != static_cast(-1)) ? fixedAttributeLocation + i : static_cast(attributes.size () - 1); diff --git a/SHADE_Engine/src/Graphics/Pipeline/SHPipelineState.h b/SHADE_Engine/src/Graphics/Pipeline/SHPipelineState.h index 380c726e..73eb1ef5 100644 --- a/SHADE_Engine/src/Graphics/Pipeline/SHPipelineState.h +++ b/SHADE_Engine/src/Graphics/Pipeline/SHPipelineState.h @@ -34,7 +34,7 @@ namespace SHADE SHVertexInputState& operator= (SHVertexInputState const& rhs) noexcept; SHVertexInputState& operator= (SHVertexInputState&& rhs) noexcept; - void AddBinding(bool instanced, bool calcOffset, std::initializer_list inAttribs, uint32_t fixedAttributeLocation = static_cast(-1)) noexcept; + void AddBinding(bool instanced, bool calcOffset, std::initializer_list inAttribs, uint32_t fixedBinding = static_cast(-1), uint32_t fixedAttributeLocation = static_cast(-1)) noexcept; friend class SHVkPipelineState; friend class SHVkPipeline; From c3582cf5eed1bcc68c50268024ed1209e8f203f5 Mon Sep 17 00:00:00 2001 From: Diren D Bharwani Date: Sat, 7 Jan 2023 16:14:55 +0800 Subject: [PATCH 11/45] Added a rotate method with quaternions for Vector3 --- SHADE_Engine/src/Math/Transform/SHTransform.cpp | 12 +++++++++++- SHADE_Managed/src/Math/Vector3.cxx | 4 ++++ SHADE_Managed/src/Math/Vector3.hxx | 17 +++++++++++++++-- 3 files changed, 30 insertions(+), 3 deletions(-) diff --git a/SHADE_Engine/src/Math/Transform/SHTransform.cpp b/SHADE_Engine/src/Math/Transform/SHTransform.cpp index ef7c5fda..7be2a60c 100644 --- a/SHADE_Engine/src/Math/Transform/SHTransform.cpp +++ b/SHADE_Engine/src/Math/Transform/SHTransform.cpp @@ -35,7 +35,17 @@ namespace SHADE : position { pos } , orientation { SHQuaternion::FromEuler(rot) } , scale { scl } - {} + { + ComputeTRS(); + } + + SHTransform::SHTransform(const SHVec3& pos, const SHQuaternion& quat, const SHVec3& scl) noexcept + : position { pos } + , orientation { quat } + , scale { scl } + { + ComputeTRS(); + } /*-----------------------------------------------------------------------------------*/ /* Operator Overload Definitions */ diff --git a/SHADE_Managed/src/Math/Vector3.cxx b/SHADE_Managed/src/Math/Vector3.cxx index d2862ac7..647174a2 100644 --- a/SHADE_Managed/src/Math/Vector3.cxx +++ b/SHADE_Managed/src/Math/Vector3.cxx @@ -167,6 +167,10 @@ namespace SHADE { return Convert::ToCLI(SHVec3::Rotate(Convert::ToNative(vec), Convert::ToNative(axis), radians)); } + Vector3 Vector3::Rotate(Vector3 vec, Quaternion quat) + { + return Convert::ToCLI(SHVec3::Rotate(Convert::ToNative(vec), Convert::ToNative(quat))); + } Vector3 Vector3::Min(Vector3 lhs, Vector3 rhs) { float lx = lhs.x, rx = rhs.x; diff --git a/SHADE_Managed/src/Math/Vector3.hxx b/SHADE_Managed/src/Math/Vector3.hxx index 76b11420..31a373ba 100644 --- a/SHADE_Managed/src/Math/Vector3.hxx +++ b/SHADE_Managed/src/Math/Vector3.hxx @@ -19,10 +19,17 @@ of DigiPen Institute of Technology is prohibited. // Project Includes #include "Vector2.hxx" -value struct Quaternion; - namespace SHADE { + /*---------------------------------------------------------------------------------*/ + /* Forward Declarations */ + /*-------------------------------------------------------------------------- --- */ + value struct Quaternion; + + /*---------------------------------------------------------------------------------*/ + /* Type Definitions */ + /*-------------------------------------------------------------------------- --- */ + /// /// CLR version of SHADE Engine's Vector3 class that represents a 3-Dimensional Vector. /// Designed to closely match Unity's Vector3 struct. @@ -308,6 +315,12 @@ namespace SHADE /// The Vector3 that represents the rotated vector. static Vector3 Rotate(Vector3 vec, Vector3 axis, float radians); /// + /// Rotates a Vector3 using a Quaternion. + /// + /// A Vector3 to rotate. + /// A Quaternion to rotate the vector with. + static Vector3 Rotate(Vector3 vec, Quaternion quat); + /// /// Computes and returns a Vector3 that is made from the smallest components of /// the two specified Vector3s. /// From 222bda9a13436cfc71a0fbd8f7043fb5ee4ec686 Mon Sep 17 00:00:00 2001 From: Diren D Bharwani Date: Sat, 7 Jan 2023 16:16:35 +0800 Subject: [PATCH 12/45] Replaced Transform's Forward.get with new rotate method --- SHADE_Managed/src/Components/Transform.cxx | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/SHADE_Managed/src/Components/Transform.cxx b/SHADE_Managed/src/Components/Transform.cxx index bc61eff3..d5b38967 100644 --- a/SHADE_Managed/src/Components/Transform.cxx +++ b/SHADE_Managed/src/Components/Transform.cxx @@ -107,8 +107,7 @@ namespace SHADE Vector3 Transform::Forward::get() { - const SHVec3 DIRECTION = SHVec3::Rotate(-SHVec3::UnitZ, Convert::ToNative(GlobalRotation)); - return Convert::ToCLI(DIRECTION); + return Vector3::Rotate(Vector3::Forward, GlobalRotation); } /*-----------------------------------------------------------------------------------*/ From 77a5829fc914eeac5bd5f44e1d2decca1a8cef77 Mon Sep 17 00:00:00 2001 From: Brandon Mak Date: Sat, 7 Jan 2023 17:45:49 +0800 Subject: [PATCH 13/45] Shadows WIP --- Assets/Application.SHConfig | 2 +- Assets/Shaders/DeferredComposite_CS.glsl | 3 +++ Assets/Shaders/DeferredComposite_CS.shshaderb | Bin 5501 -> 5749 bytes .../GlobalData/SHGraphicsPredefinedData.cpp | 2 +- .../GlobalData/SHPredefinedDescriptorTypes.h | 2 +- .../MiddleEnd/Interface/SHGraphicsSystem.cpp | 7 +++++-- .../MiddleEnd/Interface/SHRenderer.cpp | 5 +++++ .../Graphics/MiddleEnd/Interface/SHRenderer.h | 1 + .../MiddleEnd/Lights/SHLightingSubSystem.cpp | 19 ++++++++++-------- .../MiddleEnd/Lights/SHLightingSubSystem.h | 5 +++++ .../Graphics/Pipeline/SHVkPipelineLayout.cpp | 2 ++ 11 files changed, 35 insertions(+), 13 deletions(-) diff --git a/Assets/Application.SHConfig b/Assets/Application.SHConfig index 5673556d..370665d2 100644 --- a/Assets/Application.SHConfig +++ b/Assets/Application.SHConfig @@ -1,4 +1,4 @@ Start in Fullscreen: false -Starting Scene ID: 97158628 +Starting Scene ID: 86098106 Window Size: {x: 1920, y: 1080} Window Title: SHADE Engine \ No newline at end of file diff --git a/Assets/Shaders/DeferredComposite_CS.glsl b/Assets/Shaders/DeferredComposite_CS.glsl index 0a8085b1..e73ea9eb 100644 --- a/Assets/Shaders/DeferredComposite_CS.glsl +++ b/Assets/Shaders/DeferredComposite_CS.glsl @@ -6,6 +6,7 @@ struct DirectionalLightStruct uint isActive; uint cullingMask; vec4 diffuseColor; + mat4 pvMatrix; }; struct AmbientLightStruct @@ -24,6 +25,8 @@ layout(set = 3, binding = 3, r32ui) uniform uimage2D lightLayerData; layout(set = 3, binding = 4, r8) uniform image2D ssaoBlurredImage; layout(set = 3, binding = 5, rgba8) uniform image2D targetImage; +layout (set = 4, binding = 0) uniform sampler2D shadowMaps[]; // for textures (global) + layout(set = 1, binding = 0) uniform LightCounts { uint directionalLights; diff --git a/Assets/Shaders/DeferredComposite_CS.shshaderb b/Assets/Shaders/DeferredComposite_CS.shshaderb index cabce080c7257a3946de1cbe9f94d151884ade21..df956040e255167463b8ea8206fcc2b8074e10fb 100644 GIT binary patch literal 5749 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 JAEMj={TD+43N`=$ diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/GlobalData/SHGraphicsPredefinedData.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/GlobalData/SHGraphicsPredefinedData.cpp index ca68c709..d5f744fb 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/GlobalData/SHGraphicsPredefinedData.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/GlobalData/SHGraphicsPredefinedData.cpp @@ -158,7 +158,7 @@ namespace SHADE .Type = vk::DescriptorType::eCombinedImageSampler, .Stage = vk::ShaderStageFlagBits::eVertex | vk::ShaderStageFlagBits::eFragment | vk::ShaderStageFlagBits::eCompute, .BindPoint = SHGraphicsConstants::DescriptorSetBindings::IMAGE_AND_SAMPLERS_DATA, - .DescriptorCount = 200, // we can have up to 2000 textures for now + .DescriptorCount = 200, // we can have up to 200 textures for now .flags = vk::DescriptorBindingFlagBits::eVariableDescriptorCount, }; diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/GlobalData/SHPredefinedDescriptorTypes.h b/SHADE_Engine/src/Graphics/MiddleEnd/GlobalData/SHPredefinedDescriptorTypes.h index 931101f4..fc7f6a1b 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/GlobalData/SHPredefinedDescriptorTypes.h +++ b/SHADE_Engine/src/Graphics/MiddleEnd/GlobalData/SHPredefinedDescriptorTypes.h @@ -13,7 +13,7 @@ namespace SHADE CAMERA, MATERIALS, FONT, - RENDER_GRAPH_RESOURCE, RENDER_GRAPH_NODE_COMPUTE_RESOURCE, + RENDER_GRAPH_RESOURCE, }; } diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp index 81d8b88e..57c83e10 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp @@ -127,7 +127,10 @@ namespace SHADE SHFreetypeInstance::Init(); - SHAssetManager::CompileAsset("../../Assets/Shaders/ShadowMap_VS.glsl", false); + SHAssetManager::CompileAsset("../../Assets/Shaders/DeferredComposite_CS.glsl", false); + SHAssetManager::CompileAsset("../../Assets/Shaders/SSAO_CS.glsl", false); + SHAssetManager::CompileAsset("../../Assets/Shaders/SSAOBlur_CS.glsl", false); + SHAssetManager::CompileAsset("../../Assets/Shaders/PureCopy_CS.glsl", false); // Load Built In Shaders static constexpr AssetID VS_DEFAULT = 39210065; defaultVertShader = SHResourceManager::LoadOrGet(VS_DEFAULT); @@ -288,7 +291,7 @@ namespace SHADE /*-----------------------------------------------------------------------*/ /* DEFERRED COMPOSITE SUBPASS INIT */ /*-----------------------------------------------------------------------*/ - auto deferredCompositeCompute = deferredCompositeNode->AddNodeCompute("Deferred Composite", deferredCompositeShader, { "Position", "Normals", "Albedo", "Light Layer Indices", "SSAO Blur", "Scene" }); + auto deferredCompositeCompute = deferredCompositeNode->AddNodeCompute("Deferred Composite", deferredCompositeShader, { "Position", "Normals", "Albedo", "Light Layer Indices", "SSAO Blur", "Scene" }, {}/*SHGraphicsPredefinedData::GetPredefinedDescSetLayouts(SHGraphicsPredefinedData::PredefinedDescSetLayoutTypes::SHADOW)[0]*/); deferredCompositeCompute->AddPreComputeFunction([=](Handle cmdBuffer, uint32_t frameIndex) { lightingSubSystem->PrepareShadowMapsForRead(cmdBuffer); diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHRenderer.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHRenderer.cpp index f1d4dc7f..731489fb 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHRenderer.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHRenderer.cpp @@ -122,4 +122,9 @@ namespace SHADE return cameraDirector; } + SHShaderCameraData SHRenderer::GetCPUCameraData(void) const noexcept + { + return cpuCameraData; + } + } diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHRenderer.h b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHRenderer.h index a17ab1a9..867851ee 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHRenderer.h +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHRenderer.h @@ -93,6 +93,7 @@ namespace SHADE /* Setters and Getters */ /*-----------------------------------------------------------------------------*/ Handle GetCameraDirector (void) const noexcept; + SHShaderCameraData GetCPUCameraData (void) const noexcept; private: /*-----------------------------------------------------------------------------*/ diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightingSubSystem.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightingSubSystem.cpp index e16242cb..88dc0f48 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightingSubSystem.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightingSubSystem.cpp @@ -56,6 +56,11 @@ namespace SHADE //lightPtr->direction = lightData.direction; lightPtr->diffuseColor = lightData.color; lightPtr->active = lightComp->isActive; + + // write view projection matrix if renderer is available + auto lightRenderer = lightComp->GetRenderer(); + if (lightRenderer) + lightPtr->pvMatrix = lightRenderer->GetCPUCameraData().viewProjectionMatrix; break; } case SH_LIGHT_TYPE::POINT: @@ -499,6 +504,12 @@ namespace SHADE for (auto& light : lightComps) { + if (auto renderer = light.GetRenderer()) + { + //SHMatrix orthoMatrix = SHMatrix::OrthographicRH() + renderer->UpdateDataManual(frameIndex, GetViewMatrix(&light), SHMatrix::OrthographicLH(12.0f, 12.0f, 0.1f, 20.0f)); + } + auto enumValue = SHUtilities::ConvertEnum(light.GetLightData().type); // First we want to make sure the light is already bound to the system. if it @@ -520,14 +531,6 @@ namespace SHADE // Light is now updated in the container //light.ClearDirtyFlag(); } - - - if (auto renderer = light.GetRenderer()) - { - //SHMatrix orthoMatrix = SHMatrix::OrthographicRH() - renderer->UpdateDataManual (frameIndex, GetViewMatrix(&light), SHMatrix::OrthographicLH(12.0f, 12.0f, 0.1f, 20.0f)); - - } } // Write data to GPU diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightingSubSystem.h b/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightingSubSystem.h index 320c18b7..d1b9e003 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightingSubSystem.h +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightingSubSystem.h @@ -3,12 +3,14 @@ #include "Resource/SHHandle.h" #include "Math/Vector/SHVec3.h" #include "Math/Vector/SHVec4.h" +#include "Math/SHMatrix.h" #include "SHLightData.h" #include #include "Graphics/MiddleEnd/Interface/SHGraphicsConstants.h" #include "Graphics/RenderGraph/SHRenderGraphResource.h" #include "ECS_Base/SHECSMacros.h" + namespace SHADE { class SHVkLogicalDevice; @@ -39,6 +41,9 @@ namespace SHADE //! Diffuse color emitted by the light alignas (16) SHVec4 diffuseColor; + //! Matrix for world to projection from light's perspective + SHMatrix pvMatrix; + }; // Represents how the data will be interpreted in GPU. we want to copy to a container of these before passing to GPU. diff --git a/SHADE_Engine/src/Graphics/Pipeline/SHVkPipelineLayout.cpp b/SHADE_Engine/src/Graphics/Pipeline/SHVkPipelineLayout.cpp index 325b3f56..d9ff07dd 100644 --- a/SHADE_Engine/src/Graphics/Pipeline/SHVkPipelineLayout.cpp +++ b/SHADE_Engine/src/Graphics/Pipeline/SHVkPipelineLayout.cpp @@ -208,7 +208,9 @@ namespace SHADE newBinding.flags = vk::DescriptorBindingFlagBits::eVariableDescriptorCount; } else + { SHLOG_ERROR("Variable size binding is detected, but the binding is not the last binding of the set and is therefore invalid. "); + } } setsWithBindings[CURRENT_SET].emplace_back(newBinding); From 1a0edf30d7ea5e648c558bd99bc17a0ebc73c7d9 Mon Sep 17 00:00:00 2001 From: Brandon Mak Date: Sat, 7 Jan 2023 22:40:29 +0800 Subject: [PATCH 14/45] Will update commit message tomorrow. Fuck Vulkan. *KW in BG: DiReCtX* --- SHADE_Engine/src/Editor/SHEditor.cpp | 4 +- .../Descriptors/SHVkDescriptorSetGroup.cpp | 22 ++++++++ .../Descriptors/SHVkDescriptorSetGroup.h | 1 + .../Graphics/Devices/SHVkLogicalDevice.cpp | 1 + .../MiddleEnd/Interface/SHDebugDrawSystem.cpp | 4 +- .../MiddleEnd/Interface/SHGraphicsConstants.h | 15 ++++- .../MiddleEnd/Interface/SHGraphicsSystem.cpp | 42 ++++++++------ .../MiddleEnd/Lights/SHLightingSubSystem.cpp | 56 +++++++++++-------- .../MiddleEnd/Lights/SHLightingSubSystem.h | 10 +++- .../RenderGraph/SHRenderGraphNode.cpp | 15 ++++- .../Graphics/RenderGraph/SHRenderGraphNode.h | 3 +- .../RenderGraph/SHRenderGraphNodeCompute.cpp | 22 ++++---- .../RenderGraph/SHRenderGraphNodeCompute.h | 3 +- .../src/Graphics/RenderGraph/SHSubpass.cpp | 4 +- 14 files changed, 136 insertions(+), 66 deletions(-) diff --git a/SHADE_Engine/src/Editor/SHEditor.cpp b/SHADE_Engine/src/Editor/SHEditor.cpp index f3fe6b72..9e7ffcc6 100644 --- a/SHADE_Engine/src/Editor/SHEditor.cpp +++ b/SHADE_Engine/src/Editor/SHEditor.cpp @@ -502,7 +502,7 @@ namespace SHADE //auto const& renderers = gfxSystem->GetDefaultViewport()->GetRenderers(); auto renderGraph = gfxSystem->GetRenderGraph(); - auto renderPass = renderGraph->GetNode(SHGraphicsConstants::RenderGraphNodeNames::IMGUI_PASS.data())->GetRenderpass(); + auto renderPass = renderGraph->GetNode(SHGraphicsConstants::RenderGraphEntityNames::IMGUI_PASS.data())->GetRenderpass(); if(ImGui_ImplVulkan_Init(&initInfo, renderPass->GetVkRenderpass()) == false) { @@ -521,7 +521,7 @@ namespace SHADE ImGui_ImplVulkan_DestroyFontUploadObjects(); - renderGraph->GetNode(SHGraphicsConstants::RenderGraphNodeNames::IMGUI_PASS.data())->GetSubpass("ImGui Draw")->AddExteriorDrawCalls([](Handle cmd, Handle renderer, uint32_t frameIndex) + renderGraph->GetNode(SHGraphicsConstants::RenderGraphEntityNames::IMGUI_PASS.data())->GetSubpass("ImGui Draw")->AddExteriorDrawCalls([](Handle cmd, Handle renderer, uint32_t frameIndex) { cmd->BeginLabeledSegment("ImGui Draw"); ImGui_ImplVulkan_RenderDrawData(ImGui::GetDrawData(), cmd->GetVkCommandBuffer()); diff --git a/SHADE_Engine/src/Graphics/Descriptors/SHVkDescriptorSetGroup.cpp b/SHADE_Engine/src/Graphics/Descriptors/SHVkDescriptorSetGroup.cpp index 7c5c0e48..19ec721b 100644 --- a/SHADE_Engine/src/Graphics/Descriptors/SHVkDescriptorSetGroup.cpp +++ b/SHADE_Engine/src/Graphics/Descriptors/SHVkDescriptorSetGroup.cpp @@ -215,6 +215,28 @@ namespace SHADE } + void SHVkDescriptorSetGroup::UpdateDescriptorSetImage(uint32_t set, uint32_t binding, uint32_t descArrayIndex) noexcept + { + vk::WriteDescriptorSet writeDescSet{}; + + // Get binding + set hash + BindingAndSetHash bsHash = SHVkUtil::GenBindingSetHash(set, binding); + + // to index a write for a binding + uint32_t writeInfoIndex = updater.writeHashMap[bsHash]; + + // Initialize info for write + writeDescSet.descriptorType = layoutsUsed[set]->GetBindings()[binding].Type; + writeDescSet.dstArrayElement = descArrayIndex; + writeDescSet.dstSet = descSets[set]; + writeDescSet.dstBinding = binding; + + writeDescSet.pImageInfo = updater.writeInfos[writeInfoIndex].descImageInfos.data() + descArrayIndex; + writeDescSet.descriptorCount = 1u; + + device->UpdateDescriptorSet(writeDescSet); + } + void SHVkDescriptorSetGroup::UpdateDescriptorSetImages(uint32_t set, uint32_t binding) noexcept { vk::WriteDescriptorSet writeDescSet{}; diff --git a/SHADE_Engine/src/Graphics/Descriptors/SHVkDescriptorSetGroup.h b/SHADE_Engine/src/Graphics/Descriptors/SHVkDescriptorSetGroup.h index 4538b271..5b65174a 100644 --- a/SHADE_Engine/src/Graphics/Descriptors/SHVkDescriptorSetGroup.h +++ b/SHADE_Engine/src/Graphics/Descriptors/SHVkDescriptorSetGroup.h @@ -63,6 +63,7 @@ namespace SHADE /*-----------------------------------------------------------------------------*/ /* Public member functions */ /*-----------------------------------------------------------------------------*/ + void UpdateDescriptorSetImage (uint32_t set, uint32_t binding, uint32_t descArrayIndex) noexcept; void UpdateDescriptorSetImages(uint32_t set, uint32_t binding) noexcept; void UpdateDescriptorSetBuffer(uint32_t set, uint32_t binding) noexcept; diff --git a/SHADE_Engine/src/Graphics/Devices/SHVkLogicalDevice.cpp b/SHADE_Engine/src/Graphics/Devices/SHVkLogicalDevice.cpp index 6a6e385f..3e504fb5 100644 --- a/SHADE_Engine/src/Graphics/Devices/SHVkLogicalDevice.cpp +++ b/SHADE_Engine/src/Graphics/Devices/SHVkLogicalDevice.cpp @@ -191,6 +191,7 @@ namespace SHADE features.multiDrawIndirect = VK_TRUE; features.independentBlend = VK_TRUE; + // for wide lines features.wideLines = true; diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHDebugDrawSystem.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHDebugDrawSystem.cpp index fc701da3..a5bc4ccd 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHDebugDrawSystem.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHDebugDrawSystem.cpp @@ -101,7 +101,7 @@ namespace SHADE // Register function for subpass //auto const& RENDERERS = gfxSystem->GetDefaultViewport()->GetRenderers(); auto renderGraph = gfxSystem->GetRenderGraph(); - auto subPass = renderGraph->GetNode(SHGraphicsConstants::RenderGraphNodeNames::DEBUG_DRAW.data())->GetSubpass("Debug Draw"); + auto subPass = renderGraph->GetNode(SHGraphicsConstants::RenderGraphEntityNames::DEBUG_DRAW.data())->GetSubpass("Debug Draw"); subPass->AddExteriorDrawCalls([this](Handle cmdBuffer, Handle renderer, uint32_t frameIndex) { const uint32_t FRAME_IDX = gfxSystem->GetCurrentFrameIndex(); @@ -125,7 +125,7 @@ namespace SHADE } cmdBuffer->EndLabeledSegment(); }); - auto subPassWithDepth = renderGraph->GetNode(SHGraphicsConstants::RenderGraphNodeNames::DEBUG_DRAW_DEPTH_PASS.data())->GetSubpass("Debug Draw with Depth"); + auto subPassWithDepth = renderGraph->GetNode(SHGraphicsConstants::RenderGraphEntityNames::DEBUG_DRAW_DEPTH_PASS.data())->GetSubpass("Debug Draw with Depth"); subPassWithDepth->AddExteriorDrawCalls([this](Handle cmdBuffer, Handle renderer, uint32_t frameIndex) { const uint32_t FRAME_IDX = gfxSystem->GetCurrentFrameIndex(); diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsConstants.h b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsConstants.h index b061dde3..b3945689 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsConstants.h +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsConstants.h @@ -31,7 +31,7 @@ namespace SHADE static constexpr uint32_t EDITOR = 0; }; - struct RenderGraphNodeNames + struct RenderGraphEntityNames { /***************************************************************************/ /*! @@ -103,6 +103,18 @@ namespace SHADE /***************************************************************************/ static constexpr std::string_view IMGUI_PASS = "ImGui Pass"; + /***************************************************************************/ + /*! + + \brief + Name of deferred composite compute. + + */ + /***************************************************************************/ + static constexpr std::string_view DEFERRED_COMPOSITE_COMPUTE = "Deferred Composite"; + + + }; struct DescriptorSetBindings @@ -178,6 +190,7 @@ namespace SHADE /***************************************************************************/ static constexpr uint32_t SHADOW_MAP_IMAGE_SAMPLER_DATA = 0; + }; struct VertexBufferBindings diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp index 57c83e10..1fadc7b1 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp @@ -208,7 +208,7 @@ namespace SHADE /*-----------------------------------------------------------------------*/ /* MAIN NODE */ /*-----------------------------------------------------------------------*/ - auto gBufferNode = renderGraph->AddNode(SHGraphicsConstants::RenderGraphNodeNames::GBUFFER_PASS.data(), + auto gBufferNode = renderGraph->AddNode(SHGraphicsConstants::RenderGraphEntityNames::GBUFFER_PASS.data(), //auto gBufferNode = renderGraph->AddNode(SHGraphicsConstants::RenderGraphNodeNames::GBUFFER_PASS.data() { "Position", @@ -276,7 +276,7 @@ namespace SHADE /* DEFERRED COMPOSITE NODE */ /*-----------------------------------------------------------------------*/ // This pass will facilitate both lighting and shadows in 1 single pass. - auto deferredCompositeNode = renderGraph->AddNode(SHGraphicsConstants::RenderGraphNodeNames::DEFERRED_COMPOSITE_PASS.data(), + auto deferredCompositeNode = renderGraph->AddNode(SHGraphicsConstants::RenderGraphEntityNames::DEFERRED_COMPOSITE_PASS.data(), { "Position", "Light Layer Indices", @@ -285,13 +285,13 @@ namespace SHADE "Scene", "SSAO Blur" }, - { SHGraphicsConstants::RenderGraphNodeNames::GBUFFER_PASS .data()}); + { SHGraphicsConstants::RenderGraphEntityNames::GBUFFER_PASS .data()}); /*-----------------------------------------------------------------------*/ /* DEFERRED COMPOSITE SUBPASS INIT */ /*-----------------------------------------------------------------------*/ - auto deferredCompositeCompute = deferredCompositeNode->AddNodeCompute("Deferred Composite", deferredCompositeShader, { "Position", "Normals", "Albedo", "Light Layer Indices", "SSAO Blur", "Scene" }, {}/*SHGraphicsPredefinedData::GetPredefinedDescSetLayouts(SHGraphicsPredefinedData::PredefinedDescSetLayoutTypes::SHADOW)[0]*/); + auto deferredCompositeCompute = deferredCompositeNode->AddNodeCompute(SHGraphicsConstants::RenderGraphEntityNames::DEFERRED_COMPOSITE_COMPUTE.data(), deferredCompositeShader, {"Position", "Normals", "Albedo", "Light Layer Indices", "SSAO Blur", "Scene"}, {}, SHLightingSubSystem::MAX_SHADOWS); deferredCompositeCompute->AddPreComputeFunction([=](Handle cmdBuffer, uint32_t frameIndex) { lightingSubSystem->PrepareShadowMapsForRead(cmdBuffer); @@ -303,19 +303,19 @@ namespace SHADE /*-----------------------------------------------------------------------*/ // Set up Debug Draw Passes // - Depth Tested - auto debugDrawNodeDepth = renderGraph->AddNode(SHGraphicsConstants::RenderGraphNodeNames::DEBUG_DRAW_DEPTH_PASS.data(), {"Scene", "Depth Buffer"}, {SHGraphicsConstants::RenderGraphNodeNames::GBUFFER_PASS.data(), SHGraphicsConstants::RenderGraphNodeNames::DEFERRED_COMPOSITE_PASS.data()}); + auto debugDrawNodeDepth = renderGraph->AddNode(SHGraphicsConstants::RenderGraphEntityNames::DEBUG_DRAW_DEPTH_PASS.data(), {"Scene", "Depth Buffer"}, {SHGraphicsConstants::RenderGraphEntityNames::GBUFFER_PASS.data(), SHGraphicsConstants::RenderGraphEntityNames::DEFERRED_COMPOSITE_PASS.data()}); auto debugDrawDepthSubpass = debugDrawNodeDepth->AddSubpass("Debug Draw with Depth", worldViewport, worldRenderer); debugDrawDepthSubpass->AddColorOutput("Scene"); debugDrawDepthSubpass->AddDepthOutput("Depth Buffer"); // - No Depth Test - auto debugDrawNode = renderGraph->AddNode(SHGraphicsConstants::RenderGraphNodeNames::DEBUG_DRAW.data(), {"Scene"}, {SHGraphicsConstants::RenderGraphNodeNames::DEBUG_DRAW_DEPTH_PASS.data()}); + auto debugDrawNode = renderGraph->AddNode(SHGraphicsConstants::RenderGraphEntityNames::DEBUG_DRAW.data(), {"Scene"}, {SHGraphicsConstants::RenderGraphEntityNames::DEBUG_DRAW_DEPTH_PASS.data()}); auto debugDrawSubpass = debugDrawNode->AddSubpass("Debug Draw", worldViewport, worldRenderer); debugDrawSubpass->AddColorOutput("Scene"); /*-----------------------------------------------------------------------*/ /* SCREEN SPACE PASS */ /*-----------------------------------------------------------------------*/ - auto screenSpaceNode = renderGraph->AddNode(SHGraphicsConstants::RenderGraphNodeNames::SCREEN_SPACE_PASS.data(), {"Scene", "Entity ID"}, {SHGraphicsConstants::RenderGraphNodeNames::DEFERRED_COMPOSITE_PASS.data(), SHGraphicsConstants::RenderGraphNodeNames::GBUFFER_PASS.data(), SHGraphicsConstants::RenderGraphNodeNames::DEBUG_DRAW.data()}); + auto screenSpaceNode = renderGraph->AddNode(SHGraphicsConstants::RenderGraphEntityNames::SCREEN_SPACE_PASS.data(), {"Scene", "Entity ID"}, {SHGraphicsConstants::RenderGraphEntityNames::DEFERRED_COMPOSITE_PASS.data(), SHGraphicsConstants::RenderGraphEntityNames::GBUFFER_PASS.data(), SHGraphicsConstants::RenderGraphEntityNames::DEBUG_DRAW.data()}); auto uiSubpass = screenSpaceNode->AddSubpass("UI", worldViewport, screenRenderer); uiSubpass->AddColorOutput("Scene"); uiSubpass->AddColorOutput("Entity ID"); @@ -330,16 +330,16 @@ namespace SHADE #ifdef SHEDITOR { // Dummy Node to transition scene render graph resource - auto dummyNode = renderGraph->AddNode("Dummy Pass", { "Scene" }, { SHGraphicsConstants::RenderGraphNodeNames::SCREEN_SPACE_PASS .data()}); + auto dummyNode = renderGraph->AddNode("Dummy Pass", { "Scene" }, { SHGraphicsConstants::RenderGraphEntityNames::SCREEN_SPACE_PASS .data()}); auto dummySubpass = dummyNode->AddSubpass("Dummy Subpass", {}, {}); dummySubpass->AddInput("Scene"); - auto imGuiNode = renderGraph->AddNode(SHGraphicsConstants::RenderGraphNodeNames::IMGUI_PASS.data(), {"Present"}, {}); + auto imGuiNode = renderGraph->AddNode(SHGraphicsConstants::RenderGraphEntityNames::IMGUI_PASS.data(), {"Present"}, {}); auto imGuiSubpass = imGuiNode->AddSubpass("ImGui Draw", {}, {}); imGuiSubpass->AddColorOutput("Present"); } #else - renderGraph->AddRenderToSwapchainNode("Scene", "Present", { SHGraphicsConstants::RenderGraphNodeNames::SCREEN_SPACE_PASS .data()}, {renderToSwapchainVS, renderToSwapchainFS}); + renderGraph->AddRenderToSwapchainNode("Scene", "Present", { SHGraphicsConstants::RenderGraphEntityNames::SCREEN_SPACE_PASS .data()}, {renderToSwapchainVS, renderToSwapchainFS}); #endif @@ -417,7 +417,7 @@ namespace SHADE textRenderingSubSystem = resourceManager.Create(); // initialize the text renderer - auto uiNode = renderGraph->GetNode(SHGraphicsConstants::RenderGraphNodeNames::SCREEN_SPACE_PASS.data()); + auto uiNode = renderGraph->GetNode(SHGraphicsConstants::RenderGraphEntityNames::SCREEN_SPACE_PASS.data()); textRenderingSubSystem->Init(device, uiNode->GetRenderpass(), uiNode->GetSubpass("UI"), descPool, textVS, textFS); SHGlobalDescriptorSets::SetLightingSubSystem(lightingSubSystem); @@ -444,7 +444,7 @@ namespace SHADE defaultMaterial = AddMaterial ( defaultVertShader, defaultFragShader, - renderGraph->GetNode(SHGraphicsConstants::RenderGraphNodeNames::GBUFFER_PASS.data())->GetSubpass("G-Buffer Write") + renderGraph->GetNode(SHGraphicsConstants::RenderGraphEntityNames::GBUFFER_PASS.data())->GetSubpass("G-Buffer Write") ); defaultMaterial->SetProperty("data.textureIndex", defaultTexture->TextureArrayIndex); } @@ -762,7 +762,7 @@ namespace SHADE auto const& EVENT_DATA = reinterpret_cast*>(eventPtr.get())->data; auto* lightComp = SHComponentManager::GetComponent(EVENT_DATA->lightEntity); std::string resourceName = "ShadowMap " + std::to_string(EVENT_DATA->lightEntity); - Handle companionSubpass = renderGraph->GetNode(SHGraphicsConstants::RenderGraphNodeNames::GBUFFER_PASS.data())->GetSubpass("G-Buffer Write"); + Handle companionSubpass = renderGraph->GetNode(SHGraphicsConstants::RenderGraphEntityNames::GBUFFER_PASS.data())->GetSubpass("G-Buffer Write"); if (EVENT_DATA->generateRenderer) { @@ -772,16 +772,16 @@ namespace SHADE } // Add the shadow map resource to the graph - renderGraph->AddResource(resourceName, {SH_RENDER_GRAPH_RESOURCE_FLAGS::DEPTH_STENCIL, SH_RENDER_GRAPH_RESOURCE_FLAGS::INPUT}, resizeWidth, resizeHeight, vk::Format::eD24UnormS8Uint); + renderGraph->AddResource(resourceName, {SH_RENDER_GRAPH_RESOURCE_FLAGS::DEPTH, SH_RENDER_GRAPH_RESOURCE_FLAGS::INPUT}, resizeWidth, resizeHeight, vk::Format::eD32Sfloat); // link resource to node. This means linking the resource and regenerating the node's renderpass and framebuffer. //auto shadowMapNode = renderGraph->GetNode(SHGraphicsConstants::RenderGraphNodeNames::SHADOW_MAP_PASS.data()); - auto shadowMapNode = renderGraph->AddNodeAfter(SHGraphicsConstants::RenderGraphNodeNames::SHADOW_MAP_PASS.data() + resourceName, {resourceName.c_str()}, SHGraphicsConstants::RenderGraphNodeNames::GBUFFER_PASS.data()); + auto shadowMapNode = renderGraph->AddNodeAfter(SHGraphicsConstants::RenderGraphEntityNames::SHADOW_MAP_PASS.data() + resourceName, {resourceName.c_str()}, SHGraphicsConstants::RenderGraphEntityNames::GBUFFER_PASS.data()); // Add a subpass to render to that shadow map auto newSubpass = shadowMapNode->RuntimeAddSubpass(resourceName + " Subpass", worldViewport, lightComp->GetRenderer()); //auto newSubpass = shadowMapNode->RuntimeAddSubpass(resourceName + " Subpass", worldViewport, lightComp->GetRenderer()); - newSubpass->AddDepthOutput(resourceName, SH_RENDER_GRAPH_RESOURCE_FLAGS::DEPTH_STENCIL); + newSubpass->AddDepthOutput(resourceName, SH_RENDER_GRAPH_RESOURCE_FLAGS::DEPTH); // regenerate the node shadowMapNode->RuntimeStandaloneRegenerate(); @@ -791,7 +791,7 @@ namespace SHADE if (!shadowMapPipeline) { SHPipelineLibrary tempLibrary{}; - Handle rgNode = renderGraph->GetNode(SHGraphicsConstants::RenderGraphNodeNames::SHADOW_MAP_PASS.data()); + Handle rgNode = renderGraph->GetNode(SHGraphicsConstants::RenderGraphEntityNames::SHADOW_MAP_PASS.data()); tempLibrary.Init(device); tempLibrary.CreateGraphicsPipelines({ shadowMapVS, {} }, shadowMapNode->GetRenderpass(), newSubpass, SHGraphicsPredefinedData::GetShadowMapViState()); @@ -799,6 +799,12 @@ namespace SHADE } newSubpass->SetCompanionSubpass(companionSubpass, shadowMapPipeline); // set companion subpass and pipeline + // add the shadow map to the lighting system + uint32_t const NEW_SHADOW_MAP_INDEX = lightingSubSystem->AddShadowMap(renderGraph->GetRenderGraphResource(resourceName), EVENT_DATA->lightEntity); + + auto nodeCompute = renderGraph->GetNode(SHGraphicsConstants::RenderGraphEntityNames::DEFERRED_COMPOSITE_PASS.data())->GetNodeCompute(SHGraphicsConstants::RenderGraphEntityNames::DEFERRED_COMPOSITE_COMPUTE.data()); + nodeCompute->ModifyWriteDescImageComputeResource(SHGraphicsConstants::DescriptorSetBindings::SHADOW_MAP_IMAGE_SAMPLER_DATA, lightingSubSystem->GetViewSamplerLayout(NEW_SHADOW_MAP_INDEX), NEW_SHADOW_MAP_INDEX); + return eventPtr->handle; } @@ -1142,7 +1148,7 @@ namespace SHADE Handle SHGraphicsSystem::GetPrimaryRenderpass() const noexcept { - return renderGraph->GetNode(SHGraphicsConstants::RenderGraphNodeNames::GBUFFER_PASS.data()); + return renderGraph->GetNode(SHGraphicsConstants::RenderGraphEntityNames::GBUFFER_PASS.data()); } Handle SHGraphicsSystem::GetDebugDrawPipeline(DebugDrawPipelineType type) const noexcept diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightingSubSystem.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightingSubSystem.cpp index 88dc0f48..8a2fb3e3 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightingSubSystem.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightingSubSystem.cpp @@ -459,14 +459,14 @@ namespace SHADE #pragma endregion #pragma region SHADOWS - std::vector shadowDescVariableSizes{ MAX_SHADOWS }; - shadowMapDescriptorSet = descPool->Allocate({SHGraphicsPredefinedData::GetPredefinedDescSetLayouts(SHGraphicsPredefinedData::PredefinedDescSetLayoutTypes::SHADOW)}, shadowDescVariableSizes); + //std::vector shadowDescVariableSizes{ MAX_SHADOWS }; + //shadowMapDescriptorSet = descPool->Allocate({SHGraphicsPredefinedData::GetPredefinedDescSetLayouts(SHGraphicsPredefinedData::PredefinedDescSetLayoutTypes::SHADOW)}, shadowDescVariableSizes); -#ifdef _DEBUG - const auto& SHADOW_MAP_DESC_SETS = shadowMapDescriptorSet->GetVkHandle(); - for (int i = 0; i < static_cast(SHADOW_MAP_DESC_SETS.size()); ++i) - SET_VK_OBJ_NAME(logicalDevice, vk::ObjectType::eDescriptorSet, SHADOW_MAP_DESC_SETS[i], "[Descriptor Set] Shadow Map Data Frame #" + std::to_string(i)); -#endif +//#ifdef _DEBUG +// const auto& SHADOW_MAP_DESC_SETS = shadowMapDescriptorSet->GetVkHandle(); +// for (int i = 0; i < static_cast(SHADOW_MAP_DESC_SETS.size()); ++i) +// SET_VK_OBJ_NAME(logicalDevice, vk::ObjectType::eDescriptorSet, SHADOW_MAP_DESC_SETS[i], "[Descriptor Set] Shadow Map Data Frame #" + std::to_string(i)); +//#endif shadowMapSampler = inShadowMapSampler; //numLightComponents = 0; @@ -583,7 +583,7 @@ namespace SHADE } - void SHLightingSubSystem::AddShadowMap(Handle newShadowMap, EntityID lightEntity) noexcept + uint32_t SHLightingSubSystem::AddShadowMap(Handle newShadowMap, EntityID lightEntity) noexcept { // Add to container of shadow maps shadowMaps.emplace(lightEntity, newShadowMap); @@ -595,26 +595,28 @@ namespace SHADE shadowMapImageSamplers.emplace_back(NEW_IMAGE_VIEW, shadowMapSampler, vk::ImageLayout::eShaderReadOnlyOptimal); // Update descriptor set - static constexpr uint32_t SHADOW_MAP_DESC_SET_INDEX = 0; - uint32_t const SHADOW_MAP_DESC_ARRAY_INDEX = static_cast(shadowMapImageSamplers.size()) - 1u; - shadowMapDescriptorSet->ModifyWriteDescImage - ( - SHADOW_MAP_DESC_SET_INDEX, - SHGraphicsConstants::DescriptorSetBindings::SHADOW_MAP_IMAGE_SAMPLER_DATA, - shadowMapImageSamplers[SHADOW_MAP_DESC_ARRAY_INDEX], - SHADOW_MAP_DESC_ARRAY_INDEX - ); + //static constexpr uint32_t SHADOW_MAP_DESC_SET_INDEX = 0; + //uint32_t const SHADOW_MAP_DESC_ARRAY_INDEX = static_cast(shadowMapImageSamplers.size()) - 1u; + //shadowMapDescriptorSet->ModifyWriteDescImage + //( + // SHADOW_MAP_DESC_SET_INDEX, + // SHGraphicsConstants::DescriptorSetBindings::SHADOW_MAP_IMAGE_SAMPLER_DATA, + // shadowMapImageSamplers[SHADOW_MAP_DESC_ARRAY_INDEX], + // SHADOW_MAP_DESC_ARRAY_INDEX + //); - // TODO: Definitely can be optimized by writing a function that modifies a specific descriptor in the array - shadowMapDescriptorSet->UpdateDescriptorSetImages - ( - SHADOW_MAP_DESC_SET_INDEX, - SHGraphicsConstants::DescriptorSetBindings::SHADOW_MAP_IMAGE_SAMPLER_DATA - ); + //// TODO: Definitely can be optimized by writing a function that modifies a specific descriptor in the array + //shadowMapDescriptorSet->UpdateDescriptorSetImages + //( + // SHADOW_MAP_DESC_SET_INDEX, + // SHGraphicsConstants::DescriptorSetBindings::SHADOW_MAP_IMAGE_SAMPLER_DATA + //); // add to barriers shadowMapMemoryBarriers.push_back (vk::ImageMemoryBarrier { + .srcAccessMask = vk::AccessFlagBits::eDepthStencilAttachmentWrite, + .dstAccessMask = vk::AccessFlagBits::eShaderRead, .oldLayout = vk::ImageLayout::eDepthAttachmentOptimal, .newLayout = vk::ImageLayout::eShaderReadOnlyOptimal, .srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED, @@ -629,6 +631,9 @@ namespace SHADE .layerCount = 1, } }); + + // return new index of shadow map + return static_cast(shadowMapImageSamplers.size()) - 1u; } void SHLightingSubSystem::PrepareShadowMapsForRead(Handle cmdBuffer) noexcept @@ -642,4 +647,9 @@ namespace SHADE return lightingDataDescSet; } + std::tuple, Handle, vk::ImageLayout> const& SHLightingSubSystem::GetViewSamplerLayout(uint32_t index) const noexcept + { + return shadowMapImageSamplers[index]; + } + } diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightingSubSystem.h b/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightingSubSystem.h index d1b9e003..3cc5bac8 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightingSubSystem.h +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightingSubSystem.h @@ -70,11 +70,15 @@ namespace SHADE { public: using DynamicOffsetArray = std::array, static_cast(SHGraphicsConstants::NUM_FRAME_BUFFERS)>; + static constexpr uint32_t MAX_SHADOWS = 200; private: class PerTypeData { + public: + + private: /*-----------------------------------------------------------------------*/ /* STATIC MEMBER VARIABLES */ @@ -137,7 +141,6 @@ namespace SHADE /* STATIC MEMBER VARIABLES */ /*-----------------------------------------------------------------------*/ - static constexpr uint32_t MAX_SHADOWS = 200; //! logical device used for creation Handle logicalDevice; @@ -174,7 +177,7 @@ namespace SHADE //! Descriptor sets required to be given to the compute shader for shadow calculation. This will be a descriptor array. //! It will also be preallocated. - Handle shadowMapDescriptorSet; + //Handle shadowMapDescriptorSet; //! Combined image samplers for the texture descriptors std::vector, Handle, vk::ImageLayout>> shadowMapImageSamplers; @@ -205,7 +208,7 @@ namespace SHADE void Run (SHMatrix const& viewMat, uint32_t frameIndex) noexcept; void Exit (void) noexcept; void BindDescSet (Handle cmdBuffer, uint32_t setIndex, uint32_t frameIndex) noexcept; - void AddShadowMap (Handle newShadowMap, EntityID lightEntity) noexcept; + uint32_t AddShadowMap (Handle newShadowMap, EntityID lightEntity) noexcept; void PrepareShadowMapsForRead (Handle cmdBuffer) noexcept; //void RemoveShadowMap (uint32_t index) noexcept; @@ -213,6 +216,7 @@ namespace SHADE /* SETTERS AND GETTERS */ /*-----------------------------------------------------------------------*/ Handle GetLightDataDescriptorSet (void) const noexcept; + std::tuple, Handle, vk::ImageLayout> const& GetViewSamplerLayout (uint32_t index) const noexcept; }; } diff --git a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNode.cpp b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNode.cpp index fca003aa..ff540ce1 100644 --- a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNode.cpp +++ b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNode.cpp @@ -442,7 +442,7 @@ namespace SHADE return subpass; } - Handle SHRenderGraphNode::AddNodeCompute(std::string nodeName, Handle computeShaderModule, std::initializer_list resources, std::unordered_set&& dynamicBufferBindings, Handle customComputeLayout/* = {}*/, float numWorkGroupScale/* = 1.0f*/) noexcept + Handle SHRenderGraphNode::AddNodeCompute(std::string nodeName, Handle computeShaderModule, std::initializer_list resources, std::unordered_set&& dynamicBufferBindings, uint32_t variableDescCount/* = 0*/, float numWorkGroupScale/* = 1.0f*/) noexcept { // Look for the required resources in the graph std::vector> nodeComputeResources{}; @@ -458,7 +458,7 @@ namespace SHADE std::vector> temp (nodeComputeResources); // Create the subpass compute with the resources - auto nodeCompute = graphStorage->resourceHub->Create(std::move(nodeName), graphStorage, computeShaderModule, std::move(nodeComputeResources), std::move (dynamicBufferBindings), nodeComputes.empty(), customComputeLayout); + auto nodeCompute = graphStorage->resourceHub->Create(std::move(nodeName), graphStorage, computeShaderModule, std::move(nodeComputeResources), std::move (dynamicBufferBindings), nodeComputes.empty(), variableDescCount); nodeComputes.push_back(nodeCompute); for (auto& resource : temp) @@ -810,4 +810,15 @@ namespace SHADE return attResources; } + Handle SHRenderGraphNode::GetNodeCompute(std::string nodeComputeName) const noexcept + { + for (auto nc : nodeComputes) + { + if (nc->name == nodeComputeName) + return nc; + } + + return {}; + } + } \ No newline at end of file diff --git a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNode.h b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNode.h index 27fdaa19..b070b8fa 100644 --- a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNode.h +++ b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNode.h @@ -109,7 +109,7 @@ namespace SHADE /* PUBLIC MEMBER FUNCTIONS */ /*-----------------------------------------------------------------------*/ Handle AddSubpass(std::string subpassName, Handle viewport, Handle renderer) noexcept; - Handle AddNodeCompute(std::string nodeName, Handle computeShaderModule, std::initializer_list resources, std::unordered_set&& dynamicBufferBindings = {}, Handle customComputeLayout = {}, float numWorkGroupScale = 1.0f) noexcept; + Handle AddNodeCompute(std::string nodeName, Handle computeShaderModule, std::initializer_list resources, std::unordered_set&& dynamicBufferBindings = {}, uint32_t variableDescCount = 0, float numWorkGroupScale = 1.0f) noexcept; void Execute(Handle commandBuffer, Handle descPool, uint32_t frameIndex) noexcept; Handle GetOrCreatePipeline(std::pair, Handle> const& vsFsPair, Handle subpass) noexcept; @@ -127,6 +127,7 @@ namespace SHADE Handle GetSubpass(std::string_view subpassName) const noexcept; Handle GetResource (uint32_t resourceIndex) const noexcept; std::vector> const& GetResources (void) const noexcept; + Handle GetNodeCompute (std::string nodeComputeName) const noexcept; friend class SHRenderGraph; }; diff --git a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNodeCompute.cpp b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNodeCompute.cpp index 55f8a9c9..ef1b6b03 100644 --- a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNodeCompute.cpp +++ b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNodeCompute.cpp @@ -63,7 +63,7 @@ namespace SHADE } - SHRenderGraphNodeCompute::SHRenderGraphNodeCompute(std::string nodeName, Handle graphStorage, Handle computeShaderModule, std::vector>&& subpassComputeResources, std::unordered_set&& dynamicBufferBindings, bool followingEndRP, Handle customComputeLayout, float inNumWorkGroupScale/* = 1.0f*/) noexcept + SHRenderGraphNodeCompute::SHRenderGraphNodeCompute(std::string nodeName, Handle graphStorage, Handle computeShaderModule, std::vector>&& subpassComputeResources, std::unordered_set&& dynamicBufferBindings, bool followingEndRP, uint32_t variableDescCount, float inNumWorkGroupScale/* = 1.0f*/) noexcept : computePipeline{} , pipelineLayout{} , resources{} @@ -118,21 +118,11 @@ namespace SHADE if (layouts.size() == descMappings.at(SHPredefinedDescriptorTypes::RENDER_GRAPH_NODE_COMPUTE_RESOURCE) + 1) { Handle computeResourceLayout = {}; - uint32_t variableCounts = 0; - if (customComputeLayout) - { - // Just use the descriptor counts in bindings as the variable descriptor counts - auto const& bindings = customComputeLayout->GetBindings(); - variableCounts = bindings.back().DescriptorCount; - computeResourceLayout = customComputeLayout; - } - else computeResourceLayout = layouts[descMappings.at(SHPredefinedDescriptorTypes::RENDER_GRAPH_NODE_COMPUTE_RESOURCE)]; - // create compute resources computeResource = graphStorage->resourceHub->Create(); - computeResource->descSet = graphStorage->descriptorPool->Allocate({ computeResourceLayout }, {variableCounts}); + computeResource->descSet = graphStorage->descriptorPool->Allocate({ computeResourceLayout }, {variableDescCount}); #ifdef _DEBUG for (auto set : computeResource->descSet->GetVkHandle()) SET_VK_OBJ_NAME(graphStorage->logicalDevice, vk::ObjectType::eDescriptorSet, set, "[Descriptor Set] " + name + " Resources"); @@ -257,6 +247,14 @@ namespace SHADE } + void SHRenderGraphNodeCompute::ModifyWriteDescImageComputeResource(uint32_t binding, SHVkDescriptorSetGroup::viewSamplerLayout const& viewSamplerLayout, uint32_t descArrayIndex) noexcept + { + static constexpr uint32_t COMPUTE_RESOURCE_SET_INDEX = 0; + computeResource->descSet->ModifyWriteDescImage(COMPUTE_RESOURCE_SET_INDEX, binding, viewSamplerLayout, descArrayIndex); + computeResource->descSet->UpdateDescriptorSetImage(COMPUTE_RESOURCE_SET_INDEX, binding, descArrayIndex); + + } + void SHRenderGraphNodeCompute::AddPreComputeFunction(PreComputeFunction const& fn) noexcept { preComputeFunctions.push_back(fn); diff --git a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNodeCompute.h b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNodeCompute.h index 9352f1d9..83bc5d33 100644 --- a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNodeCompute.h +++ b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNodeCompute.h @@ -93,7 +93,7 @@ namespace SHADE void SetFollowingEndRenderpass (uint32_t flag) noexcept; public: - SHRenderGraphNodeCompute(std::string nodeName, Handle graphStorage, Handle computeShaderModule, std::vector>&& subpassComputeResources, std::unordered_set&& dynamicBufferBindings, bool followingEndRP, Handle customComputeLayout, float inNumWorkGroupScale = 1.0f) noexcept; + SHRenderGraphNodeCompute(std::string nodeName, Handle graphStorage, Handle computeShaderModule, std::vector>&& subpassComputeResources, std::unordered_set&& dynamicBufferBindings, bool followingEndRP, uint32_t variableDescCount, float inNumWorkGroupScale = 1.0f) noexcept; void Execute (Handle cmdBuffer, uint32_t frameIndex) noexcept; void HandleResize (void) noexcept; @@ -103,6 +103,7 @@ namespace SHADE void ModifyWriteDescBufferComputeResource (uint32_t binding, std::span> const& buffers, uint32_t offset, uint32_t range) noexcept; void ModifyWriteDescImageComputeResource(uint32_t binding, std::span const& viewSamplerLayouts) noexcept; + void ModifyWriteDescImageComputeResource(uint32_t binding, SHVkDescriptorSetGroup::viewSamplerLayout const& viewSamplerLayout, uint32_t descArrayIndex) noexcept; void AddPreComputeFunction (PreComputeFunction const& fn) noexcept; diff --git a/SHADE_Engine/src/Graphics/RenderGraph/SHSubpass.cpp b/SHADE_Engine/src/Graphics/RenderGraph/SHSubpass.cpp index c4d645db..5205b44d 100644 --- a/SHADE_Engine/src/Graphics/RenderGraph/SHSubpass.cpp +++ b/SHADE_Engine/src/Graphics/RenderGraph/SHSubpass.cpp @@ -164,7 +164,7 @@ namespace SHADE switch (attachmentDescriptionType) { case SH_RENDER_GRAPH_RESOURCE_FLAGS::DEPTH: - imageLayout = vk::ImageLayout::eDepthAttachmentOptimal; + imageLayout = vk::ImageLayout::eDepthStencilAttachmentOptimal; break; case SH_RENDER_GRAPH_RESOURCE_FLAGS::STENCIL: imageLayout = vk::ImageLayout::eStencilAttachmentOptimal; @@ -299,6 +299,8 @@ namespace SHADE if (inputReferences[i].attachment == attachmentIndex) return true; } + + return false; } bool SHSubpass::HasNoAttachments(void) const noexcept From 98bfbc1048fca2e11683ce8947c18d65fc5f561d Mon Sep 17 00:00:00 2001 From: Kah Wei Date: Sun, 8 Jan 2023 01:06:50 +0800 Subject: [PATCH 15/45] Added DrawWireCapsule for debug draw (doesn't support orientation changes yet) --- .../MiddleEnd/Interface/SHDebugDrawSystem.cpp | 58 ++++++++++++++++++ .../MiddleEnd/Interface/SHDebugDrawSystem.h | 23 ++++++++ .../MiddleEnd/Interface/SHGraphicsSystem.cpp | 2 + .../MiddleEnd/Interface/SHGraphicsSystem.h | 5 +- .../MiddleEnd/Meshes/SHPrimitiveGenerator.cpp | 59 +++++++++++++++++++ .../MiddleEnd/Meshes/SHPrimitiveGenerator.h | 41 +++++++++++++ SHADE_Engine/src/Tools/SHDebugDraw.cpp | 8 +++ SHADE_Engine/src/Tools/SHDebugDraw.h | 24 ++++++++ 8 files changed, 218 insertions(+), 2 deletions(-) diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHDebugDrawSystem.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHDebugDrawSystem.cpp index b57249de..fdd21fd4 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHDebugDrawSystem.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHDebugDrawSystem.cpp @@ -207,6 +207,11 @@ namespace SHADE drawSphere(getMeshBatch(true, depthTested), matrix, color); } + void SHDebugDrawSystem::DrawWireCapsule(const SHVec3& position, const SHQuaternion& rotation, float height, float radius, const SHColour& color, bool depthTested) + { + drawWireCapsule(getLineBatch(depthTested), getMeshBatch(false, depthTested), position, rotation, height, radius, color); + } + /*-----------------------------------------------------------------------------------*/ /* Persistent Draw Functions */ /*-----------------------------------------------------------------------------------*/ @@ -264,6 +269,12 @@ namespace SHADE markPersistentDrawsDirty(); } + void SHDebugDrawSystem::DrawPersistentWireCapsule(const SHVec3& position, const SHQuaternion& rotation, float height, float radius, const SHColour& color, bool depthTested) + { + drawWireCapsule(getPersistentLineBatch(depthTested), getPersistentMeshBatch(false, depthTested), position, rotation, height, radius, color); + markPersistentDrawsDirty(); + } + void SHDebugDrawSystem::ClearPersistentDraws() { for (auto& batch : persistentLineBatches) @@ -348,6 +359,53 @@ namespace SHADE ); } + void SHDebugDrawSystem::drawWireCapsule(LinesBatch& lineBatch, MeshBatch& meshBatch, const SHVec3& position, const SHQuaternion& rotation, float height, float radius, const SHColour& color) + { + // Get local axis vectors + const SHVec3 LOCAL_UP = SHVec3::Up; + const SHVec3 LOCAL_RIGHT = SHVec3::Right; + const SHVec3 LOCAL_FORWARD = SHVec3::Forward; + + // Rotate the circle + SHQuaternion circleOrientation = SHQuaternion::FromEuler(SHVec3(SHMath::DegreesToRadians(90.0), 0.0f, 0.0f)); + + // Compute top and bottom of the cylinder + const SHVec3 HALF_UP = LOCAL_UP * (height * 0.5f - radius); + const SHVec3 TOP_POS = position + HALF_UP; + const SHVec3 BOT_POS = position - HALF_UP; + + // Render circles + const SHVec3 CIRCLE_SCALE = SHVec3(radius * 2.0f, radius * 2.0, radius * 2.0); + drawCircle(meshBatch, SHMatrix::Transform(TOP_POS, circleOrientation, CIRCLE_SCALE), color); + drawCircle(meshBatch, SHMatrix::Transform(BOT_POS, circleOrientation, CIRCLE_SCALE), color); + + // Render connecting lines + drawLine(lineBatch, TOP_POS + LOCAL_RIGHT * radius, BOT_POS + LOCAL_RIGHT * radius, color); + drawLine(lineBatch, TOP_POS - LOCAL_RIGHT * radius, BOT_POS - LOCAL_RIGHT * radius, color); + drawLine(lineBatch, TOP_POS + LOCAL_FORWARD * radius, BOT_POS + LOCAL_FORWARD * radius, color); + drawLine(lineBatch, TOP_POS - LOCAL_FORWARD * radius, BOT_POS - LOCAL_FORWARD * radius, color); + + // Render caps + const SHVec3 RADIUS_SCALE = SHVec3(radius * 2.0, radius * 2.0f, radius * 2.0); + const SHMatrix TOP_CAP_MAT = SHMatrix::Transform(TOP_POS, rotation, RADIUS_SCALE); + drawMesh + ( + gfxSystem->GetMeshPrimitive(PrimitiveType::LineCapsuleCap), + meshBatch, TOP_CAP_MAT, color + ); + const SHMatrix BOT_CAP_MAT = SHMatrix::Transform + ( + BOT_POS, + rotation * SHQuaternion::FromEuler(SHVec3(SHMath::DegreesToRadians(180.0), 0.0f, 0.0f)), + RADIUS_SCALE + ); + drawMesh + ( + gfxSystem->GetMeshPrimitive(PrimitiveType::LineCapsuleCap), + meshBatch, BOT_CAP_MAT, color + ); + } + /*-----------------------------------------------------------------------------------*/ /* Helper Batch Functions - Lines */ /*-----------------------------------------------------------------------------------*/ diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHDebugDrawSystem.h b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHDebugDrawSystem.h index 2978d68e..3997b6df 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHDebugDrawSystem.h +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHDebugDrawSystem.h @@ -163,6 +163,17 @@ namespace SHADE /// Colour to draw with. /// Whether or not drawn object will be occluded. void DrawSphere(const SHMatrix& matrix, const SHColour& color = SHColour::WHITE, bool depthTested = false); + /// + /// Draws the outline of a capsule. + /// + /// Position of the wireframe capsule. + /// Rotation of the capsule. + /// Height of the overall capsule. + /// Radius of the capsule. + /// + /// Colour to draw with. + /// Whether or not drawn object will be occluded. + void DrawWireCapsule(const SHVec3& position, const SHQuaternion& rotation, float height, float radius, const SHColour& color = SHColour::WHITE, bool depthTested = false); /*---------------------------------------------------------------------------------*/ /* Persistent Draw Functions */ @@ -269,6 +280,17 @@ namespace SHADE /// Whether or not drawn object will be occluded. void DrawPersistentSphere(const SHMatrix& matrix, const SHColour& color = SHColour::WHITE, bool depthTested = false); /// + /// Draws a persistent outline of a capsule. + /// + /// Position of the wireframe capsule. + /// Rotation of the capsule. + /// Height of the overall capsule. + /// Radius of the capsule. + /// + /// Colour to draw with. + /// Whether or not drawn object will be occluded. + void DrawPersistentWireCapsule(const SHVec3& position, const SHQuaternion& rotation, float height, float radius, const SHColour& color = SHColour::WHITE, bool depthTested = false); + /// /// Clears any persistent drawn debug primitives. /// void ClearPersistentDraws(); @@ -386,6 +408,7 @@ namespace SHADE void drawCube(MeshBatch& batch, const SHMatrix& transformMatrix, const SHColour& color); void drawSphere(MeshBatch& batch, const SHMatrix& transformMatrix, const SHColour& color); void drawCircle(MeshBatch& batch, const SHMatrix& transformMatrix, const SHColour& color); + void drawWireCapsule(LinesBatch& lineBatch, MeshBatch& meshBatch, const SHVec3& position, const SHQuaternion& rotation, float height, float radius, const SHColour& color); /*---------------------------------------------------------------------------------*/ /* Helper Batch Functions - Lines */ diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp index b1256921..f3bcc8f7 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp @@ -419,6 +419,7 @@ namespace SHADE primitiveMeshes[static_cast(PrimitiveType::Sphere)] = SHPrimitiveGenerator::Sphere(meshLibrary); primitiveMeshes[static_cast(PrimitiveType::LineCube)] = SHPrimitiveGenerator::LineCube(meshLibrary); primitiveMeshes[static_cast(PrimitiveType::LineCircle)] = SHPrimitiveGenerator::LineCircle(meshLibrary); + primitiveMeshes[static_cast(PrimitiveType::LineCapsuleCap)] = SHPrimitiveGenerator::LineCapsuleCap(meshLibrary); BuildMeshBuffers(); // Create default materials @@ -819,6 +820,7 @@ namespace SHADE case PrimitiveType::Sphere: case PrimitiveType::LineCube: case PrimitiveType::LineCircle: + case PrimitiveType::LineCapsuleCap: return primitiveMeshes[static_cast(type)]; default: return {}; diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.h b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.h index 40148e05..707862f9 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.h +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.h @@ -72,9 +72,10 @@ namespace SHADE Cube, Sphere, LineCube, - LineCircle + LineCircle, + LineCapsuleCap }; - static constexpr int MAX_PRIMITIVE_TYPES = 4; + static constexpr int MAX_PRIMITIVE_TYPES = 5; enum class DebugDrawPipelineType { LineNoDepthTest, diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Meshes/SHPrimitiveGenerator.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Meshes/SHPrimitiveGenerator.cpp index 444a6630..d5a0073f 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Meshes/SHPrimitiveGenerator.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Meshes/SHPrimitiveGenerator.cpp @@ -29,6 +29,7 @@ namespace SHADE SHMeshData SHPrimitiveGenerator::sphereMesh; SHMeshData SHPrimitiveGenerator::lineCubeMesh; SHMeshData SHPrimitiveGenerator::lineCircleMesh; + SHMeshData SHPrimitiveGenerator::lineCapsuleCapMesh; /*-----------------------------------------------------------------------------------*/ /* Primitive Generation Functions */ @@ -392,6 +393,64 @@ namespace SHADE return addMeshDataTo(lineCircleMesh, gfxSystem); } + SHADE::SHMeshData SHPrimitiveGenerator::LineCapsuleCap() noexcept + { + SHMeshData mesh; + + // Have multiple semi-circles for the cap + static constexpr int SPLITS = 36; + static constexpr float ANGLE_INCREMENTS = (std::numbers::pi_v * 2.0f) / static_cast(SPLITS); + + /* X-Axis */ + // Generate points of the circle + for (int i = 0; i <= SPLITS / 2; ++i) + { + const float ANGLE = ANGLE_INCREMENTS * i; + mesh.VertexPositions.emplace_back(cos(ANGLE) * 0.5f, sin(ANGLE) * 0.5f, 0.0f); + } + + // Generate lines of the circle + for (int i = 1; i <= SPLITS / 2; ++i) + { + mesh.Indices.emplace_back(static_cast(i - 1)); + mesh.Indices.emplace_back(static_cast(i)); + } + + /* Z-Axis */ + // Generate points of the circle + for (int i = 0; i <= SPLITS / 2; ++i) + { + const float ANGLE = ANGLE_INCREMENTS * i; + mesh.VertexPositions.emplace_back(0.0f, sin(ANGLE) * 0.5f, cos(ANGLE) * 0.5f); + } + + // Generate lines of the circle + for (int i = 2 + SPLITS / 2; i <= SPLITS + 1; ++i) + { + mesh.Indices.emplace_back(static_cast(i - 1)); + mesh.Indices.emplace_back(static_cast(i)); + } + + mesh.VertexNormals.resize(mesh.VertexPositions.size()); + mesh.VertexTangents.resize(mesh.VertexPositions.size()); + mesh.VertexTexCoords.resize(mesh.VertexPositions.size()); + + return mesh; + } + Handle SHPrimitiveGenerator::LineCapsuleCap(SHMeshLibrary& meshLibrary) noexcept + { + if (lineCapsuleCapMesh.VertexPositions.empty()) + lineCapsuleCapMesh = LineCapsuleCap(); + + return addMeshDataTo(lineCapsuleCapMesh, meshLibrary); + } + Handle SHPrimitiveGenerator::LineCapsuleCap(SHGraphicsSystem& gfxSystem) noexcept + { + if (lineCapsuleCapMesh.VertexPositions.empty()) + lineCapsuleCapMesh = LineCapsuleCap(); + + return addMeshDataTo(lineCapsuleCapMesh, gfxSystem); + } /*-----------------------------------------------------------------------------------*/ /* Helper Functions */ /*-----------------------------------------------------------------------------------*/ diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Meshes/SHPrimitiveGenerator.h b/SHADE_Engine/src/Graphics/MiddleEnd/Meshes/SHPrimitiveGenerator.h index 9bcd2f3c..e8c7c3fb 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Meshes/SHPrimitiveGenerator.h +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Meshes/SHPrimitiveGenerator.h @@ -194,6 +194,46 @@ namespace SHADE */ /***********************************************************************************/ [[nodiscard]] static Handle LineCircle(SHGraphicsSystem& gfxSystem) noexcept; + /***********************************************************************************/ + /*! + \brief + Produces a circle that is comprised only of lines with no diagonal lines and + store the data in a SHMeshData object. + + \return + SHMeshData object containing vertex data for the line circle. + */ + /***********************************************************************************/ + [[nodiscard]] static SHMeshData LineCapsuleCap() noexcept; + /***********************************************************************************/ + /*! + \brief + Produces a line circle and constructs a SHMesh using the SHGraphicsSystem + provided. + + \param meshLibrary + Reference to the SHMeshLibrary to produce and store a line circle mesh in. + + \return + SHMesh object that points to the generated line circle mesh in the SHMeshLibrary. + */ + /***********************************************************************************/ + [[nodiscard]] static Handle LineCapsuleCap(SHMeshLibrary& meshLibrary) noexcept; + /***********************************************************************************/ + /*! + \brief + Produces a line circle and constructs a SHMesh using the SHGraphicsSystem + provided. + + \param gfxSystem + Reference to the SHGraphicsSystem to produce and store a line circle mesh in. + + \return + SHMesh object that points to the generated line circle mesh in the + SHGraphicsSystem. + */ + /***********************************************************************************/ + [[nodiscard]] static Handle LineCapsuleCap(SHGraphicsSystem& gfxSystem) noexcept; private: /*---------------------------------------------------------------------------------*/ @@ -209,5 +249,6 @@ namespace SHADE static SHMeshData sphereMesh; static SHMeshData lineCubeMesh; static SHMeshData lineCircleMesh; + static SHMeshData lineCapsuleCapMesh; }; } \ No newline at end of file diff --git a/SHADE_Engine/src/Tools/SHDebugDraw.cpp b/SHADE_Engine/src/Tools/SHDebugDraw.cpp index 02eca592..ee040d8b 100644 --- a/SHADE_Engine/src/Tools/SHDebugDraw.cpp +++ b/SHADE_Engine/src/Tools/SHDebugDraw.cpp @@ -128,6 +128,10 @@ namespace SHADE dbgDrawSys->DrawWireSphere(SHMatrix::Transform(center, SHQuaternion(), scale), color, depthTested); } + void SHDebugDraw::WireCapsule(const SHVec3& position, const SHQuaternion& rotation, float height, float radius, const SHColour& color, bool depthTested) + { + dbgDrawSys->DrawWireCapsule(position, rotation, height, radius, color, depthTested); + } /*-----------------------------------------------------------------------------------*/ /* Persistent Draw Functions */ /*-----------------------------------------------------------------------------------*/ @@ -216,6 +220,10 @@ namespace SHADE dbgDrawSys->DrawPersistentWireSphere(SHMatrix::Transform(center, SHQuaternion(), scale), color, depthTested); } + void SHDebugDraw::Persistent::WireCapsule(const SHVec3& position, const SHQuaternion& rotation, float height, float radius, const SHColour& color, bool depthTested) + { + dbgDrawSys->DrawPersistentWireCapsule(position, rotation, height, radius, color, depthTested); + } void SHDebugDraw::Persistent::ClearDraws() { dbgDrawSys->ClearPersistentDraws(); diff --git a/SHADE_Engine/src/Tools/SHDebugDraw.h b/SHADE_Engine/src/Tools/SHDebugDraw.h index c28b93e6..3d7bee2f 100644 --- a/SHADE_Engine/src/Tools/SHDebugDraw.h +++ b/SHADE_Engine/src/Tools/SHDebugDraw.h @@ -194,6 +194,18 @@ namespace SHADE /// Colour to draw with. /// Whether or not drawn object will be occluded. static void WireSphere(const SHVec3& center, const SHVec3& scale, const SHVec4& color = SHColour::WHITE, bool depthTested = false); + /// + /// Draws the outline of a capsule. + /// This will remain drawn until ClearDraws() is called. + /// + /// Position of the wireframe capsule. + /// Rotation of the capsule. + /// Height of the overall capsule. + /// Radius of the capsule. + /// + /// Colour to draw with. + /// Whether or not drawn object will be occluded. + void WireCapsule(const SHVec3& position, const SHQuaternion& rotation, float height, float radius, const SHColour& color = SHColour::WHITE, bool depthTested = false); /*---------------------------------------------------------------------------------*/ /* Persistent Draw Function Class "Folder" */ @@ -366,6 +378,18 @@ namespace SHADE /// Whether or not drawn object will be occluded. static void WireSphere(const SHVec3& center, const SHVec3& scale, const SHVec4& color = SHColour::WHITE, bool depthTested = false); /// + /// Draws the outline of a capsule. + /// This will remain drawn until ClearDraws() is called. + /// + /// Position of the wireframe capsule. + /// Rotation of the capsule. + /// Height of the overall capsule. + /// Radius of the capsule. + /// + /// Colour to draw with. + /// Whether or not drawn object will be occluded. + void WireCapsule(const SHVec3& position, const SHQuaternion& rotation, float height, float radius, const SHColour& color = SHColour::WHITE, bool depthTested = false); + /// /// Clears any persistent drawn debug primitives. /// static void ClearDraws(); From f44e7b7a1c2a17d41a0047049428192565463e6a Mon Sep 17 00:00:00 2001 From: Kah Wei Date: Sun, 8 Jan 2023 01:43:40 +0800 Subject: [PATCH 16/45] Debug draw capsule now works with different orientations --- .../Graphics/MiddleEnd/Interface/SHDebugDrawSystem.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHDebugDrawSystem.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHDebugDrawSystem.cpp index fdd21fd4..ae8c62b2 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHDebugDrawSystem.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHDebugDrawSystem.cpp @@ -362,12 +362,12 @@ namespace SHADE void SHDebugDrawSystem::drawWireCapsule(LinesBatch& lineBatch, MeshBatch& meshBatch, const SHVec3& position, const SHQuaternion& rotation, float height, float radius, const SHColour& color) { // Get local axis vectors - const SHVec3 LOCAL_UP = SHVec3::Up; - const SHVec3 LOCAL_RIGHT = SHVec3::Right; - const SHVec3 LOCAL_FORWARD = SHVec3::Forward; + const SHVec3 LOCAL_UP = SHVec3::Rotate(SHVec3::Up, rotation); + const SHVec3 LOCAL_RIGHT = SHVec3::Rotate(SHVec3::Right, rotation); + const SHVec3 LOCAL_FORWARD = SHVec3::Rotate(SHVec3::Forward, rotation); // Rotate the circle - SHQuaternion circleOrientation = SHQuaternion::FromEuler(SHVec3(SHMath::DegreesToRadians(90.0), 0.0f, 0.0f)); + SHQuaternion circleOrientation = SHQuaternion::FromEuler(SHVec3(SHMath::DegreesToRadians(90.0), 0.0f, 0.0f)) * rotation; // Compute top and bottom of the cylinder const SHVec3 HALF_UP = LOCAL_UP * (height * 0.5f - radius); @@ -396,7 +396,7 @@ namespace SHADE const SHMatrix BOT_CAP_MAT = SHMatrix::Transform ( BOT_POS, - rotation * SHQuaternion::FromEuler(SHVec3(SHMath::DegreesToRadians(180.0), 0.0f, 0.0f)), + SHQuaternion::FromEuler(SHVec3(SHMath::DegreesToRadians(180.0), 0.0f, 0.0f)) * rotation, RADIUS_SCALE ); drawMesh From 686e141efaad45351a836dd91e42a792b52055c2 Mon Sep 17 00:00:00 2001 From: Kah Wei Date: Sun, 8 Jan 2023 01:46:52 +0800 Subject: [PATCH 17/45] Fixed comment for SHPrimitiveGenerator::LineCapsuleCap --- .../Graphics/MiddleEnd/Meshes/SHPrimitiveGenerator.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Meshes/SHPrimitiveGenerator.h b/SHADE_Engine/src/Graphics/MiddleEnd/Meshes/SHPrimitiveGenerator.h index e8c7c3fb..839d0ef6 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Meshes/SHPrimitiveGenerator.h +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Meshes/SHPrimitiveGenerator.h @@ -197,7 +197,7 @@ namespace SHADE /***********************************************************************************/ /*! \brief - Produces a circle that is comprised only of lines with no diagonal lines and + Produces a cap of a wireframe capsule that is comprised only of lines and store the data in a SHMeshData object. \return @@ -208,8 +208,8 @@ namespace SHADE /***********************************************************************************/ /*! \brief - Produces a line circle and constructs a SHMesh using the SHGraphicsSystem - provided. + Produces a cap of a wireframe capsule that is comprised only of lines and + constructs a SHMesh using the SHGraphicsSystem provided. \param meshLibrary Reference to the SHMeshLibrary to produce and store a line circle mesh in. @@ -222,8 +222,8 @@ namespace SHADE /***********************************************************************************/ /*! \brief - Produces a line circle and constructs a SHMesh using the SHGraphicsSystem - provided. + Produces a cap of a wireframe capsule that is comprised only of lines and + constructs a SHMesh using the SHGraphicsSystem provided. \param gfxSystem Reference to the SHGraphicsSystem to produce and store a line circle mesh in. From baaeb9ee102d2b80b1b32d007f91d095cb5d0aaa Mon Sep 17 00:00:00 2001 From: mushgunAX Date: Sun, 8 Jan 2023 21:05:09 +0800 Subject: [PATCH 18/45] Input Binding File I/O --- Assets/Bindings.SHConfig | 52 +++++++ SHADE_Engine/src/Input/SHInputManager.cpp | 169 ++++++++++++++++++++++ SHADE_Engine/src/Input/SHInputManager.h | 11 ++ 3 files changed, 232 insertions(+) create mode 100644 Assets/Bindings.SHConfig diff --git a/Assets/Bindings.SHConfig b/Assets/Bindings.SHConfig new file mode 100644 index 00000000..e0023603 --- /dev/null +++ b/Assets/Bindings.SHConfig @@ -0,0 +1,52 @@ +4 +Horizontal +0 +0 +5 +0.2 +5 +0 +2 +39 +68 +2 +37 +65 +2 +3 +16 +1 +2 +Mouse Wheel +3 +0 +1 +0.2 +1 +0 +0 +0 +0 +0 +Mouse X +1 +0 +1 +0.2 +1 +0 +0 +0 +0 +0 +Mouse Y +2 +0 +1 +0.2 +1 +0 +0 +0 +0 +0 diff --git a/SHADE_Engine/src/Input/SHInputManager.cpp b/SHADE_Engine/src/Input/SHInputManager.cpp index cec78648..a94b66d4 100644 --- a/SHADE_Engine/src/Input/SHInputManager.cpp +++ b/SHADE_Engine/src/Input/SHInputManager.cpp @@ -11,6 +11,7 @@ #pragma once #include +#include #include "SHInputManager.h" #include "../Tools/SHException.h" @@ -99,6 +100,174 @@ namespace SHADE } } + //The Binding File format presently goes as such: + /* + * Name + Binding Type Enum + Inverted Bool + Gravity Double + Dead Double + Sensitivity Double + Snap Bool + PositiveKeyCode count + PositiveKeyCodes + NegativeKeyCode count + NegativeKeyCodes + PositiveControllerCode Count + PositiveControllerCodes + NegativeControllerCode Count + NegativeControllerCodes + */ + void SHInputManager::SaveBindings(std::string const& targetFile) noexcept + { + std::ofstream file; + file.open("../../Assets/Bindings.SHConfig"); + + //File cannot be written to + if (!file) return; + + //First write the number of bindings + file << bindings.size() << std::endl; + + for (auto& b : bindings) + { + //Name + file << b.first << std::endl; + + //Data + auto& lbd = b.second; + + file << static_cast(lbd.bindingType) << std::endl; + file << static_cast(lbd.inverted) << std::endl; + file << lbd.gravity << std::endl; + file << lbd.dead << std::endl; + file << lbd.sensitivity << std::endl; + file << static_cast(lbd.snap) << std::endl; + + //Bindings + file << lbd.positiveKeyCodes.size() << std::endl; + for (auto kc : lbd.positiveKeyCodes) + file << static_cast(kc) << std::endl; + file << lbd.negativeKeyCodes.size() << std::endl; + for (auto kc : lbd.negativeKeyCodes) + file << static_cast(kc) << std::endl; + file << lbd.positiveControllerCodes.size() << std::endl; + for (auto cc : lbd.positiveControllerCodes) + file << static_cast(cc) << std::endl; + file << lbd.negativeControllerCodes.size() << std::endl; + for (auto cc : lbd.negativeControllerCodes) + file << static_cast(cc) << std::endl; + } + + file.close(); + } + + void SHInputManager::LoadBindings(std::string const& sourceFile) noexcept + { + std::ifstream file; + file.open("../../Assets/Bindings.SHConfig"); + + //Check + if (!file) return; + + //Erase + ClearBindings(); + + //Read + std::string read; + + int count = 0; + std::getline(file, read); + count = std::stoi(read); + + std::string bindingName; + for (int b = 0; b < count; ++b) + { + //Name + std::getline(file, read); + SHLOGV_CRITICAL("Binding Name: {}", read); + bindingName = read; + AddBinding(bindingName); + + //Type + std::getline(file, read); + SHLOGV_CRITICAL("Binding Type: {}", read); + SetBindingType(bindingName, static_cast(std::stoi(read))); + + //Inversion + std::getline(file, read); + SHLOGV_CRITICAL("Inversion: {}", read); + SetBindingInverted(bindingName, static_cast(std::stoi(read))); + + //Gravity + std::getline(file, read); + SHLOGV_CRITICAL("Gravity: {}", read); + SetBindingGravity(bindingName, std::stod(read)); + + //Dead + std::getline(file, read); + SHLOGV_CRITICAL("Dead: {}", read); + SetBindingDead(bindingName, std::stod(read)); + + //Sensitivity + std::getline(file, read); + SHLOGV_CRITICAL("Sensitivity: {}", read); + SetBindingSensitivity(bindingName, std::stod(read)); + + //Snap + std::getline(file, read); + SHLOGV_CRITICAL("Snap: {}", read); + SetBindingSnap(bindingName, static_cast(std::stoi(read))); + + int count = 0; + //Positive Key Codes + std::getline(file, read); + SHLOGV_CRITICAL("Positive Key Count: {}", read); + count = std::stoi(read); + for (int i = 0; i < count; ++i) + { + std::getline(file, read); + SHLOGV_CRITICAL("Positive Key: {}", read); + AddBindingPositiveKeyCode(bindingName, static_cast(std::stoi(read))); + } + + //Negative Key Codes + std::getline(file, read); + SHLOGV_CRITICAL("Negative Key Count: {}", read); + count = std::stoi(read); + for (int i = 0; i < count; ++i) + { + std::getline(file, read); + SHLOGV_CRITICAL("Negative Key: {}", read); + AddBindingNegativeKeyCode(bindingName, static_cast(std::stoi(read))); + } + + //Positive Controller Codes + std::getline(file, read); + SHLOGV_CRITICAL("Positive Controller Count: {}", read); + count = std::stoi(read); + for (int i = 0; i < count; ++i) + { + std::getline(file, read); + SHLOGV_CRITICAL("Positive Controller: {}", read); + AddBindingPositiveControllerCode(bindingName, static_cast(std::stoi(read))); + } + + //Negative Controller Codes + std::getline(file, read); + SHLOGV_CRITICAL("Negative Controller Count: {}", read); + count = std::stoi(read); + for (int i = 0; i < count; ++i) + { + std::getline(file, read); + SHLOGV_CRITICAL("Negative Controller: {}", read); + AddBindingNegativeControllerCode(bindingName, static_cast(std::stoi(read))); + } + } + + file.close(); + } + void SHInputManager::UpdateInput(double dt) noexcept { //Keyboard and Mouse Buttons//////////////////////////////////////////////// diff --git a/SHADE_Engine/src/Input/SHInputManager.h b/SHADE_Engine/src/Input/SHInputManager.h index 3f708124..977a2d08 100644 --- a/SHADE_Engine/src/Input/SHInputManager.h +++ b/SHADE_Engine/src/Input/SHInputManager.h @@ -681,6 +681,17 @@ namespace SHADE return controllersReleasedTime[controllerNum][static_cast(code)]; } + /*------------------------------------------------------------------------*/ + /* Binding I/O */ + /*------------------------------------------------------------------------*/ + + //Save bindings registered into a file + static void SaveBindings(std::string const& targetFile = "Assets/InputBindings.SHConfig") noexcept; + + //Load and register bindings from a file + //The current list of bindings will be overwritten, so save them somewhere else before loading + static void LoadBindings(std::string const& sourceFile = "Assets/InputBindings.SHConfig") noexcept; + /*------------------------------------------------------------------------*/ /* Binding Functions */ /*------------------------------------------------------------------------*/ From 4123e76a7d991add7f03f57b2b6ba9512b5f92b0 Mon Sep 17 00:00:00 2001 From: mushgunAX Date: Sun, 8 Jan 2023 21:36:19 +0800 Subject: [PATCH 19/45] Checking Input Binding I/O --- SHADE_Engine/src/Input/SHInputManager.cpp | 21 ++++----------------- SHADE_Engine/src/Input/SHInputManager.h | 4 ++-- 2 files changed, 6 insertions(+), 19 deletions(-) diff --git a/SHADE_Engine/src/Input/SHInputManager.cpp b/SHADE_Engine/src/Input/SHInputManager.cpp index a94b66d4..b8f329b9 100644 --- a/SHADE_Engine/src/Input/SHInputManager.cpp +++ b/SHADE_Engine/src/Input/SHInputManager.cpp @@ -102,6 +102,8 @@ namespace SHADE //The Binding File format presently goes as such: /* + * Binding count + * (For each binding:) * Name Binding Type Enum Inverted Bool @@ -121,7 +123,7 @@ namespace SHADE void SHInputManager::SaveBindings(std::string const& targetFile) noexcept { std::ofstream file; - file.open("../../Assets/Bindings.SHConfig"); + file.open(targetFile); //File cannot be written to if (!file) return; @@ -165,7 +167,7 @@ namespace SHADE void SHInputManager::LoadBindings(std::string const& sourceFile) noexcept { std::ifstream file; - file.open("../../Assets/Bindings.SHConfig"); + file.open(sourceFile); //Check if (!file) return; @@ -185,82 +187,67 @@ namespace SHADE { //Name std::getline(file, read); - SHLOGV_CRITICAL("Binding Name: {}", read); bindingName = read; AddBinding(bindingName); //Type std::getline(file, read); - SHLOGV_CRITICAL("Binding Type: {}", read); SetBindingType(bindingName, static_cast(std::stoi(read))); //Inversion std::getline(file, read); - SHLOGV_CRITICAL("Inversion: {}", read); SetBindingInverted(bindingName, static_cast(std::stoi(read))); //Gravity std::getline(file, read); - SHLOGV_CRITICAL("Gravity: {}", read); SetBindingGravity(bindingName, std::stod(read)); //Dead std::getline(file, read); - SHLOGV_CRITICAL("Dead: {}", read); SetBindingDead(bindingName, std::stod(read)); //Sensitivity std::getline(file, read); - SHLOGV_CRITICAL("Sensitivity: {}", read); SetBindingSensitivity(bindingName, std::stod(read)); //Snap std::getline(file, read); - SHLOGV_CRITICAL("Snap: {}", read); SetBindingSnap(bindingName, static_cast(std::stoi(read))); int count = 0; //Positive Key Codes std::getline(file, read); - SHLOGV_CRITICAL("Positive Key Count: {}", read); count = std::stoi(read); for (int i = 0; i < count; ++i) { std::getline(file, read); - SHLOGV_CRITICAL("Positive Key: {}", read); AddBindingPositiveKeyCode(bindingName, static_cast(std::stoi(read))); } //Negative Key Codes std::getline(file, read); - SHLOGV_CRITICAL("Negative Key Count: {}", read); count = std::stoi(read); for (int i = 0; i < count; ++i) { std::getline(file, read); - SHLOGV_CRITICAL("Negative Key: {}", read); AddBindingNegativeKeyCode(bindingName, static_cast(std::stoi(read))); } //Positive Controller Codes std::getline(file, read); - SHLOGV_CRITICAL("Positive Controller Count: {}", read); count = std::stoi(read); for (int i = 0; i < count; ++i) { std::getline(file, read); - SHLOGV_CRITICAL("Positive Controller: {}", read); AddBindingPositiveControllerCode(bindingName, static_cast(std::stoi(read))); } //Negative Controller Codes std::getline(file, read); - SHLOGV_CRITICAL("Negative Controller Count: {}", read); count = std::stoi(read); for (int i = 0; i < count; ++i) { std::getline(file, read); - SHLOGV_CRITICAL("Negative Controller: {}", read); AddBindingNegativeControllerCode(bindingName, static_cast(std::stoi(read))); } } diff --git a/SHADE_Engine/src/Input/SHInputManager.h b/SHADE_Engine/src/Input/SHInputManager.h index 977a2d08..01ef6c42 100644 --- a/SHADE_Engine/src/Input/SHInputManager.h +++ b/SHADE_Engine/src/Input/SHInputManager.h @@ -686,11 +686,11 @@ namespace SHADE /*------------------------------------------------------------------------*/ //Save bindings registered into a file - static void SaveBindings(std::string const& targetFile = "Assets/InputBindings.SHConfig") noexcept; + static void SaveBindings(std::string const& targetFile = "../../Assets/Bindings.SHConfig") noexcept; //Load and register bindings from a file //The current list of bindings will be overwritten, so save them somewhere else before loading - static void LoadBindings(std::string const& sourceFile = "Assets/InputBindings.SHConfig") noexcept; + static void LoadBindings(std::string const& sourceFile = "../../Assets/Bindings.SHConfig") noexcept; /*------------------------------------------------------------------------*/ /* Binding Functions */ From 7dbd0b93b3cff3bb85bb48565e7a85ee68cb0caf Mon Sep 17 00:00:00 2001 From: mushgunAX Date: Sun, 8 Jan 2023 21:39:48 +0800 Subject: [PATCH 20/45] Minor comment fix --- SHADE_Engine/src/Input/SHInputManager.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SHADE_Engine/src/Input/SHInputManager.h b/SHADE_Engine/src/Input/SHInputManager.h index 01ef6c42..30ee00e8 100644 --- a/SHADE_Engine/src/Input/SHInputManager.h +++ b/SHADE_Engine/src/Input/SHInputManager.h @@ -689,7 +689,7 @@ namespace SHADE static void SaveBindings(std::string const& targetFile = "../../Assets/Bindings.SHConfig") noexcept; //Load and register bindings from a file - //The current list of bindings will be overwritten, so save them somewhere else before loading + //If specified file exists, the current list of bindings will be overwritten, so save them somewhere else before loading static void LoadBindings(std::string const& sourceFile = "../../Assets/Bindings.SHConfig") noexcept; /*------------------------------------------------------------------------*/ From b293b28a56f66dfefd476c706f0cb5a2c7a3aec4 Mon Sep 17 00:00:00 2001 From: maverickdgg Date: Mon, 9 Jan 2023 07:14:40 +0800 Subject: [PATCH 21/45] Button fix --- Assets/Application.SHConfig | 2 +- Assets/Scenes/UI Test.shade.shmeta | 2 +- SHADE_Engine/src/UI/SHUISystem.cpp | 54 ++++++++++++++++++++---------- SHADE_Engine/src/UI/SHUISystem.h | 2 ++ 4 files changed, 41 insertions(+), 19 deletions(-) diff --git a/Assets/Application.SHConfig b/Assets/Application.SHConfig index c9b34a7a..bc619d3b 100644 --- a/Assets/Application.SHConfig +++ b/Assets/Application.SHConfig @@ -1,4 +1,4 @@ Start in Fullscreen: false -Starting Scene ID: 94246101 +Starting Scene ID: 93618245 Window Size: {x: 1920, y: 1080} Window Title: SHADE Engine \ No newline at end of file diff --git a/Assets/Scenes/UI Test.shade.shmeta b/Assets/Scenes/UI Test.shade.shmeta index cf38916e..f64d5657 100644 --- a/Assets/Scenes/UI Test.shade.shmeta +++ b/Assets/Scenes/UI Test.shade.shmeta @@ -1,3 +1,3 @@ Name: UI Test -ID: 87707373 +ID: 92351881 Type: 5 diff --git a/SHADE_Engine/src/UI/SHUISystem.cpp b/SHADE_Engine/src/UI/SHUISystem.cpp index 1387bc6b..00aa0cda 100644 --- a/SHADE_Engine/src/UI/SHUISystem.cpp +++ b/SHADE_Engine/src/UI/SHUISystem.cpp @@ -149,9 +149,9 @@ namespace SHADE SHVec4 topExtent4 = uiComp->GetMatrix() * SHVec4(-comp.size.x * 0.5f, comp.size.y * 0.5f , 0.0f,1.0f); SHVec4 btmExtent4 = uiComp->GetMatrix() * SHVec4(comp.size.x * 0.5f , -comp.size.y * 0.5f , 0.0f, 1.0f); - SHVec2 topExtent{ topExtent4.x,-topExtent4.y }; - SHVec2 btmExtent{ btmExtent4.x,-btmExtent4.y }; - + SHVec2 topExtent{ topExtent4.x,topExtent4.y }; + SHVec2 btmExtent{ btmExtent4.x,btmExtent4.y }; + //SHLOG_INFO("TopExtent: {}, {}", topExtent.x, topExtent.y); SHVec2 windowSize; @@ -160,23 +160,24 @@ namespace SHADE windowSize = SHEditorWindowManager::GetEditorWindow()->windowSize; mousePos = SHEditorWindowManager::GetEditorWindow()->viewportMousePos; - - - + //SHLOG_INFO("MousePos: {}, {}", mousePos.x, mousePos.y); + //mousePos /= windowSize; #endif - SHVec2 camSize{ cameraSystem->GetCameraWidthHeight(0).x , cameraSystem->GetCameraWidthHeight(0).y }; + SHVec2 camSize{ cameraSystem->GetCameraWidthHeight(0)}; - topExtent += camSize * 0.5f; - btmExtent += camSize * 0.5f; + topExtent = CanvasToScreenPoint(topExtent); + btmExtent = CanvasToScreenPoint(btmExtent); - //Convert everything to using ratios - topExtent /= camSize; - btmExtent /= camSize; + //SHLOG_INFO("TopExtent Screen Point: {}, {}, Cam size: {}, {}", topExtent.x, topExtent.y, camSize.x, camSize.y); - mousePos /= windowSize; + //Convert everything to using ratios + //topExtent /= camSize; + //btmExtent /= camSize; + + //SHLOG_INFO("mousePos: {} , {}", mousePos.x, mousePos.y); comp.isClicked = false; @@ -187,6 +188,7 @@ namespace SHADE if (SHInputManager::GetKeyUp(SHInputManager::SH_KEYCODE::LMB)) { comp.isClicked = true; + //SHLOG_INFO("BUTTON CLICKED"); } //SHLOG_INFO("BUTTON HOVERED"); @@ -202,11 +204,11 @@ namespace SHADE if (SHComponentManager::HasComponent(comp.GetEID())) { - //auto renderable = SHComponentManager::GetComponent_s(comp.GetEID()); - //auto texture = SHResourceManager::Get(comp.GetDefaultTexture()); + auto renderable = SHComponentManager::GetComponent_s(comp.GetEID()); + auto texture = SHResourceManager::Get(comp.GetDefaultTexture()); - //auto material = renderable->GetModifiableMaterial(); - //material->SetProperty("texture", comp.GetDefaultTexture()); + auto material = renderable->GetModifiableMaterial(); + material->SetProperty("texture", comp.GetDefaultTexture()); } } @@ -221,4 +223,22 @@ namespace SHADE } } + SHVec2 SHUISystem::CanvasToScreenPoint(SHVec2& const canvasPoint) noexcept + { + SHVec2 result{canvasPoint}; + + auto cameraSystem = SHSystemManager::GetSystem(); + + SHVec2 camSize{ cameraSystem->GetCameraWidthHeight(0) }; + + + result.y *= -1.0f; + result += camSize * 0.5f; + + return result; + } + + + + }//end namespace diff --git a/SHADE_Engine/src/UI/SHUISystem.h b/SHADE_Engine/src/UI/SHUISystem.h index 04e057ad..21518f16 100644 --- a/SHADE_Engine/src/UI/SHUISystem.h +++ b/SHADE_Engine/src/UI/SHUISystem.h @@ -65,6 +65,8 @@ namespace SHADE void UpdateUIComponent(SHUIComponent& comp) noexcept; void UpdateButtonComponent(SHButtonComponent& comp) noexcept; void UpdateCanvasComponent(SHCanvasComponent& comp) noexcept; + SHVec2 CanvasToScreenPoint(SHVec2& const canvasPoint) noexcept; + }; From 5f11a931c78ab54aa6b706b9cf8f3690d3bf7af2 Mon Sep 17 00:00:00 2001 From: maverickdgg Date: Mon, 9 Jan 2023 09:24:20 +0800 Subject: [PATCH 22/45] Added Toggle Button, Fixed canvas Scalar --- Assets/Scenes/UI Test.shade | 24 +++- Assets/Scenes/UI Test.shade.shmeta | 2 +- .../Inspector/SHEditorInspector.cpp | 6 + .../src/Serialization/SHSerialization.cpp | 4 + SHADE_Engine/src/UI/SHButtonComponent.cpp | 2 +- SHADE_Engine/src/UI/SHButtonComponent.h | 1 - .../src/UI/SHToggleButtonComponent.cpp | 59 +++++++++ SHADE_Engine/src/UI/SHToggleButtonComponent.h | 48 ++++++++ SHADE_Engine/src/UI/SHUISystem.cpp | 116 +++++++++++++----- SHADE_Engine/src/UI/SHUISystem.h | 2 + 10 files changed, 229 insertions(+), 35 deletions(-) create mode 100644 SHADE_Engine/src/UI/SHToggleButtonComponent.cpp create mode 100644 SHADE_Engine/src/UI/SHToggleButtonComponent.h diff --git a/Assets/Scenes/UI Test.shade b/Assets/Scenes/UI Test.shade index e8ee4df2..0aea6f72 100644 --- a/Assets/Scenes/UI Test.shade +++ b/Assets/Scenes/UI Test.shade @@ -1,7 +1,7 @@ - EID: 0 Name: Canvas IsActive: true - NumberOfChildren: 1 + NumberOfChildren: 2 Components: Canvas Component: Canvas Width: 10 @@ -14,7 +14,7 @@ NumberOfChildren: 0 Components: Transform Component: - Translate: {x: 0, y: 0, z: 0} + Translate: {x: -3.5999999, y: 3.0999999, z: 0} Rotate: {x: 0, y: 0, z: 0} Scale: {x: 1, y: 1, z: 1} IsActive: true @@ -28,6 +28,26 @@ Clicked Texture: 0 IsActive: true Scripts: ~ +- EID: 5 + Name: Default + IsActive: true + NumberOfChildren: 0 + Components: + Transform Component: + Translate: {x: 153.399994, y: 0, z: 0} + Rotate: {x: 0, y: 0, z: 0} + Scale: {x: 1, y: 1, z: 1} + IsActive: true + Renderable Component: + Mesh: 141771688 + Material: 129340704 + IsActive: true + Toggle Button Component: + Non Toggled Texture: 0 + Toggled Texture: 0 + Value: false + IsActive: true + Scripts: ~ - EID: 1 Name: Camera IsActive: true diff --git a/Assets/Scenes/UI Test.shade.shmeta b/Assets/Scenes/UI Test.shade.shmeta index f64d5657..a889afd5 100644 --- a/Assets/Scenes/UI Test.shade.shmeta +++ b/Assets/Scenes/UI Test.shade.shmeta @@ -1,3 +1,3 @@ Name: UI Test -ID: 92351881 +ID: 94041256 Type: 5 diff --git a/SHADE_Engine/src/Editor/EditorWindow/Inspector/SHEditorInspector.cpp b/SHADE_Engine/src/Editor/EditorWindow/Inspector/SHEditorInspector.cpp index 83647da7..ed6ea6bb 100644 --- a/SHADE_Engine/src/Editor/EditorWindow/Inspector/SHEditorInspector.cpp +++ b/SHADE_Engine/src/Editor/EditorWindow/Inspector/SHEditorInspector.cpp @@ -21,6 +21,7 @@ #include "UI/SHUIComponent.h" #include "UI/SHCanvasComponent.h" #include "UI/SHButtonComponent.h" +#include "UI/SHToggleButtonComponent.h" #include "SHEditorComponentView.h" #include "AudioSystem/SHAudioListenerComponent.h" #include "Graphics/MiddleEnd/TextRendering/SHTextRenderableComponent.h" @@ -154,6 +155,10 @@ namespace SHADE { DrawComponent(buttonComponent); } + if (auto toggleButton = SHComponentManager::GetComponent_s(eid)) + { + DrawComponent(toggleButton); + } ImGui::Separator(); // Render Scripts SHScriptEngine* scriptEngine = static_cast(SHSystemManager::GetSystem()); @@ -167,6 +172,7 @@ namespace SHADE DrawAddComponentButton(eid); DrawAddComponentButton(eid); DrawAddComponentButton(eid); + DrawAddComponentButton(eid); // Components that require Transforms diff --git a/SHADE_Engine/src/Serialization/SHSerialization.cpp b/SHADE_Engine/src/Serialization/SHSerialization.cpp index 99e4fa41..89e947fc 100644 --- a/SHADE_Engine/src/Serialization/SHSerialization.cpp +++ b/SHADE_Engine/src/Serialization/SHSerialization.cpp @@ -18,6 +18,7 @@ #include "Physics/Interface/SHRigidBodyComponent.h" #include "UI/SHCanvasComponent.h" #include "UI/SHButtonComponent.h" +#include "UI/SHToggleButtonComponent.h" #include "ECS_Base/Managers/SHSystemManager.h" #include "Graphics/MiddleEnd/Lights/SHLightComponent.h" #include "Scripting/SHScriptEngine.h" @@ -218,6 +219,7 @@ namespace SHADE AddComponentToComponentNode(components, eid); AddComponentToComponentNode(components, eid); + AddComponentToComponentNode(components, eid); AddConvComponentToComponentNode(components, eid); @@ -275,6 +277,7 @@ namespace SHADE AddComponentID(componentIDList, componentsNode); AddComponentID(componentIDList, componentsNode); + AddComponentID(componentIDList, componentsNode); AddComponentID(componentIDList, componentsNode); return componentIDList; @@ -356,6 +359,7 @@ namespace SHADE SHSerializationHelper::InitializeComponentFromNode(componentsNode, eid); SHSerializationHelper::InitializeComponentFromNode(componentsNode, eid); + SHSerializationHelper::InitializeComponentFromNode(componentsNode, eid); SHSerializationHelper::ConvertNodeToComponent(componentsNode, eid); SHSerializationHelper::InitializeComponentFromNode(componentsNode, eid); } diff --git a/SHADE_Engine/src/UI/SHButtonComponent.cpp b/SHADE_Engine/src/UI/SHButtonComponent.cpp index 7b275128..8e87b10e 100644 --- a/SHADE_Engine/src/UI/SHButtonComponent.cpp +++ b/SHADE_Engine/src/UI/SHButtonComponent.cpp @@ -5,7 +5,7 @@ namespace SHADE { SHButtonComponent::SHButtonComponent() - :size(1.0f), offset(0.0f), isHovered(false), isClicked(false), + :size(1.0f), isHovered(false), isClicked(false), defaultTexture(0), hoveredTexture(0), clickedTexture(0) { } diff --git a/SHADE_Engine/src/UI/SHButtonComponent.h b/SHADE_Engine/src/UI/SHButtonComponent.h index 39790b6a..be6ada3e 100644 --- a/SHADE_Engine/src/UI/SHButtonComponent.h +++ b/SHADE_Engine/src/UI/SHButtonComponent.h @@ -18,7 +18,6 @@ namespace SHADE virtual ~SHButtonComponent() = default; SHVec2 size; - SHVec2 offset; AssetID GetClickedTexture() const noexcept; AssetID GetDefaultTexture() const noexcept; diff --git a/SHADE_Engine/src/UI/SHToggleButtonComponent.cpp b/SHADE_Engine/src/UI/SHToggleButtonComponent.cpp new file mode 100644 index 00000000..527323ea --- /dev/null +++ b/SHADE_Engine/src/UI/SHToggleButtonComponent.cpp @@ -0,0 +1,59 @@ +#include "SHpch.h" +#include "SHToggleButtonComponent.h" + + +namespace SHADE +{ + SHToggleButtonComponent::SHToggleButtonComponent() + :size(1.0f), isHovered(false), isClicked(false), value(false), + defaultTexture(0), toggledTexture(0) + { + } + + AssetID SHToggleButtonComponent::GetDefaultTexture() const noexcept + { + return defaultTexture; + } + + AssetID SHToggleButtonComponent::GetToggledTexture() const noexcept + { + return toggledTexture; + } + + bool SHToggleButtonComponent::GetValue() const noexcept + { + return value; + } + + + void SHToggleButtonComponent::SetDefaultTexture(AssetID texture) noexcept + { + defaultTexture = texture; + } + + void SHToggleButtonComponent::SetToggledTexture(AssetID texture) noexcept + { + toggledTexture = texture; + } + + void SHToggleButtonComponent::SetValue(bool value) noexcept + { + this->value = value; + } + +} + + +RTTR_REGISTRATION +{ + using namespace SHADE; + using namespace rttr; + + registration::class_("Toggle Button Component") + .property("Non Toggled Texture", &SHToggleButtonComponent::GetDefaultTexture, &SHToggleButtonComponent::SetDefaultTexture) + .property("Toggled Texture", &SHToggleButtonComponent::GetToggledTexture, &SHToggleButtonComponent::SetToggledTexture) + .property("Value", &SHToggleButtonComponent::GetValue, &SHToggleButtonComponent::SetValue) + ; + + +} \ No newline at end of file diff --git a/SHADE_Engine/src/UI/SHToggleButtonComponent.h b/SHADE_Engine/src/UI/SHToggleButtonComponent.h new file mode 100644 index 00000000..3217c892 --- /dev/null +++ b/SHADE_Engine/src/UI/SHToggleButtonComponent.h @@ -0,0 +1,48 @@ +#pragma once + +#include + +#include "SH_API.h" +#include "ECS_Base/Components/SHComponent.h" +#include "Math/Vector/SHVec3.h" +#include "Math/Vector/SHVec2.h" +#include "Assets/SHAssetMacros.h" + +namespace SHADE +{ + + class SH_API SHToggleButtonComponent final: public SHComponent + { + public: + SHToggleButtonComponent(); + virtual ~SHToggleButtonComponent() = default; + + SHVec2 size; + + AssetID GetToggledTexture() const noexcept; + AssetID GetDefaultTexture() const noexcept; + bool GetValue() const noexcept; + + + void SetDefaultTexture(AssetID texture) noexcept; + void SetToggledTexture(AssetID texture) noexcept; + void SetValue(bool value) noexcept; + + + + friend class SHUISystem; + private: + + bool isHovered; + bool isClicked; + bool value; + AssetID defaultTexture; + AssetID toggledTexture; + + + + RTTR_ENABLE() + }; + + +} \ No newline at end of file diff --git a/SHADE_Engine/src/UI/SHUISystem.cpp b/SHADE_Engine/src/UI/SHUISystem.cpp index 00aa0cda..f3b5cad8 100644 --- a/SHADE_Engine/src/UI/SHUISystem.cpp +++ b/SHADE_Engine/src/UI/SHUISystem.cpp @@ -103,7 +103,7 @@ namespace SHADE { auto transform = SHComponentManager::GetComponent(comp.GetEID()); if (canvasComp != nullptr) - comp.localToCanvasMatrix = canvasComp->GetMatrix()* transform->GetTRS(); + comp.localToCanvasMatrix = transform->GetTRS() * canvasComp->GetMatrix(); else comp.localToCanvasMatrix = transform->GetTRS(); } @@ -139,47 +139,38 @@ namespace SHADE void SHUISystem::UpdateButtonComponent(SHButtonComponent& comp) noexcept { - if (!SHComponentManager::HasComponent(comp.GetEID()) || !SHComponentManager::HasComponent(comp.GetEID())) + if (!SHComponentManager::HasComponent(comp.GetEID())) { return; } auto cameraSystem = SHSystemManager::GetSystem(); auto uiComp = SHComponentManager::GetComponent(comp.GetEID()); - SHVec4 topExtent4 = uiComp->GetMatrix() * SHVec4(-comp.size.x * 0.5f, comp.size.y * 0.5f , 0.0f,1.0f); - SHVec4 btmExtent4 = uiComp->GetMatrix() * SHVec4(comp.size.x * 0.5f , -comp.size.y * 0.5f , 0.0f, 1.0f); + SHVec4 topExtent4 = SHMatrix::Translate(-comp.size.x * 0.5f, comp.size.y * 0.5f, 0.0f) * uiComp->GetMatrix() * SHVec4(0.0f,0.0f, 0.0f,1.0f); + SHVec4 btmExtent4 = SHMatrix::Translate(comp.size.x * 0.5f, -comp.size.y * 0.5f, 0.0f) * uiComp->GetMatrix() * SHVec4(0.0f,0.0f, 0.0f,1.0f); + //SHVec4 btmExtent4 = uiComp->GetMatrix() * SHVec4(comp.size.x * 0.5f , -comp.size.y * 0.5f , 0.0f, 1.0f); SHVec2 topExtent{ topExtent4.x,topExtent4.y }; SHVec2 btmExtent{ btmExtent4.x,btmExtent4.y }; - //SHLOG_INFO("TopExtent: {}, {}", topExtent.x, topExtent.y); - - SHVec2 windowSize; + SHVec2 mousePos; + SHVec2 windowSize; #ifdef SHEDITOR - windowSize = SHEditorWindowManager::GetEditorWindow()->windowSize; mousePos = SHEditorWindowManager::GetEditorWindow()->viewportMousePos; - //SHLOG_INFO("MousePos: {}, {}", mousePos.x, mousePos.y); - //mousePos /= windowSize; + //mousePos.y = windowSize.y - mousePos.y; + mousePos /= windowSize; #endif - - SHVec2 camSize{ cameraSystem->GetCameraWidthHeight(0)}; + //SHLOG_INFO("TopExtent: {}, {}", topExtent.x, topExtent.y) topExtent = CanvasToScreenPoint(topExtent); btmExtent = CanvasToScreenPoint(btmExtent); - - //SHLOG_INFO("TopExtent Screen Point: {}, {}, Cam size: {}, {}", topExtent.x, topExtent.y, camSize.x, camSize.y); + topExtent /= camSize; + btmExtent /= camSize; - //Convert everything to using ratios - //topExtent /= camSize; - //btmExtent /= camSize; - - - - //SHLOG_INFO("mousePos: {} , {}", mousePos.x, mousePos.y); comp.isClicked = false; if (mousePos.x >= topExtent.x && mousePos.x <= btmExtent.x && mousePos.y >= topExtent.y && mousePos.y <= btmExtent.y) @@ -188,30 +179,88 @@ namespace SHADE if (SHInputManager::GetKeyUp(SHInputManager::SH_KEYCODE::LMB)) { comp.isClicked = true; - //SHLOG_INFO("BUTTON CLICKED"); } - //SHLOG_INFO("BUTTON HOVERED"); - - + SHLOG_INFO("HOVERED") } else { comp.isHovered = false; - - //SHLOG_INFO("BUTTON NOT HOVERED") + SHLOG_INFO("NOT HOVERED") } if (SHComponentManager::HasComponent(comp.GetEID())) { - auto renderable = SHComponentManager::GetComponent_s(comp.GetEID()); + /*auto renderable = SHComponentManager::GetComponent_s(comp.GetEID()); auto texture = SHResourceManager::Get(comp.GetDefaultTexture()); auto material = renderable->GetModifiableMaterial(); - material->SetProperty("texture", comp.GetDefaultTexture()); + material->SetProperty("texture", comp.GetDefaultTexture());*/ } } + + void SHUISystem::UpdateToggleButtonComponent(SHToggleButtonComponent& comp) noexcept + { + if (!SHComponentManager::HasComponent(comp.GetEID())) + { + return; + } + auto cameraSystem = SHSystemManager::GetSystem(); + auto uiComp = SHComponentManager::GetComponent(comp.GetEID()); + + SHVec4 topExtent4 = uiComp->GetMatrix() * SHVec4(-comp.size.x * 0.5f, comp.size.y * 0.5f, 0.0f, 1.0f); + SHVec4 btmExtent4 = uiComp->GetMatrix() * SHVec4(comp.size.x * 0.5f, -comp.size.y * 0.5f, 0.0f, 1.0f); + + SHVec2 topExtent{ topExtent4.x,topExtent4.y }; + SHVec2 btmExtent{ btmExtent4.x,btmExtent4.y }; + + SHVec2 mousePos; + SHVec2 windowSize; +#ifdef SHEDITOR + windowSize = SHEditorWindowManager::GetEditorWindow()->windowSize; + mousePos = SHEditorWindowManager::GetEditorWindow()->viewportMousePos; + mousePos /= windowSize; +#endif + + SHVec2 camSize{ cameraSystem->GetCameraWidthHeight(0) }; + + + + topExtent = CanvasToScreenPoint(topExtent); + btmExtent = CanvasToScreenPoint(btmExtent); + topExtent /= camSize; + btmExtent /= camSize; + + + comp.isClicked = false; + if (mousePos.x >= topExtent.x && mousePos.x <= btmExtent.x + && mousePos.y >= topExtent.y && mousePos.y <= btmExtent.y) + { + comp.isHovered = true; + if (SHInputManager::GetKeyUp(SHInputManager::SH_KEYCODE::LMB)) + { + comp.isClicked = true; + comp.value = !comp.value; + } + } + else + { + comp.isHovered = false; + } + + + if (SHComponentManager::HasComponent(comp.GetEID())) + { + /*auto renderable = SHComponentManager::GetComponent_s(comp.GetEID()); + auto texture = SHResourceManager::Get(comp.GetDefaultTexture()); + + auto material = renderable->GetModifiableMaterial(); + material->SetProperty("texture", comp.GetDefaultTexture());*/ + } + } + + void SHUISystem::UpdateButtonsRoutine::Execute(double dt) noexcept { SHUISystem* system = (SHUISystem*)GetSystem(); @@ -221,6 +270,13 @@ namespace SHADE if (SHSceneManager::CheckNodeAndComponentsActive(comp.GetEID())) system->UpdateButtonComponent(comp); } + + auto& toggleButtonDense = SHComponentManager::GetDense(); + for (auto& comp : toggleButtonDense) + { + if (SHSceneManager::CheckNodeAndComponentsActive(comp.GetEID())) + system->UpdateToggleButtonComponent(comp); + } } SHVec2 SHUISystem::CanvasToScreenPoint(SHVec2& const canvasPoint) noexcept @@ -230,7 +286,7 @@ namespace SHADE auto cameraSystem = SHSystemManager::GetSystem(); SHVec2 camSize{ cameraSystem->GetCameraWidthHeight(0) }; - + //camSize.y *= -1.0f; result.y *= -1.0f; result += camSize * 0.5f; diff --git a/SHADE_Engine/src/UI/SHUISystem.h b/SHADE_Engine/src/UI/SHUISystem.h index 21518f16..a5ba8c4f 100644 --- a/SHADE_Engine/src/UI/SHUISystem.h +++ b/SHADE_Engine/src/UI/SHUISystem.h @@ -5,6 +5,7 @@ #include "ECS_Base/System/SHSystemRoutine.h" #include "SHUIComponent.h" #include "SHButtonComponent.h" +#include "SHToggleButtonComponent.h" #include "SHCanvasComponent.h" #include "Scene/SHSceneGraph.h" #include "Scene/SHSceneManager.h" @@ -64,6 +65,7 @@ namespace SHADE private: void UpdateUIComponent(SHUIComponent& comp) noexcept; void UpdateButtonComponent(SHButtonComponent& comp) noexcept; + void UpdateToggleButtonComponent(SHToggleButtonComponent& comp) noexcept; void UpdateCanvasComponent(SHCanvasComponent& comp) noexcept; SHVec2 CanvasToScreenPoint(SHVec2& const canvasPoint) noexcept; From e89b6f5c4cc421555a58e2973202a5dcb02cc944 Mon Sep 17 00:00:00 2001 From: maverickdgg Date: Mon, 9 Jan 2023 09:38:53 +0800 Subject: [PATCH 23/45] Fixing button --- Assets/Scenes/UI Test.shade.shmeta | 2 +- SHADE_Engine/src/UI/SHUISystem.cpp | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/Assets/Scenes/UI Test.shade.shmeta b/Assets/Scenes/UI Test.shade.shmeta index a889afd5..e65c0b8f 100644 --- a/Assets/Scenes/UI Test.shade.shmeta +++ b/Assets/Scenes/UI Test.shade.shmeta @@ -1,3 +1,3 @@ Name: UI Test -ID: 94041256 +ID: 96041206 Type: 5 diff --git a/SHADE_Engine/src/UI/SHUISystem.cpp b/SHADE_Engine/src/UI/SHUISystem.cpp index f3b5cad8..571eb167 100644 --- a/SHADE_Engine/src/UI/SHUISystem.cpp +++ b/SHADE_Engine/src/UI/SHUISystem.cpp @@ -145,10 +145,11 @@ namespace SHADE } auto cameraSystem = SHSystemManager::GetSystem(); auto uiComp = SHComponentManager::GetComponent(comp.GetEID()); + //auto canvasComp = SHComponentManager::GetComponent_s(uiComp->canvasID); - SHVec4 topExtent4 = SHMatrix::Translate(-comp.size.x * 0.5f, comp.size.y * 0.5f, 0.0f) * uiComp->GetMatrix() * SHVec4(0.0f,0.0f, 0.0f,1.0f); - SHVec4 btmExtent4 = SHMatrix::Translate(comp.size.x * 0.5f, -comp.size.y * 0.5f, 0.0f) * uiComp->GetMatrix() * SHVec4(0.0f,0.0f, 0.0f,1.0f); - //SHVec4 btmExtent4 = uiComp->GetMatrix() * SHVec4(comp.size.x * 0.5f , -comp.size.y * 0.5f , 0.0f, 1.0f); + SHVec4 topExtent4 = SHMatrix::Translate(-comp.size.x * 0.5f, comp.size.y * 0.5f, 0.0f) * uiComp->GetMatrix() * SHVec4(0.0f, 0.0f, 0.0f, 1.0f); + SHVec4 btmExtent4 = SHMatrix::Translate(comp.size.x * 0.5f, -comp.size.y * 0.5f, 0.0f) * uiComp->GetMatrix() * SHVec4(0.0f,0.0f, 0.0f,1.0f); + SHVec2 topExtent{ topExtent4.x,topExtent4.y }; SHVec2 btmExtent{ btmExtent4.x,btmExtent4.y }; From 4928ed4bcfa52d32493f873ae3499b26bed3bec0 Mon Sep 17 00:00:00 2001 From: Brandon Mak Date: Sat, 7 Jan 2023 22:40:29 +0800 Subject: [PATCH 24/45] Will update commit message tomorrow. Fuck Vulkan. *KW in BG: DiReCtX* - Changed RenderGraphNodeNames to RenderGraphEntityNames - Managed to get shadow maps into desc sets --- SHADE_Engine/src/Editor/SHEditor.cpp | 4 +- .../Descriptors/SHVkDescriptorSetGroup.cpp | 22 ++++++++ .../Descriptors/SHVkDescriptorSetGroup.h | 1 + .../Graphics/Devices/SHVkLogicalDevice.cpp | 1 + .../MiddleEnd/Interface/SHDebugDrawSystem.cpp | 4 +- .../MiddleEnd/Interface/SHGraphicsConstants.h | 15 ++++- .../MiddleEnd/Interface/SHGraphicsSystem.cpp | 42 ++++++++------ .../MiddleEnd/Lights/SHLightingSubSystem.cpp | 56 +++++++++++-------- .../MiddleEnd/Lights/SHLightingSubSystem.h | 10 +++- .../RenderGraph/SHRenderGraphNode.cpp | 15 ++++- .../Graphics/RenderGraph/SHRenderGraphNode.h | 3 +- .../RenderGraph/SHRenderGraphNodeCompute.cpp | 22 ++++---- .../RenderGraph/SHRenderGraphNodeCompute.h | 3 +- .../src/Graphics/RenderGraph/SHSubpass.cpp | 4 +- 14 files changed, 136 insertions(+), 66 deletions(-) diff --git a/SHADE_Engine/src/Editor/SHEditor.cpp b/SHADE_Engine/src/Editor/SHEditor.cpp index f3fe6b72..9e7ffcc6 100644 --- a/SHADE_Engine/src/Editor/SHEditor.cpp +++ b/SHADE_Engine/src/Editor/SHEditor.cpp @@ -502,7 +502,7 @@ namespace SHADE //auto const& renderers = gfxSystem->GetDefaultViewport()->GetRenderers(); auto renderGraph = gfxSystem->GetRenderGraph(); - auto renderPass = renderGraph->GetNode(SHGraphicsConstants::RenderGraphNodeNames::IMGUI_PASS.data())->GetRenderpass(); + auto renderPass = renderGraph->GetNode(SHGraphicsConstants::RenderGraphEntityNames::IMGUI_PASS.data())->GetRenderpass(); if(ImGui_ImplVulkan_Init(&initInfo, renderPass->GetVkRenderpass()) == false) { @@ -521,7 +521,7 @@ namespace SHADE ImGui_ImplVulkan_DestroyFontUploadObjects(); - renderGraph->GetNode(SHGraphicsConstants::RenderGraphNodeNames::IMGUI_PASS.data())->GetSubpass("ImGui Draw")->AddExteriorDrawCalls([](Handle cmd, Handle renderer, uint32_t frameIndex) + renderGraph->GetNode(SHGraphicsConstants::RenderGraphEntityNames::IMGUI_PASS.data())->GetSubpass("ImGui Draw")->AddExteriorDrawCalls([](Handle cmd, Handle renderer, uint32_t frameIndex) { cmd->BeginLabeledSegment("ImGui Draw"); ImGui_ImplVulkan_RenderDrawData(ImGui::GetDrawData(), cmd->GetVkCommandBuffer()); diff --git a/SHADE_Engine/src/Graphics/Descriptors/SHVkDescriptorSetGroup.cpp b/SHADE_Engine/src/Graphics/Descriptors/SHVkDescriptorSetGroup.cpp index 7c5c0e48..19ec721b 100644 --- a/SHADE_Engine/src/Graphics/Descriptors/SHVkDescriptorSetGroup.cpp +++ b/SHADE_Engine/src/Graphics/Descriptors/SHVkDescriptorSetGroup.cpp @@ -215,6 +215,28 @@ namespace SHADE } + void SHVkDescriptorSetGroup::UpdateDescriptorSetImage(uint32_t set, uint32_t binding, uint32_t descArrayIndex) noexcept + { + vk::WriteDescriptorSet writeDescSet{}; + + // Get binding + set hash + BindingAndSetHash bsHash = SHVkUtil::GenBindingSetHash(set, binding); + + // to index a write for a binding + uint32_t writeInfoIndex = updater.writeHashMap[bsHash]; + + // Initialize info for write + writeDescSet.descriptorType = layoutsUsed[set]->GetBindings()[binding].Type; + writeDescSet.dstArrayElement = descArrayIndex; + writeDescSet.dstSet = descSets[set]; + writeDescSet.dstBinding = binding; + + writeDescSet.pImageInfo = updater.writeInfos[writeInfoIndex].descImageInfos.data() + descArrayIndex; + writeDescSet.descriptorCount = 1u; + + device->UpdateDescriptorSet(writeDescSet); + } + void SHVkDescriptorSetGroup::UpdateDescriptorSetImages(uint32_t set, uint32_t binding) noexcept { vk::WriteDescriptorSet writeDescSet{}; diff --git a/SHADE_Engine/src/Graphics/Descriptors/SHVkDescriptorSetGroup.h b/SHADE_Engine/src/Graphics/Descriptors/SHVkDescriptorSetGroup.h index 4538b271..5b65174a 100644 --- a/SHADE_Engine/src/Graphics/Descriptors/SHVkDescriptorSetGroup.h +++ b/SHADE_Engine/src/Graphics/Descriptors/SHVkDescriptorSetGroup.h @@ -63,6 +63,7 @@ namespace SHADE /*-----------------------------------------------------------------------------*/ /* Public member functions */ /*-----------------------------------------------------------------------------*/ + void UpdateDescriptorSetImage (uint32_t set, uint32_t binding, uint32_t descArrayIndex) noexcept; void UpdateDescriptorSetImages(uint32_t set, uint32_t binding) noexcept; void UpdateDescriptorSetBuffer(uint32_t set, uint32_t binding) noexcept; diff --git a/SHADE_Engine/src/Graphics/Devices/SHVkLogicalDevice.cpp b/SHADE_Engine/src/Graphics/Devices/SHVkLogicalDevice.cpp index 6a6e385f..3e504fb5 100644 --- a/SHADE_Engine/src/Graphics/Devices/SHVkLogicalDevice.cpp +++ b/SHADE_Engine/src/Graphics/Devices/SHVkLogicalDevice.cpp @@ -191,6 +191,7 @@ namespace SHADE features.multiDrawIndirect = VK_TRUE; features.independentBlend = VK_TRUE; + // for wide lines features.wideLines = true; diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHDebugDrawSystem.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHDebugDrawSystem.cpp index fc701da3..a5bc4ccd 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHDebugDrawSystem.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHDebugDrawSystem.cpp @@ -101,7 +101,7 @@ namespace SHADE // Register function for subpass //auto const& RENDERERS = gfxSystem->GetDefaultViewport()->GetRenderers(); auto renderGraph = gfxSystem->GetRenderGraph(); - auto subPass = renderGraph->GetNode(SHGraphicsConstants::RenderGraphNodeNames::DEBUG_DRAW.data())->GetSubpass("Debug Draw"); + auto subPass = renderGraph->GetNode(SHGraphicsConstants::RenderGraphEntityNames::DEBUG_DRAW.data())->GetSubpass("Debug Draw"); subPass->AddExteriorDrawCalls([this](Handle cmdBuffer, Handle renderer, uint32_t frameIndex) { const uint32_t FRAME_IDX = gfxSystem->GetCurrentFrameIndex(); @@ -125,7 +125,7 @@ namespace SHADE } cmdBuffer->EndLabeledSegment(); }); - auto subPassWithDepth = renderGraph->GetNode(SHGraphicsConstants::RenderGraphNodeNames::DEBUG_DRAW_DEPTH_PASS.data())->GetSubpass("Debug Draw with Depth"); + auto subPassWithDepth = renderGraph->GetNode(SHGraphicsConstants::RenderGraphEntityNames::DEBUG_DRAW_DEPTH_PASS.data())->GetSubpass("Debug Draw with Depth"); subPassWithDepth->AddExteriorDrawCalls([this](Handle cmdBuffer, Handle renderer, uint32_t frameIndex) { const uint32_t FRAME_IDX = gfxSystem->GetCurrentFrameIndex(); diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsConstants.h b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsConstants.h index b061dde3..b3945689 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsConstants.h +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsConstants.h @@ -31,7 +31,7 @@ namespace SHADE static constexpr uint32_t EDITOR = 0; }; - struct RenderGraphNodeNames + struct RenderGraphEntityNames { /***************************************************************************/ /*! @@ -103,6 +103,18 @@ namespace SHADE /***************************************************************************/ static constexpr std::string_view IMGUI_PASS = "ImGui Pass"; + /***************************************************************************/ + /*! + + \brief + Name of deferred composite compute. + + */ + /***************************************************************************/ + static constexpr std::string_view DEFERRED_COMPOSITE_COMPUTE = "Deferred Composite"; + + + }; struct DescriptorSetBindings @@ -178,6 +190,7 @@ namespace SHADE /***************************************************************************/ static constexpr uint32_t SHADOW_MAP_IMAGE_SAMPLER_DATA = 0; + }; struct VertexBufferBindings diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp index 57c83e10..1fadc7b1 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp @@ -208,7 +208,7 @@ namespace SHADE /*-----------------------------------------------------------------------*/ /* MAIN NODE */ /*-----------------------------------------------------------------------*/ - auto gBufferNode = renderGraph->AddNode(SHGraphicsConstants::RenderGraphNodeNames::GBUFFER_PASS.data(), + auto gBufferNode = renderGraph->AddNode(SHGraphicsConstants::RenderGraphEntityNames::GBUFFER_PASS.data(), //auto gBufferNode = renderGraph->AddNode(SHGraphicsConstants::RenderGraphNodeNames::GBUFFER_PASS.data() { "Position", @@ -276,7 +276,7 @@ namespace SHADE /* DEFERRED COMPOSITE NODE */ /*-----------------------------------------------------------------------*/ // This pass will facilitate both lighting and shadows in 1 single pass. - auto deferredCompositeNode = renderGraph->AddNode(SHGraphicsConstants::RenderGraphNodeNames::DEFERRED_COMPOSITE_PASS.data(), + auto deferredCompositeNode = renderGraph->AddNode(SHGraphicsConstants::RenderGraphEntityNames::DEFERRED_COMPOSITE_PASS.data(), { "Position", "Light Layer Indices", @@ -285,13 +285,13 @@ namespace SHADE "Scene", "SSAO Blur" }, - { SHGraphicsConstants::RenderGraphNodeNames::GBUFFER_PASS .data()}); + { SHGraphicsConstants::RenderGraphEntityNames::GBUFFER_PASS .data()}); /*-----------------------------------------------------------------------*/ /* DEFERRED COMPOSITE SUBPASS INIT */ /*-----------------------------------------------------------------------*/ - auto deferredCompositeCompute = deferredCompositeNode->AddNodeCompute("Deferred Composite", deferredCompositeShader, { "Position", "Normals", "Albedo", "Light Layer Indices", "SSAO Blur", "Scene" }, {}/*SHGraphicsPredefinedData::GetPredefinedDescSetLayouts(SHGraphicsPredefinedData::PredefinedDescSetLayoutTypes::SHADOW)[0]*/); + auto deferredCompositeCompute = deferredCompositeNode->AddNodeCompute(SHGraphicsConstants::RenderGraphEntityNames::DEFERRED_COMPOSITE_COMPUTE.data(), deferredCompositeShader, {"Position", "Normals", "Albedo", "Light Layer Indices", "SSAO Blur", "Scene"}, {}, SHLightingSubSystem::MAX_SHADOWS); deferredCompositeCompute->AddPreComputeFunction([=](Handle cmdBuffer, uint32_t frameIndex) { lightingSubSystem->PrepareShadowMapsForRead(cmdBuffer); @@ -303,19 +303,19 @@ namespace SHADE /*-----------------------------------------------------------------------*/ // Set up Debug Draw Passes // - Depth Tested - auto debugDrawNodeDepth = renderGraph->AddNode(SHGraphicsConstants::RenderGraphNodeNames::DEBUG_DRAW_DEPTH_PASS.data(), {"Scene", "Depth Buffer"}, {SHGraphicsConstants::RenderGraphNodeNames::GBUFFER_PASS.data(), SHGraphicsConstants::RenderGraphNodeNames::DEFERRED_COMPOSITE_PASS.data()}); + auto debugDrawNodeDepth = renderGraph->AddNode(SHGraphicsConstants::RenderGraphEntityNames::DEBUG_DRAW_DEPTH_PASS.data(), {"Scene", "Depth Buffer"}, {SHGraphicsConstants::RenderGraphEntityNames::GBUFFER_PASS.data(), SHGraphicsConstants::RenderGraphEntityNames::DEFERRED_COMPOSITE_PASS.data()}); auto debugDrawDepthSubpass = debugDrawNodeDepth->AddSubpass("Debug Draw with Depth", worldViewport, worldRenderer); debugDrawDepthSubpass->AddColorOutput("Scene"); debugDrawDepthSubpass->AddDepthOutput("Depth Buffer"); // - No Depth Test - auto debugDrawNode = renderGraph->AddNode(SHGraphicsConstants::RenderGraphNodeNames::DEBUG_DRAW.data(), {"Scene"}, {SHGraphicsConstants::RenderGraphNodeNames::DEBUG_DRAW_DEPTH_PASS.data()}); + auto debugDrawNode = renderGraph->AddNode(SHGraphicsConstants::RenderGraphEntityNames::DEBUG_DRAW.data(), {"Scene"}, {SHGraphicsConstants::RenderGraphEntityNames::DEBUG_DRAW_DEPTH_PASS.data()}); auto debugDrawSubpass = debugDrawNode->AddSubpass("Debug Draw", worldViewport, worldRenderer); debugDrawSubpass->AddColorOutput("Scene"); /*-----------------------------------------------------------------------*/ /* SCREEN SPACE PASS */ /*-----------------------------------------------------------------------*/ - auto screenSpaceNode = renderGraph->AddNode(SHGraphicsConstants::RenderGraphNodeNames::SCREEN_SPACE_PASS.data(), {"Scene", "Entity ID"}, {SHGraphicsConstants::RenderGraphNodeNames::DEFERRED_COMPOSITE_PASS.data(), SHGraphicsConstants::RenderGraphNodeNames::GBUFFER_PASS.data(), SHGraphicsConstants::RenderGraphNodeNames::DEBUG_DRAW.data()}); + auto screenSpaceNode = renderGraph->AddNode(SHGraphicsConstants::RenderGraphEntityNames::SCREEN_SPACE_PASS.data(), {"Scene", "Entity ID"}, {SHGraphicsConstants::RenderGraphEntityNames::DEFERRED_COMPOSITE_PASS.data(), SHGraphicsConstants::RenderGraphEntityNames::GBUFFER_PASS.data(), SHGraphicsConstants::RenderGraphEntityNames::DEBUG_DRAW.data()}); auto uiSubpass = screenSpaceNode->AddSubpass("UI", worldViewport, screenRenderer); uiSubpass->AddColorOutput("Scene"); uiSubpass->AddColorOutput("Entity ID"); @@ -330,16 +330,16 @@ namespace SHADE #ifdef SHEDITOR { // Dummy Node to transition scene render graph resource - auto dummyNode = renderGraph->AddNode("Dummy Pass", { "Scene" }, { SHGraphicsConstants::RenderGraphNodeNames::SCREEN_SPACE_PASS .data()}); + auto dummyNode = renderGraph->AddNode("Dummy Pass", { "Scene" }, { SHGraphicsConstants::RenderGraphEntityNames::SCREEN_SPACE_PASS .data()}); auto dummySubpass = dummyNode->AddSubpass("Dummy Subpass", {}, {}); dummySubpass->AddInput("Scene"); - auto imGuiNode = renderGraph->AddNode(SHGraphicsConstants::RenderGraphNodeNames::IMGUI_PASS.data(), {"Present"}, {}); + auto imGuiNode = renderGraph->AddNode(SHGraphicsConstants::RenderGraphEntityNames::IMGUI_PASS.data(), {"Present"}, {}); auto imGuiSubpass = imGuiNode->AddSubpass("ImGui Draw", {}, {}); imGuiSubpass->AddColorOutput("Present"); } #else - renderGraph->AddRenderToSwapchainNode("Scene", "Present", { SHGraphicsConstants::RenderGraphNodeNames::SCREEN_SPACE_PASS .data()}, {renderToSwapchainVS, renderToSwapchainFS}); + renderGraph->AddRenderToSwapchainNode("Scene", "Present", { SHGraphicsConstants::RenderGraphEntityNames::SCREEN_SPACE_PASS .data()}, {renderToSwapchainVS, renderToSwapchainFS}); #endif @@ -417,7 +417,7 @@ namespace SHADE textRenderingSubSystem = resourceManager.Create(); // initialize the text renderer - auto uiNode = renderGraph->GetNode(SHGraphicsConstants::RenderGraphNodeNames::SCREEN_SPACE_PASS.data()); + auto uiNode = renderGraph->GetNode(SHGraphicsConstants::RenderGraphEntityNames::SCREEN_SPACE_PASS.data()); textRenderingSubSystem->Init(device, uiNode->GetRenderpass(), uiNode->GetSubpass("UI"), descPool, textVS, textFS); SHGlobalDescriptorSets::SetLightingSubSystem(lightingSubSystem); @@ -444,7 +444,7 @@ namespace SHADE defaultMaterial = AddMaterial ( defaultVertShader, defaultFragShader, - renderGraph->GetNode(SHGraphicsConstants::RenderGraphNodeNames::GBUFFER_PASS.data())->GetSubpass("G-Buffer Write") + renderGraph->GetNode(SHGraphicsConstants::RenderGraphEntityNames::GBUFFER_PASS.data())->GetSubpass("G-Buffer Write") ); defaultMaterial->SetProperty("data.textureIndex", defaultTexture->TextureArrayIndex); } @@ -762,7 +762,7 @@ namespace SHADE auto const& EVENT_DATA = reinterpret_cast*>(eventPtr.get())->data; auto* lightComp = SHComponentManager::GetComponent(EVENT_DATA->lightEntity); std::string resourceName = "ShadowMap " + std::to_string(EVENT_DATA->lightEntity); - Handle companionSubpass = renderGraph->GetNode(SHGraphicsConstants::RenderGraphNodeNames::GBUFFER_PASS.data())->GetSubpass("G-Buffer Write"); + Handle companionSubpass = renderGraph->GetNode(SHGraphicsConstants::RenderGraphEntityNames::GBUFFER_PASS.data())->GetSubpass("G-Buffer Write"); if (EVENT_DATA->generateRenderer) { @@ -772,16 +772,16 @@ namespace SHADE } // Add the shadow map resource to the graph - renderGraph->AddResource(resourceName, {SH_RENDER_GRAPH_RESOURCE_FLAGS::DEPTH_STENCIL, SH_RENDER_GRAPH_RESOURCE_FLAGS::INPUT}, resizeWidth, resizeHeight, vk::Format::eD24UnormS8Uint); + renderGraph->AddResource(resourceName, {SH_RENDER_GRAPH_RESOURCE_FLAGS::DEPTH, SH_RENDER_GRAPH_RESOURCE_FLAGS::INPUT}, resizeWidth, resizeHeight, vk::Format::eD32Sfloat); // link resource to node. This means linking the resource and regenerating the node's renderpass and framebuffer. //auto shadowMapNode = renderGraph->GetNode(SHGraphicsConstants::RenderGraphNodeNames::SHADOW_MAP_PASS.data()); - auto shadowMapNode = renderGraph->AddNodeAfter(SHGraphicsConstants::RenderGraphNodeNames::SHADOW_MAP_PASS.data() + resourceName, {resourceName.c_str()}, SHGraphicsConstants::RenderGraphNodeNames::GBUFFER_PASS.data()); + auto shadowMapNode = renderGraph->AddNodeAfter(SHGraphicsConstants::RenderGraphEntityNames::SHADOW_MAP_PASS.data() + resourceName, {resourceName.c_str()}, SHGraphicsConstants::RenderGraphEntityNames::GBUFFER_PASS.data()); // Add a subpass to render to that shadow map auto newSubpass = shadowMapNode->RuntimeAddSubpass(resourceName + " Subpass", worldViewport, lightComp->GetRenderer()); //auto newSubpass = shadowMapNode->RuntimeAddSubpass(resourceName + " Subpass", worldViewport, lightComp->GetRenderer()); - newSubpass->AddDepthOutput(resourceName, SH_RENDER_GRAPH_RESOURCE_FLAGS::DEPTH_STENCIL); + newSubpass->AddDepthOutput(resourceName, SH_RENDER_GRAPH_RESOURCE_FLAGS::DEPTH); // regenerate the node shadowMapNode->RuntimeStandaloneRegenerate(); @@ -791,7 +791,7 @@ namespace SHADE if (!shadowMapPipeline) { SHPipelineLibrary tempLibrary{}; - Handle rgNode = renderGraph->GetNode(SHGraphicsConstants::RenderGraphNodeNames::SHADOW_MAP_PASS.data()); + Handle rgNode = renderGraph->GetNode(SHGraphicsConstants::RenderGraphEntityNames::SHADOW_MAP_PASS.data()); tempLibrary.Init(device); tempLibrary.CreateGraphicsPipelines({ shadowMapVS, {} }, shadowMapNode->GetRenderpass(), newSubpass, SHGraphicsPredefinedData::GetShadowMapViState()); @@ -799,6 +799,12 @@ namespace SHADE } newSubpass->SetCompanionSubpass(companionSubpass, shadowMapPipeline); // set companion subpass and pipeline + // add the shadow map to the lighting system + uint32_t const NEW_SHADOW_MAP_INDEX = lightingSubSystem->AddShadowMap(renderGraph->GetRenderGraphResource(resourceName), EVENT_DATA->lightEntity); + + auto nodeCompute = renderGraph->GetNode(SHGraphicsConstants::RenderGraphEntityNames::DEFERRED_COMPOSITE_PASS.data())->GetNodeCompute(SHGraphicsConstants::RenderGraphEntityNames::DEFERRED_COMPOSITE_COMPUTE.data()); + nodeCompute->ModifyWriteDescImageComputeResource(SHGraphicsConstants::DescriptorSetBindings::SHADOW_MAP_IMAGE_SAMPLER_DATA, lightingSubSystem->GetViewSamplerLayout(NEW_SHADOW_MAP_INDEX), NEW_SHADOW_MAP_INDEX); + return eventPtr->handle; } @@ -1142,7 +1148,7 @@ namespace SHADE Handle SHGraphicsSystem::GetPrimaryRenderpass() const noexcept { - return renderGraph->GetNode(SHGraphicsConstants::RenderGraphNodeNames::GBUFFER_PASS.data()); + return renderGraph->GetNode(SHGraphicsConstants::RenderGraphEntityNames::GBUFFER_PASS.data()); } Handle SHGraphicsSystem::GetDebugDrawPipeline(DebugDrawPipelineType type) const noexcept diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightingSubSystem.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightingSubSystem.cpp index 88dc0f48..8a2fb3e3 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightingSubSystem.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightingSubSystem.cpp @@ -459,14 +459,14 @@ namespace SHADE #pragma endregion #pragma region SHADOWS - std::vector shadowDescVariableSizes{ MAX_SHADOWS }; - shadowMapDescriptorSet = descPool->Allocate({SHGraphicsPredefinedData::GetPredefinedDescSetLayouts(SHGraphicsPredefinedData::PredefinedDescSetLayoutTypes::SHADOW)}, shadowDescVariableSizes); + //std::vector shadowDescVariableSizes{ MAX_SHADOWS }; + //shadowMapDescriptorSet = descPool->Allocate({SHGraphicsPredefinedData::GetPredefinedDescSetLayouts(SHGraphicsPredefinedData::PredefinedDescSetLayoutTypes::SHADOW)}, shadowDescVariableSizes); -#ifdef _DEBUG - const auto& SHADOW_MAP_DESC_SETS = shadowMapDescriptorSet->GetVkHandle(); - for (int i = 0; i < static_cast(SHADOW_MAP_DESC_SETS.size()); ++i) - SET_VK_OBJ_NAME(logicalDevice, vk::ObjectType::eDescriptorSet, SHADOW_MAP_DESC_SETS[i], "[Descriptor Set] Shadow Map Data Frame #" + std::to_string(i)); -#endif +//#ifdef _DEBUG +// const auto& SHADOW_MAP_DESC_SETS = shadowMapDescriptorSet->GetVkHandle(); +// for (int i = 0; i < static_cast(SHADOW_MAP_DESC_SETS.size()); ++i) +// SET_VK_OBJ_NAME(logicalDevice, vk::ObjectType::eDescriptorSet, SHADOW_MAP_DESC_SETS[i], "[Descriptor Set] Shadow Map Data Frame #" + std::to_string(i)); +//#endif shadowMapSampler = inShadowMapSampler; //numLightComponents = 0; @@ -583,7 +583,7 @@ namespace SHADE } - void SHLightingSubSystem::AddShadowMap(Handle newShadowMap, EntityID lightEntity) noexcept + uint32_t SHLightingSubSystem::AddShadowMap(Handle newShadowMap, EntityID lightEntity) noexcept { // Add to container of shadow maps shadowMaps.emplace(lightEntity, newShadowMap); @@ -595,26 +595,28 @@ namespace SHADE shadowMapImageSamplers.emplace_back(NEW_IMAGE_VIEW, shadowMapSampler, vk::ImageLayout::eShaderReadOnlyOptimal); // Update descriptor set - static constexpr uint32_t SHADOW_MAP_DESC_SET_INDEX = 0; - uint32_t const SHADOW_MAP_DESC_ARRAY_INDEX = static_cast(shadowMapImageSamplers.size()) - 1u; - shadowMapDescriptorSet->ModifyWriteDescImage - ( - SHADOW_MAP_DESC_SET_INDEX, - SHGraphicsConstants::DescriptorSetBindings::SHADOW_MAP_IMAGE_SAMPLER_DATA, - shadowMapImageSamplers[SHADOW_MAP_DESC_ARRAY_INDEX], - SHADOW_MAP_DESC_ARRAY_INDEX - ); + //static constexpr uint32_t SHADOW_MAP_DESC_SET_INDEX = 0; + //uint32_t const SHADOW_MAP_DESC_ARRAY_INDEX = static_cast(shadowMapImageSamplers.size()) - 1u; + //shadowMapDescriptorSet->ModifyWriteDescImage + //( + // SHADOW_MAP_DESC_SET_INDEX, + // SHGraphicsConstants::DescriptorSetBindings::SHADOW_MAP_IMAGE_SAMPLER_DATA, + // shadowMapImageSamplers[SHADOW_MAP_DESC_ARRAY_INDEX], + // SHADOW_MAP_DESC_ARRAY_INDEX + //); - // TODO: Definitely can be optimized by writing a function that modifies a specific descriptor in the array - shadowMapDescriptorSet->UpdateDescriptorSetImages - ( - SHADOW_MAP_DESC_SET_INDEX, - SHGraphicsConstants::DescriptorSetBindings::SHADOW_MAP_IMAGE_SAMPLER_DATA - ); + //// TODO: Definitely can be optimized by writing a function that modifies a specific descriptor in the array + //shadowMapDescriptorSet->UpdateDescriptorSetImages + //( + // SHADOW_MAP_DESC_SET_INDEX, + // SHGraphicsConstants::DescriptorSetBindings::SHADOW_MAP_IMAGE_SAMPLER_DATA + //); // add to barriers shadowMapMemoryBarriers.push_back (vk::ImageMemoryBarrier { + .srcAccessMask = vk::AccessFlagBits::eDepthStencilAttachmentWrite, + .dstAccessMask = vk::AccessFlagBits::eShaderRead, .oldLayout = vk::ImageLayout::eDepthAttachmentOptimal, .newLayout = vk::ImageLayout::eShaderReadOnlyOptimal, .srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED, @@ -629,6 +631,9 @@ namespace SHADE .layerCount = 1, } }); + + // return new index of shadow map + return static_cast(shadowMapImageSamplers.size()) - 1u; } void SHLightingSubSystem::PrepareShadowMapsForRead(Handle cmdBuffer) noexcept @@ -642,4 +647,9 @@ namespace SHADE return lightingDataDescSet; } + std::tuple, Handle, vk::ImageLayout> const& SHLightingSubSystem::GetViewSamplerLayout(uint32_t index) const noexcept + { + return shadowMapImageSamplers[index]; + } + } diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightingSubSystem.h b/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightingSubSystem.h index d1b9e003..3cc5bac8 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightingSubSystem.h +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightingSubSystem.h @@ -70,11 +70,15 @@ namespace SHADE { public: using DynamicOffsetArray = std::array, static_cast(SHGraphicsConstants::NUM_FRAME_BUFFERS)>; + static constexpr uint32_t MAX_SHADOWS = 200; private: class PerTypeData { + public: + + private: /*-----------------------------------------------------------------------*/ /* STATIC MEMBER VARIABLES */ @@ -137,7 +141,6 @@ namespace SHADE /* STATIC MEMBER VARIABLES */ /*-----------------------------------------------------------------------*/ - static constexpr uint32_t MAX_SHADOWS = 200; //! logical device used for creation Handle logicalDevice; @@ -174,7 +177,7 @@ namespace SHADE //! Descriptor sets required to be given to the compute shader for shadow calculation. This will be a descriptor array. //! It will also be preallocated. - Handle shadowMapDescriptorSet; + //Handle shadowMapDescriptorSet; //! Combined image samplers for the texture descriptors std::vector, Handle, vk::ImageLayout>> shadowMapImageSamplers; @@ -205,7 +208,7 @@ namespace SHADE void Run (SHMatrix const& viewMat, uint32_t frameIndex) noexcept; void Exit (void) noexcept; void BindDescSet (Handle cmdBuffer, uint32_t setIndex, uint32_t frameIndex) noexcept; - void AddShadowMap (Handle newShadowMap, EntityID lightEntity) noexcept; + uint32_t AddShadowMap (Handle newShadowMap, EntityID lightEntity) noexcept; void PrepareShadowMapsForRead (Handle cmdBuffer) noexcept; //void RemoveShadowMap (uint32_t index) noexcept; @@ -213,6 +216,7 @@ namespace SHADE /* SETTERS AND GETTERS */ /*-----------------------------------------------------------------------*/ Handle GetLightDataDescriptorSet (void) const noexcept; + std::tuple, Handle, vk::ImageLayout> const& GetViewSamplerLayout (uint32_t index) const noexcept; }; } diff --git a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNode.cpp b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNode.cpp index fca003aa..ff540ce1 100644 --- a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNode.cpp +++ b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNode.cpp @@ -442,7 +442,7 @@ namespace SHADE return subpass; } - Handle SHRenderGraphNode::AddNodeCompute(std::string nodeName, Handle computeShaderModule, std::initializer_list resources, std::unordered_set&& dynamicBufferBindings, Handle customComputeLayout/* = {}*/, float numWorkGroupScale/* = 1.0f*/) noexcept + Handle SHRenderGraphNode::AddNodeCompute(std::string nodeName, Handle computeShaderModule, std::initializer_list resources, std::unordered_set&& dynamicBufferBindings, uint32_t variableDescCount/* = 0*/, float numWorkGroupScale/* = 1.0f*/) noexcept { // Look for the required resources in the graph std::vector> nodeComputeResources{}; @@ -458,7 +458,7 @@ namespace SHADE std::vector> temp (nodeComputeResources); // Create the subpass compute with the resources - auto nodeCompute = graphStorage->resourceHub->Create(std::move(nodeName), graphStorage, computeShaderModule, std::move(nodeComputeResources), std::move (dynamicBufferBindings), nodeComputes.empty(), customComputeLayout); + auto nodeCompute = graphStorage->resourceHub->Create(std::move(nodeName), graphStorage, computeShaderModule, std::move(nodeComputeResources), std::move (dynamicBufferBindings), nodeComputes.empty(), variableDescCount); nodeComputes.push_back(nodeCompute); for (auto& resource : temp) @@ -810,4 +810,15 @@ namespace SHADE return attResources; } + Handle SHRenderGraphNode::GetNodeCompute(std::string nodeComputeName) const noexcept + { + for (auto nc : nodeComputes) + { + if (nc->name == nodeComputeName) + return nc; + } + + return {}; + } + } \ No newline at end of file diff --git a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNode.h b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNode.h index 27fdaa19..b070b8fa 100644 --- a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNode.h +++ b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNode.h @@ -109,7 +109,7 @@ namespace SHADE /* PUBLIC MEMBER FUNCTIONS */ /*-----------------------------------------------------------------------*/ Handle AddSubpass(std::string subpassName, Handle viewport, Handle renderer) noexcept; - Handle AddNodeCompute(std::string nodeName, Handle computeShaderModule, std::initializer_list resources, std::unordered_set&& dynamicBufferBindings = {}, Handle customComputeLayout = {}, float numWorkGroupScale = 1.0f) noexcept; + Handle AddNodeCompute(std::string nodeName, Handle computeShaderModule, std::initializer_list resources, std::unordered_set&& dynamicBufferBindings = {}, uint32_t variableDescCount = 0, float numWorkGroupScale = 1.0f) noexcept; void Execute(Handle commandBuffer, Handle descPool, uint32_t frameIndex) noexcept; Handle GetOrCreatePipeline(std::pair, Handle> const& vsFsPair, Handle subpass) noexcept; @@ -127,6 +127,7 @@ namespace SHADE Handle GetSubpass(std::string_view subpassName) const noexcept; Handle GetResource (uint32_t resourceIndex) const noexcept; std::vector> const& GetResources (void) const noexcept; + Handle GetNodeCompute (std::string nodeComputeName) const noexcept; friend class SHRenderGraph; }; diff --git a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNodeCompute.cpp b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNodeCompute.cpp index 55f8a9c9..ef1b6b03 100644 --- a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNodeCompute.cpp +++ b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNodeCompute.cpp @@ -63,7 +63,7 @@ namespace SHADE } - SHRenderGraphNodeCompute::SHRenderGraphNodeCompute(std::string nodeName, Handle graphStorage, Handle computeShaderModule, std::vector>&& subpassComputeResources, std::unordered_set&& dynamicBufferBindings, bool followingEndRP, Handle customComputeLayout, float inNumWorkGroupScale/* = 1.0f*/) noexcept + SHRenderGraphNodeCompute::SHRenderGraphNodeCompute(std::string nodeName, Handle graphStorage, Handle computeShaderModule, std::vector>&& subpassComputeResources, std::unordered_set&& dynamicBufferBindings, bool followingEndRP, uint32_t variableDescCount, float inNumWorkGroupScale/* = 1.0f*/) noexcept : computePipeline{} , pipelineLayout{} , resources{} @@ -118,21 +118,11 @@ namespace SHADE if (layouts.size() == descMappings.at(SHPredefinedDescriptorTypes::RENDER_GRAPH_NODE_COMPUTE_RESOURCE) + 1) { Handle computeResourceLayout = {}; - uint32_t variableCounts = 0; - if (customComputeLayout) - { - // Just use the descriptor counts in bindings as the variable descriptor counts - auto const& bindings = customComputeLayout->GetBindings(); - variableCounts = bindings.back().DescriptorCount; - computeResourceLayout = customComputeLayout; - } - else computeResourceLayout = layouts[descMappings.at(SHPredefinedDescriptorTypes::RENDER_GRAPH_NODE_COMPUTE_RESOURCE)]; - // create compute resources computeResource = graphStorage->resourceHub->Create(); - computeResource->descSet = graphStorage->descriptorPool->Allocate({ computeResourceLayout }, {variableCounts}); + computeResource->descSet = graphStorage->descriptorPool->Allocate({ computeResourceLayout }, {variableDescCount}); #ifdef _DEBUG for (auto set : computeResource->descSet->GetVkHandle()) SET_VK_OBJ_NAME(graphStorage->logicalDevice, vk::ObjectType::eDescriptorSet, set, "[Descriptor Set] " + name + " Resources"); @@ -257,6 +247,14 @@ namespace SHADE } + void SHRenderGraphNodeCompute::ModifyWriteDescImageComputeResource(uint32_t binding, SHVkDescriptorSetGroup::viewSamplerLayout const& viewSamplerLayout, uint32_t descArrayIndex) noexcept + { + static constexpr uint32_t COMPUTE_RESOURCE_SET_INDEX = 0; + computeResource->descSet->ModifyWriteDescImage(COMPUTE_RESOURCE_SET_INDEX, binding, viewSamplerLayout, descArrayIndex); + computeResource->descSet->UpdateDescriptorSetImage(COMPUTE_RESOURCE_SET_INDEX, binding, descArrayIndex); + + } + void SHRenderGraphNodeCompute::AddPreComputeFunction(PreComputeFunction const& fn) noexcept { preComputeFunctions.push_back(fn); diff --git a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNodeCompute.h b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNodeCompute.h index 9352f1d9..83bc5d33 100644 --- a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNodeCompute.h +++ b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNodeCompute.h @@ -93,7 +93,7 @@ namespace SHADE void SetFollowingEndRenderpass (uint32_t flag) noexcept; public: - SHRenderGraphNodeCompute(std::string nodeName, Handle graphStorage, Handle computeShaderModule, std::vector>&& subpassComputeResources, std::unordered_set&& dynamicBufferBindings, bool followingEndRP, Handle customComputeLayout, float inNumWorkGroupScale = 1.0f) noexcept; + SHRenderGraphNodeCompute(std::string nodeName, Handle graphStorage, Handle computeShaderModule, std::vector>&& subpassComputeResources, std::unordered_set&& dynamicBufferBindings, bool followingEndRP, uint32_t variableDescCount, float inNumWorkGroupScale = 1.0f) noexcept; void Execute (Handle cmdBuffer, uint32_t frameIndex) noexcept; void HandleResize (void) noexcept; @@ -103,6 +103,7 @@ namespace SHADE void ModifyWriteDescBufferComputeResource (uint32_t binding, std::span> const& buffers, uint32_t offset, uint32_t range) noexcept; void ModifyWriteDescImageComputeResource(uint32_t binding, std::span const& viewSamplerLayouts) noexcept; + void ModifyWriteDescImageComputeResource(uint32_t binding, SHVkDescriptorSetGroup::viewSamplerLayout const& viewSamplerLayout, uint32_t descArrayIndex) noexcept; void AddPreComputeFunction (PreComputeFunction const& fn) noexcept; diff --git a/SHADE_Engine/src/Graphics/RenderGraph/SHSubpass.cpp b/SHADE_Engine/src/Graphics/RenderGraph/SHSubpass.cpp index c4d645db..5205b44d 100644 --- a/SHADE_Engine/src/Graphics/RenderGraph/SHSubpass.cpp +++ b/SHADE_Engine/src/Graphics/RenderGraph/SHSubpass.cpp @@ -164,7 +164,7 @@ namespace SHADE switch (attachmentDescriptionType) { case SH_RENDER_GRAPH_RESOURCE_FLAGS::DEPTH: - imageLayout = vk::ImageLayout::eDepthAttachmentOptimal; + imageLayout = vk::ImageLayout::eDepthStencilAttachmentOptimal; break; case SH_RENDER_GRAPH_RESOURCE_FLAGS::STENCIL: imageLayout = vk::ImageLayout::eStencilAttachmentOptimal; @@ -299,6 +299,8 @@ namespace SHADE if (inputReferences[i].attachment == attachmentIndex) return true; } + + return false; } bool SHSubpass::HasNoAttachments(void) const noexcept From 88491ffbd80c4b022a1c91dfe91e7024c36cae51 Mon Sep 17 00:00:00 2001 From: maverickdgg Date: Mon, 9 Jan 2023 09:56:46 +0800 Subject: [PATCH 25/45] ToggleButton fix --- Assets/Scenes/UI Test.shade.shmeta | 2 +- SHADE_Engine/src/UI/SHUISystem.cpp | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/Assets/Scenes/UI Test.shade.shmeta b/Assets/Scenes/UI Test.shade.shmeta index e65c0b8f..ad821810 100644 --- a/Assets/Scenes/UI Test.shade.shmeta +++ b/Assets/Scenes/UI Test.shade.shmeta @@ -1,3 +1,3 @@ Name: UI Test -ID: 96041206 +ID: 88543249 Type: 5 diff --git a/SHADE_Engine/src/UI/SHUISystem.cpp b/SHADE_Engine/src/UI/SHUISystem.cpp index 571eb167..95663bc0 100644 --- a/SHADE_Engine/src/UI/SHUISystem.cpp +++ b/SHADE_Engine/src/UI/SHUISystem.cpp @@ -161,7 +161,9 @@ namespace SHADE windowSize = SHEditorWindowManager::GetEditorWindow()->windowSize; mousePos = SHEditorWindowManager::GetEditorWindow()->viewportMousePos; //mousePos.y = windowSize.y - mousePos.y; + SHLOG_INFO("mouse pos: {}, {}", mousePos.x, mousePos.y) mousePos /= windowSize; + SHLOG_INFO("mouse pos normalized: {}, {}", mousePos.x, mousePos.y) #endif SHVec2 camSize{ cameraSystem->GetCameraWidthHeight(0)}; @@ -169,6 +171,7 @@ namespace SHADE topExtent = CanvasToScreenPoint(topExtent); btmExtent = CanvasToScreenPoint(btmExtent); + //SHLOG_INFO("TopExtent: {}, {} Btm Extent: {}, {}", topExtent.x, topExtent.y, btmExtent.x, btmExtent.y) topExtent /= camSize; btmExtent /= camSize; @@ -210,8 +213,9 @@ namespace SHADE auto cameraSystem = SHSystemManager::GetSystem(); auto uiComp = SHComponentManager::GetComponent(comp.GetEID()); - SHVec4 topExtent4 = uiComp->GetMatrix() * SHVec4(-comp.size.x * 0.5f, comp.size.y * 0.5f, 0.0f, 1.0f); - SHVec4 btmExtent4 = uiComp->GetMatrix() * SHVec4(comp.size.x * 0.5f, -comp.size.y * 0.5f, 0.0f, 1.0f); + SHVec4 topExtent4 = SHMatrix::Translate(-comp.size.x * 0.5f, comp.size.y * 0.5f, 0.0f) * uiComp->GetMatrix() * SHVec4(0.0f, 0.0f, 0.0f, 1.0f); + SHVec4 btmExtent4 = SHMatrix::Translate(comp.size.x * 0.5f, -comp.size.y * 0.5f, 0.0f) * uiComp->GetMatrix() * SHVec4(0.0f, 0.0f, 0.0f, 1.0f); + SHVec2 topExtent{ topExtent4.x,topExtent4.y }; SHVec2 btmExtent{ btmExtent4.x,btmExtent4.y }; From 4f63558f4021d2fea154b59f83cfa0ec77022bae Mon Sep 17 00:00:00 2001 From: maverickdgg Date: Mon, 9 Jan 2023 10:44:36 +0800 Subject: [PATCH 26/45] Added GetComponents to Component Manager --- .../ECS_Base/Managers/SHComponentManager.h | 28 ++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/SHADE_Engine/src/ECS_Base/Managers/SHComponentManager.h b/SHADE_Engine/src/ECS_Base/Managers/SHComponentManager.h index 8921fbce..9fcbf6f8 100644 --- a/SHADE_Engine/src/ECS_Base/Managers/SHComponentManager.h +++ b/SHADE_Engine/src/ECS_Base/Managers/SHComponentManager.h @@ -23,7 +23,7 @@ #include "SH_API.h" #include "Events/SHEventManager.hpp" - +#include #include namespace SHADE @@ -151,6 +151,32 @@ namespace SHADE return (componentSet.GetSparseSet()->GetElement_s(EntityHandleGenerator::GetIndex(entityID))); } + /*!************************************************************************* + * \brief + * Gets the Component of the entity with the specified entityID + * + * This is the safe version of GetComponent_s which does a HasComponent to make + * sure that the entity has such a component and returns nullptr if it doesn't + * + * This safe version also checks if the sparse set of this component type + * has been created in SHComponentManager and creates one if it doesn't + * + * @tparam T... + * Pack of Types for all the Components to get. + * \param entityID + * EntityID of the entity that we are trying to get the component of. + * \return + * A tuple of pointers to all the components specified. + * Returns nullptr if the entity does not contain such a component. + ***************************************************************************/ + + template + static std::enable_if_t<(... && std::is_base_of_v), std::tuple> GetComponents(EntityID entityID) noexcept + { + return std::make_tuple(GetComponent_s(entityID)...); + } + + /*!************************************************************************* * \brief * Gets the Component of the entity with the specified entityID From 28829213c9a310d9dd7719746f2b97bed252fe4a Mon Sep 17 00:00:00 2001 From: maverickdgg Date: Mon, 9 Jan 2023 10:53:56 +0800 Subject: [PATCH 27/45] merge --- Assets/Scenes/UI_Test.shade.shmeta | 4 ++-- SHADE_Engine/src/Serialization/SHSerialization.cpp | 2 +- SHADE_Engine/src/UI/SHUISystem.cpp | 10 +++++----- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Assets/Scenes/UI_Test.shade.shmeta b/Assets/Scenes/UI_Test.shade.shmeta index ad821810..f32277e0 100644 --- a/Assets/Scenes/UI_Test.shade.shmeta +++ b/Assets/Scenes/UI_Test.shade.shmeta @@ -1,3 +1,3 @@ -Name: UI Test -ID: 88543249 +Name: UI_Test +ID: 97161771 Type: 5 diff --git a/SHADE_Engine/src/Serialization/SHSerialization.cpp b/SHADE_Engine/src/Serialization/SHSerialization.cpp index e92a4d5f..a055d91c 100644 --- a/SHADE_Engine/src/Serialization/SHSerialization.cpp +++ b/SHADE_Engine/src/Serialization/SHSerialization.cpp @@ -350,7 +350,7 @@ namespace SHADE SHSerializationHelper::InitializeComponentFromNode(componentsNode, eid); SHSerializationHelper::InitializeComponentFromNode(componentsNode, eid); SHSerializationHelper::InitializeComponentFromNode(componentsNode, eid); - SHSerializationHelper::ConvertNodeToComponent(componentsNode, eid); + //SHSerializationHelper::ConvertNodeToComponent(componentsNode, eid); SHSerializationHelper::InitializeComponentFromNode(componentsNode, eid); SHSerializationHelper::InitializeComponentFromNode(componentsNode, eid); } diff --git a/SHADE_Engine/src/UI/SHUISystem.cpp b/SHADE_Engine/src/UI/SHUISystem.cpp index 95663bc0..4d175e5f 100644 --- a/SHADE_Engine/src/UI/SHUISystem.cpp +++ b/SHADE_Engine/src/UI/SHUISystem.cpp @@ -161,9 +161,9 @@ namespace SHADE windowSize = SHEditorWindowManager::GetEditorWindow()->windowSize; mousePos = SHEditorWindowManager::GetEditorWindow()->viewportMousePos; //mousePos.y = windowSize.y - mousePos.y; - SHLOG_INFO("mouse pos: {}, {}", mousePos.x, mousePos.y) - mousePos /= windowSize; - SHLOG_INFO("mouse pos normalized: {}, {}", mousePos.x, mousePos.y) + //SHLOG_INFO("mouse pos: {}, {}", mousePos.x, mousePos.y) + //mousePos /= windowSize; + //SHLOG_INFO("mouse pos normalized: {}, {}", mousePos.x, mousePos.y) #endif SHVec2 camSize{ cameraSystem->GetCameraWidthHeight(0)}; @@ -172,8 +172,8 @@ namespace SHADE topExtent = CanvasToScreenPoint(topExtent); btmExtent = CanvasToScreenPoint(btmExtent); //SHLOG_INFO("TopExtent: {}, {} Btm Extent: {}, {}", topExtent.x, topExtent.y, btmExtent.x, btmExtent.y) - topExtent /= camSize; - btmExtent /= camSize; + //topExtent /= camSize; + //btmExtent /= camSize; comp.isClicked = false; if (mousePos.x >= topExtent.x && mousePos.x <= btmExtent.x From cb9223db0bc3f636650542ee3c12c38d50f69573 Mon Sep 17 00:00:00 2001 From: Brandon Mak Date: Mon, 9 Jan 2023 11:06:10 +0800 Subject: [PATCH 28/45] Enabled partially bound bit for descriptor sets with variable size - Shadow maps can be sampled from compute shaders --- Assets/Shaders/DeferredComposite_CS.glsl | 12 ++++++++++++ Assets/Shaders/DeferredComposite_CS.shshaderb | Bin 5749 -> 6529 bytes .../Graphics/Devices/SHVkLogicalDevice.cpp | 1 + .../MiddleEnd/Interface/SHGraphicsSystem.cpp | 6 ------ .../MiddleEnd/Lights/SHLightingSubSystem.cpp | 8 ++++++++ .../MiddleEnd/Lights/SHLightingSubSystem.h | 5 +++-- .../Graphics/Pipeline/SHVkPipelineLayout.cpp | 2 +- 7 files changed, 25 insertions(+), 9 deletions(-) diff --git a/Assets/Shaders/DeferredComposite_CS.glsl b/Assets/Shaders/DeferredComposite_CS.glsl index e73ea9eb..2402d4f8 100644 --- a/Assets/Shaders/DeferredComposite_CS.glsl +++ b/Assets/Shaders/DeferredComposite_CS.glsl @@ -7,6 +7,7 @@ struct DirectionalLightStruct uint cullingMask; vec4 diffuseColor; mat4 pvMatrix; + uint shadowData; }; struct AmbientLightStruct @@ -65,6 +66,8 @@ void main() vec3 fragColor = vec3 (0.0f); + vec4 shadowMapColor = vec4 (1.0f); + for (int i = 0; i < lightCounts.directionalLights; ++i) { if ((lightLayer & DirLightData.dLightData[i].cullingMask) != 0) @@ -77,6 +80,13 @@ void main() // Calculate the fragment color fragColor += DirLightData.dLightData[i].diffuseColor.rgb * diffuseStrength.rrr * pixelDiffuse; + + if ((DirLightData.dLightData[i].shadowData & uint(1)) == 1) + { + // calculate shadow map here + vec2 texCoord = vec2 (gl_GlobalInvocationID.xy) / vec2 (imageSize (targetImage)); + shadowMapColor = texture (shadowMaps[0], texCoord).xxxx; + } } } @@ -95,6 +105,8 @@ void main() // store result into result image imageStore(targetImage, ivec2(gl_GlobalInvocationID.xy), vec4(fragColor.rgb, 1.0f)); + + imageStore(targetImage, ivec2(gl_GlobalInvocationID.xy), shadowMapColor); //imageStore(targetImage, ivec2(gl_GlobalInvocationID.xy), vec4(ssaoVal.rrr, 1.0f)); } \ No newline at end of file diff --git a/Assets/Shaders/DeferredComposite_CS.shshaderb b/Assets/Shaders/DeferredComposite_CS.shshaderb index df956040e255167463b8ea8206fcc2b8074e10fb..fc527efa0308db8d380e4a8cfabff95cb1ce335b 100644 GIT binary patch literal 6529 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 literal 5749 zcmZve`*&Sc5ywxPXK4$q6sXYFl=uL_Qjr3swwN}MMpF`OtxpUm$!&7mn|tHEH*JHc zMFqqMzEJT^u|7dW@rlpnFaAfq)^aUBpL6!4hc0&4bY{LYduI0R*(Z0XadlR#p0&dR zS+*v-EZdmw0 zKV8#ru;N#5&Ni0kst$d4RP*jQf#=CJ9>lFKLL2uOO7rGPqO08Yyxb+p-Xx`1s9DBh}wDb8xtwsx1 z_V;A_;q^l9%kG6w80%1Lx!LVd?O=fcXQ{2NX5J`Vtg)Ye?(y!ITJ>f(SpxUII!mp9 z@g6Aroq~LEre0g!QPy`Dyf{nBZ{MfDM$0Q*&3&}nUY_li`L(-N>q9obxOLS#BWW5g z;?_00++bYhkK~yIq?bU(DxgK-l`S=i%MFJzwjVu-ISqU&!ZLXO84c4C@#%{l2V+ zwn6H?&Fdl068cVL&#XQSuiDkMyR`cjt9EtmYm(h}ShcHbH{W4u^zFEe>k7>MV$NJ( z)+9Dq!Hgre0U9H!@$|Dc-;%kb7IkyGj2Z97{jR_ww=n~Y+?y&`sp3Aze*V%N%{=ni~aR&Y3Tw9RC z&phtk3YqUQxb+P|`otVZeCrc)pZ?BswLW$0vlrSgBzyR)SMAQS`@^oT-M+g2Wwy$><%L+H+!n56$@1ngZ<#PVlGnb$L}EABzNv8u~jJ+t}kh08lLzq)VR zWsdD|W9VDC6~U& zRQDUpz`j^Qh0lJ+nOu|C7iuXQz;jZ!KZ>$JiRkp7?!;xw%+(Pw_p_ zX1$NYAA`*I8MyJptXJK)AH8}y$=2h1JPTJgUv=s4dokt@l0jc%s$WQ$x^wRL!R5TX z0Jm0ScqZe&1ZCN|yVbS*9@+$j{s&}haDIHhFGKoB+N|}D@K>ufYQK(N{0SfZwvp%0 zaCP^4j=#WN;?}M1cgl4;UpDJ?R$SiCzd`)o>Fc*>9pqiA`+e}Yc2ys`M8Bb;`z~*( z=`VJKN-iv+=GM~2NQ0#plvi5(Z9=#vgc;e5cT0Vd* zeh2g~di5c=%eu6E5E8R4<*4Jsg} zjjvA)5)1tVvUBnjb#H;sL;8qspci5bka6|93)08feh0Kg?e#(~Yd?kDfTDJ7CkuP| z`(rWLV~(5XVv@^zYawG>LklwBR66TY!o;OVso(Q`1TvQPIAa^xw;VnlWc|d$r;F@7 zKa%1sBa7)9vo7ZR#=Xha55m1idGz9RA!pe+;yK@EA+a-%@q900)%P-zY%2vXZ4V(E zTkczW82&NH<=&6OwaX*-CyRb9Oy7}WReGd5v$l29)5{kW_N7f#1=?lol6OXs_B(iwCr7t17tV`P$ zAu;PxHny|yWypJvzI+8a>T*863PoMo;%#k5ek$2xKEIYQaaYV|%+%Mx%%@-E`v!94 zdm8zhP~_8g2GVy6{9BOrnD1{VOk9dQ-$6E)_BiKvk@rF|yWc|=(>G>U%z24E$<>`D z`zDXNzmII)F}u$oi&?Mnv^@j4-??AgOOET&(aSxo<}@Sj7^Cw)Eq7tls%l5gA#@D~#% z?(%+pKi2 ssaoBlurPass = gBufferNode->AddNodeCompute("SSAO Blur Step", ssaoBlurShader, { "SSAO", "SSAO Blur" }); - /*-----------------------------------------------------------------------*/ - /* SHADOW MAP PASS */ - /*-----------------------------------------------------------------------*/ - // Shadow map pass will have no resources bound at first. Lighting system will add resources to the node. - // It will initially also not have any subpasses since they will be added for each light that casts shadows. - //auto shadowMapPassNode = renderGraph->AddNode(SHGraphicsConstants::RenderGraphNodeNames::SHADOW_MAP_PASS.data(), {}, {}); /*-----------------------------------------------------------------------*/ /* DEFERRED COMPOSITE NODE */ diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightingSubSystem.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightingSubSystem.cpp index 8a2fb3e3..bc9554c4 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightingSubSystem.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightingSubSystem.cpp @@ -60,7 +60,15 @@ namespace SHADE // write view projection matrix if renderer is available auto lightRenderer = lightComp->GetRenderer(); if (lightRenderer) + { lightPtr->pvMatrix = lightRenderer->GetCPUCameraData().viewProjectionMatrix; + + // Boolean to cast shadows in first 8 bits (1 byte) + lightPtr->shadowData = lightData.castShadows; + + // Next 24 bits for shadow map index + lightPtr->shadowData |= (lightData.shadowMapIndex << 8); + } break; } case SH_LIGHT_TYPE::POINT: diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightingSubSystem.h b/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightingSubSystem.h index 3cc5bac8..f3a98d14 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightingSubSystem.h +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightingSubSystem.h @@ -44,6 +44,9 @@ namespace SHADE //! Matrix for world to projection from light's perspective SHMatrix pvMatrix; + //! Represents boolean for casting shadows in first byte and shadow map index in the other 3. + uint32_t shadowData; + }; // Represents how the data will be interpreted in GPU. we want to copy to a container of these before passing to GPU. @@ -62,8 +65,6 @@ namespace SHADE //! when a fragment is being evaluated, the shader will use the fragment's //! layer value to AND with the light's. If result is 1, do lighting calculations. uint32_t cullingMask; - - }; class SH_API SHLightingSubSystem diff --git a/SHADE_Engine/src/Graphics/Pipeline/SHVkPipelineLayout.cpp b/SHADE_Engine/src/Graphics/Pipeline/SHVkPipelineLayout.cpp index d9ff07dd..6a6ef879 100644 --- a/SHADE_Engine/src/Graphics/Pipeline/SHVkPipelineLayout.cpp +++ b/SHADE_Engine/src/Graphics/Pipeline/SHVkPipelineLayout.cpp @@ -205,7 +205,7 @@ namespace SHADE newBinding.DescriptorCount = SHVkDescriptorSetLayout::Binding::VARIABLE_DESCRIPTOR_UPPER_BOUND; // Set the flags for variable bindings - newBinding.flags = vk::DescriptorBindingFlagBits::eVariableDescriptorCount; + newBinding.flags = vk::DescriptorBindingFlagBits::eVariableDescriptorCount | vk::DescriptorBindingFlagBits::ePartiallyBound; } else { From 402bd165226338bfe6ed0c7a7cb69bd78a710484 Mon Sep 17 00:00:00 2001 From: maverickdgg Date: Mon, 9 Jan 2023 17:18:22 +0800 Subject: [PATCH 29/45] fix for editor window size --- Assets/Application.SHConfig | 2 +- SHADE_Engine/src/UI/SHUISystem.cpp | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/Assets/Application.SHConfig b/Assets/Application.SHConfig index 5673556d..3cf8846b 100644 --- a/Assets/Application.SHConfig +++ b/Assets/Application.SHConfig @@ -1,4 +1,4 @@ Start in Fullscreen: false -Starting Scene ID: 97158628 +Starting Scene ID: 97161771 Window Size: {x: 1920, y: 1080} Window Title: SHADE Engine \ No newline at end of file diff --git a/SHADE_Engine/src/UI/SHUISystem.cpp b/SHADE_Engine/src/UI/SHUISystem.cpp index 4d175e5f..eef63a73 100644 --- a/SHADE_Engine/src/UI/SHUISystem.cpp +++ b/SHADE_Engine/src/UI/SHUISystem.cpp @@ -158,10 +158,11 @@ namespace SHADE SHVec2 mousePos; SHVec2 windowSize; #ifdef SHEDITOR - windowSize = SHEditorWindowManager::GetEditorWindow()->windowSize; + windowSize = SHEditorWindowManager::GetEditorWindow()->beginContentRegionAvailable; mousePos = SHEditorWindowManager::GetEditorWindow()->viewportMousePos; //mousePos.y = windowSize.y - mousePos.y; - //SHLOG_INFO("mouse pos: {}, {}", mousePos.x, mousePos.y) + SHLOG_INFO("mouse pos: {}, {}", mousePos.x, mousePos.y) + SHLOG_INFO("window size: {}, {}", windowSize.x, windowSize.y) //mousePos /= windowSize; //SHLOG_INFO("mouse pos normalized: {}, {}", mousePos.x, mousePos.y) #endif From 356ec24cc20f93693cef18aa6ff165c3f1cfa299 Mon Sep 17 00:00:00 2001 From: mushgunAX Date: Mon, 9 Jan 2023 17:21:24 +0800 Subject: [PATCH 30/45] Change default pathing for binding file I/O --- Assets/Bindings.SHConfig | 51 ------------------------- SHADE_Engine/src/Input/SHInputManager.h | 5 ++- 2 files changed, 3 insertions(+), 53 deletions(-) diff --git a/Assets/Bindings.SHConfig b/Assets/Bindings.SHConfig index e0023603..573541ac 100644 --- a/Assets/Bindings.SHConfig +++ b/Assets/Bindings.SHConfig @@ -1,52 +1 @@ -4 -Horizontal -0 -0 -5 -0.2 -5 -0 -2 -39 -68 -2 -37 -65 -2 -3 -16 -1 -2 -Mouse Wheel -3 -0 -1 -0.2 -1 -0 -0 -0 -0 -0 -Mouse X -1 -0 -1 -0.2 -1 -0 -0 -0 -0 -0 -Mouse Y -2 -0 -1 -0.2 -1 -0 -0 -0 -0 0 diff --git a/SHADE_Engine/src/Input/SHInputManager.h b/SHADE_Engine/src/Input/SHInputManager.h index 30ee00e8..680035c3 100644 --- a/SHADE_Engine/src/Input/SHInputManager.h +++ b/SHADE_Engine/src/Input/SHInputManager.h @@ -14,6 +14,7 @@ #include #include #include "../../SHADE_Managed/src/SHpch.h" +#include "../../SHADE_Engine/src/Assets/SHAssetMacros.h" #include "SH_API.h" #pragma comment(lib, "xinput.lib") @@ -686,11 +687,11 @@ namespace SHADE /*------------------------------------------------------------------------*/ //Save bindings registered into a file - static void SaveBindings(std::string const& targetFile = "../../Assets/Bindings.SHConfig") noexcept; + static void SaveBindings(std::string const& targetFile = std::string(ASSET_ROOT) + "/Bindings.SHConfig") noexcept; //Load and register bindings from a file //If specified file exists, the current list of bindings will be overwritten, so save them somewhere else before loading - static void LoadBindings(std::string const& sourceFile = "../../Assets/Bindings.SHConfig") noexcept; + static void LoadBindings(std::string const& sourceFile = std::string(ASSET_ROOT) + "/Bindings.SHConfig") noexcept; /*------------------------------------------------------------------------*/ /* Binding Functions */ From 8b2297f45160b86cf4d2713114498f92d9b8cfba Mon Sep 17 00:00:00 2001 From: maverickdgg Date: Mon, 9 Jan 2023 17:40:21 +0800 Subject: [PATCH 31/45] CreateSparseSet --- SHADE_Engine/src/UI/SHUISystem.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/SHADE_Engine/src/UI/SHUISystem.cpp b/SHADE_Engine/src/UI/SHUISystem.cpp index eef63a73..cd2bef82 100644 --- a/SHADE_Engine/src/UI/SHUISystem.cpp +++ b/SHADE_Engine/src/UI/SHUISystem.cpp @@ -20,6 +20,7 @@ namespace SHADE SHComponentManager::CreateComponentSparseSet(); SHComponentManager::CreateComponentSparseSet(); SHComponentManager::CreateComponentSparseSet(); + SHComponentManager::CreateComponentSparseSet(); } void SHUISystem::Exit() From 9538636af6dd0e2c2450ec558a4559489be63749 Mon Sep 17 00:00:00 2001 From: Brandon Mak Date: Tue, 10 Jan 2023 01:47:10 +0800 Subject: [PATCH 32/45] Shadows WIP --- .../Descriptors/SHVkDescriptorSetGroup.cpp | 6 +++ .../Graphics/Devices/SHVkLogicalDevice.cpp | 40 +++++++++++-------- .../MiddleEnd/Interface/SHGraphicsSystem.cpp | 26 ++++++------ .../MiddleEnd/Lights/SHLightingSubSystem.cpp | 26 +++++++++++- .../MiddleEnd/Lights/SHLightingSubSystem.h | 11 +++-- .../Graphics/RenderGraph/SHRenderGraph.cpp | 11 +++-- .../src/Graphics/RenderGraph/SHRenderGraph.h | 1 + .../RenderGraph/SHRenderGraphResource.cpp | 7 +++- .../RenderGraph/SHRenderGraphResource.h | 5 ++- 9 files changed, 92 insertions(+), 41 deletions(-) diff --git a/SHADE_Engine/src/Graphics/Descriptors/SHVkDescriptorSetGroup.cpp b/SHADE_Engine/src/Graphics/Descriptors/SHVkDescriptorSetGroup.cpp index 19ec721b..8143ec0e 100644 --- a/SHADE_Engine/src/Graphics/Descriptors/SHVkDescriptorSetGroup.cpp +++ b/SHADE_Engine/src/Graphics/Descriptors/SHVkDescriptorSetGroup.cpp @@ -175,6 +175,12 @@ namespace SHADE writeInfo.descImageInfos[i].sampler = sampler ? sampler->GetVkSampler() : nullptr; writeInfo.descImageInfos[i].imageLayout = layout; } + + // Rest is not used, so it doesn't matter what's in them, we just want to pacify Vulkan + for (uint32_t i = imageViewsAndSamplers.size(); i < writeInfo.descImageInfos.size(); ++i) + { + writeInfo.descImageInfos[i].sampler = std::get>(imageViewsAndSamplers.back())->GetVkSampler(); + } } void SHVkDescriptorSetGroup::ModifyWriteDescImage(uint32_t set, uint32_t binding, std::tuple, Handle, vk::ImageLayout> const& imageViewAndSampler, uint32_t descIndex) noexcept diff --git a/SHADE_Engine/src/Graphics/Devices/SHVkLogicalDevice.cpp b/SHADE_Engine/src/Graphics/Devices/SHVkLogicalDevice.cpp index b425bc5f..5653bbe7 100644 --- a/SHADE_Engine/src/Graphics/Devices/SHVkLogicalDevice.cpp +++ b/SHADE_Engine/src/Graphics/Devices/SHVkLogicalDevice.cpp @@ -183,35 +183,43 @@ namespace SHADE /*if (!extensionsSupported) SHUtil::ReportWarning("Some of the required extensions cannot be found on the physical device. ");*/ - vk::PhysicalDeviceFeatures features{}; // ADD MORE FEATURES HERE IF NEEDED + vk::PhysicalDeviceDescriptorIndexingFeatures descIndexingFeature + { + .shaderSampledImageArrayNonUniformIndexing = VK_TRUE, + .descriptorBindingPartiallyBound = VK_TRUE, + .descriptorBindingVariableDescriptorCount = VK_TRUE, + .runtimeDescriptorArray = VK_TRUE, + }; + + vk::PhysicalDeviceRobustness2FeaturesEXT robustFeatures + { + .nullDescriptor = VK_TRUE, + }; + + robustFeatures.pNext = &descIndexingFeature; + + vk::PhysicalDeviceFeatures2 features{}; // ADD MORE FEATURES HERE IF NEEDED // point and lines fill mode - features.fillModeNonSolid = VK_TRUE; - features.samplerAnisotropy = VK_TRUE; - features.multiDrawIndirect = VK_TRUE; - features.independentBlend = VK_TRUE; + features.features.fillModeNonSolid = VK_TRUE; + features.features.samplerAnisotropy = VK_TRUE; + features.features.multiDrawIndirect = VK_TRUE; + features.features.independentBlend = VK_TRUE; + features.features.wideLines = VK_TRUE; - - // for wide lines - features.wideLines = true; - - vk::PhysicalDeviceDescriptorIndexingFeatures descIndexingFeature{}; - descIndexingFeature.descriptorBindingVariableDescriptorCount = true; - descIndexingFeature.shaderSampledImageArrayNonUniformIndexing = true; - descIndexingFeature.descriptorBindingPartiallyBound = true; - descIndexingFeature.runtimeDescriptorArray = true; + features.pNext = &robustFeatures; // Prepare to create the device vk::DeviceCreateInfo deviceCreateInfo { - .pNext = &descIndexingFeature, + .pNext = &features, .queueCreateInfoCount = static_cast(queueCreateInfos.size()), .pQueueCreateInfos = queueCreateInfos.data(), .enabledLayerCount = 0, // deprecated and ignored .ppEnabledLayerNames = nullptr, // deprecated and ignored .enabledExtensionCount = !extensionsSupported ? 0 : static_cast(requiredExtensions.size()), .ppEnabledExtensionNames = !extensionsSupported ? nullptr : requiredExtensions.data(), - .pEnabledFeatures = &features + //.pEnabledFeatures = &features }; // Actually create the device diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp index eaf9b767..2e03d5a8 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp @@ -193,17 +193,17 @@ namespace SHADE /*-----------------------------------------------------------------------*/ // Initialize world render graph renderGraph->Init("World Render Graph", device, swapchain, &resourceManager, renderContextCmdPools); - renderGraph->AddResource("Position", { SH_RENDER_GRAPH_RESOURCE_FLAGS::COLOR, SH_RENDER_GRAPH_RESOURCE_FLAGS::INPUT, SH_RENDER_GRAPH_RESOURCE_FLAGS::STORAGE }, windowDims.first, windowDims.second, vk::Format::eR32G32B32A32Sfloat); - renderGraph->AddResource("Normals", { SH_RENDER_GRAPH_RESOURCE_FLAGS::COLOR, SH_RENDER_GRAPH_RESOURCE_FLAGS::INPUT, SH_RENDER_GRAPH_RESOURCE_FLAGS::STORAGE }, windowDims.first, windowDims.second, vk::Format::eR32G32B32A32Sfloat); + renderGraph->AddResource("Position", { SH_RENDER_GRAPH_RESOURCE_FLAGS::COLOR, SH_RENDER_GRAPH_RESOURCE_FLAGS::INPUT, SH_RENDER_GRAPH_RESOURCE_FLAGS::STORAGE }, true, windowDims.first, windowDims.second, vk::Format::eR32G32B32A32Sfloat); + renderGraph->AddResource("Normals", { SH_RENDER_GRAPH_RESOURCE_FLAGS::COLOR, SH_RENDER_GRAPH_RESOURCE_FLAGS::INPUT, SH_RENDER_GRAPH_RESOURCE_FLAGS::STORAGE }, true, windowDims.first, windowDims.second, vk::Format::eR32G32B32A32Sfloat); //worldRenderGraph->AddResource("Tangents", { SH_ATT_DESC_TYPE_FLAGS::COLOR, SH_ATT_DESC_TYPE_FLAGS::INPUT, SH_ATT_DESC_TYPE_FLAGS::STORAGE }, windowDims.first, windowDims.second, vk::Format::eR32G32B32A32Sfloat); - renderGraph->AddResource("Albedo", { SH_RENDER_GRAPH_RESOURCE_FLAGS::COLOR, SH_RENDER_GRAPH_RESOURCE_FLAGS::INPUT, SH_RENDER_GRAPH_RESOURCE_FLAGS::STORAGE }, windowDims.first, windowDims.second); - renderGraph->AddResource("Depth Buffer", { SH_RENDER_GRAPH_RESOURCE_FLAGS::DEPTH_STENCIL }, windowDims.first, windowDims.second, vk::Format::eD32SfloatS8Uint); - renderGraph->AddResource("Entity ID", { SH_RENDER_GRAPH_RESOURCE_FLAGS::COLOR, SH_RENDER_GRAPH_RESOURCE_FLAGS::SHARED }, windowDims.first, windowDims.second, vk::Format::eR32Uint, 1, vk::ImageUsageFlagBits::eTransferSrc); - renderGraph->AddResource("Light Layer Indices", { SH_RENDER_GRAPH_RESOURCE_FLAGS::COLOR, SH_RENDER_GRAPH_RESOURCE_FLAGS::INPUT, SH_RENDER_GRAPH_RESOURCE_FLAGS::STORAGE }, windowDims.first, windowDims.second, vk::Format::eR32Uint, 1, vk::ImageUsageFlagBits::eTransferSrc); - renderGraph->AddResource("Scene", { SH_RENDER_GRAPH_RESOURCE_FLAGS::COLOR, SH_RENDER_GRAPH_RESOURCE_FLAGS::INPUT, SH_RENDER_GRAPH_RESOURCE_FLAGS::STORAGE, SH_RENDER_GRAPH_RESOURCE_FLAGS::SHARED }, windowDims.first, windowDims.second); - renderGraph->AddResource("SSAO", { SH_RENDER_GRAPH_RESOURCE_FLAGS::COLOR, SH_RENDER_GRAPH_RESOURCE_FLAGS::INPUT, SH_RENDER_GRAPH_RESOURCE_FLAGS::STORAGE }, windowDims.first, windowDims.second, vk::Format::eR8Unorm); - renderGraph->AddResource("SSAO Blur", { SH_RENDER_GRAPH_RESOURCE_FLAGS::COLOR, SH_RENDER_GRAPH_RESOURCE_FLAGS::INPUT, SH_RENDER_GRAPH_RESOURCE_FLAGS::STORAGE }, windowDims.first, windowDims.second, vk::Format::eR8Unorm); - renderGraph->AddResource("Present", { SH_RENDER_GRAPH_RESOURCE_FLAGS::COLOR_PRESENT }, windowDims.first, windowDims.second); + renderGraph->AddResource("Albedo", { SH_RENDER_GRAPH_RESOURCE_FLAGS::COLOR, SH_RENDER_GRAPH_RESOURCE_FLAGS::INPUT, SH_RENDER_GRAPH_RESOURCE_FLAGS::STORAGE }, true, windowDims.first, windowDims.second); + renderGraph->AddResource("Depth Buffer", { SH_RENDER_GRAPH_RESOURCE_FLAGS::DEPTH_STENCIL }, true, windowDims.first, windowDims.second, vk::Format::eD32SfloatS8Uint); + renderGraph->AddResource("Entity ID", { SH_RENDER_GRAPH_RESOURCE_FLAGS::COLOR, SH_RENDER_GRAPH_RESOURCE_FLAGS::SHARED }, true, windowDims.first, windowDims.second, vk::Format::eR32Uint, 1, vk::ImageUsageFlagBits::eTransferSrc); + renderGraph->AddResource("Light Layer Indices", { SH_RENDER_GRAPH_RESOURCE_FLAGS::COLOR, SH_RENDER_GRAPH_RESOURCE_FLAGS::INPUT, SH_RENDER_GRAPH_RESOURCE_FLAGS::STORAGE }, true, windowDims.first, windowDims.second, vk::Format::eR32Uint, 1, vk::ImageUsageFlagBits::eTransferSrc); + renderGraph->AddResource("Scene", { SH_RENDER_GRAPH_RESOURCE_FLAGS::COLOR, SH_RENDER_GRAPH_RESOURCE_FLAGS::INPUT, SH_RENDER_GRAPH_RESOURCE_FLAGS::STORAGE, SH_RENDER_GRAPH_RESOURCE_FLAGS::SHARED }, true, windowDims.first, windowDims.second); + renderGraph->AddResource("SSAO", { SH_RENDER_GRAPH_RESOURCE_FLAGS::COLOR, SH_RENDER_GRAPH_RESOURCE_FLAGS::INPUT, SH_RENDER_GRAPH_RESOURCE_FLAGS::STORAGE }, true, windowDims.first, windowDims.second, vk::Format::eR8Unorm); + renderGraph->AddResource("SSAO Blur", { SH_RENDER_GRAPH_RESOURCE_FLAGS::COLOR, SH_RENDER_GRAPH_RESOURCE_FLAGS::INPUT, SH_RENDER_GRAPH_RESOURCE_FLAGS::STORAGE }, true, windowDims.first, windowDims.second, vk::Format::eR8Unorm); + renderGraph->AddResource("Present", { SH_RENDER_GRAPH_RESOURCE_FLAGS::COLOR_PRESENT }, true, windowDims.first, windowDims.second); /*-----------------------------------------------------------------------*/ /* MAIN NODE */ @@ -766,21 +766,18 @@ namespace SHADE } // Add the shadow map resource to the graph - renderGraph->AddResource(resourceName, {SH_RENDER_GRAPH_RESOURCE_FLAGS::DEPTH, SH_RENDER_GRAPH_RESOURCE_FLAGS::INPUT}, resizeWidth, resizeHeight, vk::Format::eD32Sfloat); + renderGraph->AddResource(resourceName, {SH_RENDER_GRAPH_RESOURCE_FLAGS::DEPTH, SH_RENDER_GRAPH_RESOURCE_FLAGS::INPUT}, false, SHLightingSubSystem::SHADOW_MAP_WIDTH, SHLightingSubSystem::SHADOW_MAP_HEIGHT, vk::Format::eD32Sfloat); // link resource to node. This means linking the resource and regenerating the node's renderpass and framebuffer. - //auto shadowMapNode = renderGraph->GetNode(SHGraphicsConstants::RenderGraphNodeNames::SHADOW_MAP_PASS.data()); auto shadowMapNode = renderGraph->AddNodeAfter(SHGraphicsConstants::RenderGraphEntityNames::SHADOW_MAP_PASS.data() + resourceName, {resourceName.c_str()}, SHGraphicsConstants::RenderGraphEntityNames::GBUFFER_PASS.data()); // Add a subpass to render to that shadow map auto newSubpass = shadowMapNode->RuntimeAddSubpass(resourceName + " Subpass", worldViewport, lightComp->GetRenderer()); - //auto newSubpass = shadowMapNode->RuntimeAddSubpass(resourceName + " Subpass", worldViewport, lightComp->GetRenderer()); newSubpass->AddDepthOutput(resourceName, SH_RENDER_GRAPH_RESOURCE_FLAGS::DEPTH); // regenerate the node shadowMapNode->RuntimeStandaloneRegenerate(); - // Create pipeline from new renderpass and subpass if it's not created yet if (!shadowMapPipeline) { @@ -1110,6 +1107,7 @@ namespace SHADE mousePickSubSystem->HandleResize(); postOffscreenRenderSubSystem->HandleResize(); + //lightingSubSystem->HandleResize(renderGraph->GetNode(SHGraphicsConstants::RenderGraphEntityNames::DEFERRED_COMPOSITE_PASS.data())->GetNodeCompute(SHGraphicsConstants::RenderGraphEntityNames::DEFERRED_COMPOSITE_COMPUTE.data())); worldViewport->SetWidth(static_cast(resizeWidth)); worldViewport->SetHeight(static_cast(resizeHeight)); diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightingSubSystem.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightingSubSystem.cpp index bc9554c4..6beac351 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightingSubSystem.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightingSubSystem.cpp @@ -16,6 +16,7 @@ #include "Graphics/Events/SHGraphicsEvents.h" #include "Graphics/MiddleEnd/Interface/SHRenderer.h" #include "Math/Transform/SHTransformComponent.h" +#include "Graphics/RenderGraph/SHRenderGraphNodeCompute.h" namespace SHADE { @@ -594,7 +595,8 @@ namespace SHADE uint32_t SHLightingSubSystem::AddShadowMap(Handle newShadowMap, EntityID lightEntity) noexcept { // Add to container of shadow maps - shadowMaps.emplace(lightEntity, newShadowMap); + shadowMapIndexing.emplace(lightEntity, shadowMaps.size()); + shadowMaps.emplace_back(newShadowMap); // Just use the image view stored in the resource Handle const NEW_IMAGE_VIEW = newShadowMap->GetImageView(); @@ -650,6 +652,28 @@ namespace SHADE cmdBuffer->PipelineBarrier(vk::PipelineStageFlagBits::eEarlyFragmentTests | vk::PipelineStageFlagBits::eLateFragmentTests, vk::PipelineStageFlagBits::eComputeShader, {}, {}, {}, shadowMapMemoryBarriers); } + //void SHLightingSubSystem::HandleResize(Handle compute) noexcept + //{ + // uint32_t const NUM_SHADOW_MAPS = static_cast(shadowMaps.size()); + // for (uint32_t i = 0; i < NUM_SHADOW_MAPS; ++i) + // { + // // Just use the image view stored in the resource + // Handle const NEW_IMAGE_VIEW = shadowMaps[i]->GetImageView(); + + // // set new image view + // std::get>(shadowMapImageSamplers[i]) = NEW_IMAGE_VIEW; + + // // Set image for barrier + // shadowMapMemoryBarriers[i].image = shadowMaps[i]->GetImage()->GetVkImage(); + // } + + // if (NUM_SHADOW_MAPS > 0) + // { + // // modify descriptors in render graph node compute + // compute->ModifyWriteDescImageComputeResource (SHGraphicsConstants::DescriptorSetBindings::SHADOW_MAP_IMAGE_SAMPLER_DATA, shadowMapImageSamplers); + // } + //} + Handle SHLightingSubSystem::GetLightDataDescriptorSet(void) const noexcept { return lightingDataDescSet; diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightingSubSystem.h b/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightingSubSystem.h index f3a98d14..43d901fc 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightingSubSystem.h +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightingSubSystem.h @@ -23,6 +23,7 @@ namespace SHADE class SHSamplerCache; class SHVkImageView; class SHVkSampler; + class SHRenderGraphNodeCompute; // Represents how the data will be interpreted in GPU. we want to copy to a container of these before passing to GPU. struct SHDirectionalLightData @@ -72,7 +73,8 @@ namespace SHADE public: using DynamicOffsetArray = std::array, static_cast(SHGraphicsConstants::NUM_FRAME_BUFFERS)>; static constexpr uint32_t MAX_SHADOWS = 200; - + static constexpr uint32_t SHADOW_MAP_WIDTH = 1024; + static constexpr uint32_t SHADOW_MAP_HEIGHT = 1024; private: class PerTypeData @@ -172,9 +174,11 @@ namespace SHADE //! Handle to sampler that all shadow map descriptors will use Handle shadowMapSampler; - //std::vector> shadowMaps; + //! For indexing shadow maps + std::unordered_map shadowMapIndexing; + //! Shadow maps for every light that casts a shadow Order here doesn't matter. We just want to store it - std::unordered_map> shadowMaps; + std::vector> shadowMaps; //! Descriptor sets required to be given to the compute shader for shadow calculation. This will be a descriptor array. //! It will also be preallocated. @@ -211,6 +215,7 @@ namespace SHADE void BindDescSet (Handle cmdBuffer, uint32_t setIndex, uint32_t frameIndex) noexcept; uint32_t AddShadowMap (Handle newShadowMap, EntityID lightEntity) noexcept; void PrepareShadowMapsForRead (Handle cmdBuffer) noexcept; + //void HandleResize (Handle compute) noexcept; //void RemoveShadowMap (uint32_t index) noexcept; /*-----------------------------------------------------------------------*/ diff --git a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraph.cpp b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraph.cpp index 5f8b8624..74ea951a 100644 --- a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraph.cpp +++ b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraph.cpp @@ -54,7 +54,7 @@ namespace SHADE */ /***************************************************************************/ - void SHRenderGraph::AddResource(std::string resourceName, std::initializer_list typeFlags, uint32_t w /*= static_cast(-1)*/, uint32_t h /*= static_cast(-1)*/, vk::Format format/* = vk::Format::eB8G8R8A8Unorm*/, uint8_t levels /*= 1*/, vk::ImageUsageFlagBits usageFlags/* = {}*/, vk::ImageCreateFlagBits createFlags /*= {}*/) + void SHRenderGraph::AddResource(std::string resourceName, std::initializer_list typeFlags, bool resizeWithWindow, uint32_t w /*= static_cast(-1)*/, uint32_t h /*= static_cast(-1)*/, vk::Format format/* = vk::Format::eB8G8R8A8Unorm*/, uint8_t levels /*= 1*/, vk::ImageUsageFlagBits usageFlags/* = {}*/, vk::ImageCreateFlagBits createFlags /*= {}*/) { // If we set to if (w == static_cast(-1) && h == static_cast(-1)) @@ -64,7 +64,7 @@ namespace SHADE format = renderGraphStorage->swapchain->GetSurfaceFormatKHR().format; } - auto resource = renderGraphStorage->resourceHub->Create(renderGraphStorage, resourceName, typeFlags, format, w, h, levels, usageFlags, createFlags); + auto resource = renderGraphStorage->resourceHub->Create(renderGraphStorage, resourceName, typeFlags, format, w, h, levels, usageFlags, createFlags, resizeWithWindow); renderGraphStorage->graphResources->try_emplace(resourceName, resource); } @@ -616,8 +616,11 @@ namespace SHADE // resize resources for (auto& [name, resource] : *renderGraphStorage->graphResources) { - if (!renderGraphStorage->nonOwningResourceInitialLayouts.contains (resource.GetId().Raw)) - resource->HandleResize(newWidth, newHeight); + if (resource->resizeWithWindow) + { + if (!renderGraphStorage->nonOwningResourceInitialLayouts.contains (resource.GetId().Raw)) + resource->HandleResize(newWidth, newHeight); + } } for (auto& node : nodes) diff --git a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraph.h b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraph.h index 6ee181f8..5abcd6b6 100644 --- a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraph.h +++ b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraph.h @@ -102,6 +102,7 @@ namespace SHADE ( std::string resourceName, std::initializer_list typeFlags, + bool resizeWithWindow = true, uint32_t w = static_cast(-1), uint32_t h = static_cast(-1), vk::Format format = vk::Format::eB8G8R8A8Unorm, diff --git a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphResource.cpp b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphResource.cpp index 5a34fa04..d0a88e86 100644 --- a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphResource.cpp +++ b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphResource.cpp @@ -78,7 +78,7 @@ namespace SHADE */ /***************************************************************************/ - SHRenderGraphResource::SHRenderGraphResource(Handle renderGraphStorage, std::string const& name, std::initializer_list typeFlags, vk::Format format, uint32_t w, uint32_t h, uint8_t levels, vk::ImageUsageFlagBits usageFlags, vk::ImageCreateFlagBits createFlags) noexcept + SHRenderGraphResource::SHRenderGraphResource(Handle renderGraphStorage, std::string const& name, std::initializer_list typeFlags, vk::Format format, uint32_t w, uint32_t h, uint8_t levels, vk::ImageUsageFlagBits usageFlags, vk::ImageCreateFlagBits createFlags, bool inResizeWithWindow) noexcept : graphStorage{renderGraphStorage} , resourceTypeFlags{ } , resourceFormat{ format } @@ -88,6 +88,7 @@ namespace SHADE , height{ h } , mipLevels{ levels } , resourceName{ name } + , resizeWithWindow { inResizeWithWindow } { // If the resource type is an arbitrary image and not swapchain image if (typeFlags.size() == 1 && *typeFlags.begin() == SH_RENDER_GRAPH_RESOURCE_FLAGS::COLOR_PRESENT) @@ -210,6 +211,7 @@ namespace SHADE , imageAspectFlags{ rhs.imageAspectFlags } , graphStorage{rhs.graphStorage} , infoTracker {std::move (rhs.infoTracker)} + , resizeWithWindow{rhs.resizeWithWindow} { } @@ -242,7 +244,8 @@ namespace SHADE mipLevels = rhs.mipLevels; imageAspectFlags = rhs.imageAspectFlags; graphStorage = rhs.graphStorage; - infoTracker = std::move(infoTracker); + infoTracker = std::move(rhs.infoTracker); + resizeWithWindow = rhs.resizeWithWindow; return *this; } diff --git a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphResource.h b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphResource.h index 7ac2b824..b9fe219e 100644 --- a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphResource.h +++ b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphResource.h @@ -96,11 +96,14 @@ namespace SHADE //! For tracking resource states in stages of the render graphs Handle infoTracker; + //! Whether or not to resize (recreate vulkan image) when window resizes + bool resizeWithWindow; + public: /*-----------------------------------------------------------------------*/ /* CTORS AND DTORS */ /*-----------------------------------------------------------------------*/ - SHRenderGraphResource(Handle renderGraphStorage, std::string const& name, std::initializer_list typeFlags, vk::Format format, uint32_t w, uint32_t h, uint8_t levels, vk::ImageUsageFlagBits usageFlags, vk::ImageCreateFlagBits createFlags) noexcept; + SHRenderGraphResource(Handle renderGraphStorage, std::string const& name, std::initializer_list typeFlags, vk::Format format, uint32_t w, uint32_t h, uint8_t levels, vk::ImageUsageFlagBits usageFlags, vk::ImageCreateFlagBits createFlags, bool inResizeWithWindow) noexcept; SHRenderGraphResource(SHRenderGraphResource&& rhs) noexcept; SHRenderGraphResource& operator=(SHRenderGraphResource&& rhs) noexcept; ~SHRenderGraphResource(void) noexcept; From 4a06032bea4167d487f83fc281509a7606a45248 Mon Sep 17 00:00:00 2001 From: Brandon Mak Date: Wed, 11 Jan 2023 08:25:38 +0800 Subject: [PATCH 33/45] Shadows WIP --- Assets/Application.SHConfig | 2 +- Assets/Scenes/Scene2.shade | 25 ++++++++++++++- Assets/Shaders/DeferredComposite_CS.glsl | 29 ++++++++++-------- Assets/Shaders/DeferredComposite_CS.shshaderb | Bin 6529 -> 6277 bytes Assets/Shaders/TestCube_FS.glsl | 5 ++- Assets/Shaders/TestCube_FS.shshaderb | Bin 2401 -> 2557 bytes Assets/Shaders/TestCube_VS.glsl | 5 ++- Assets/Shaders/TestCube_VS.shshaderb | Bin 3689 -> 3905 bytes .../MiddleEnd/Interface/SHGraphicsSystem.cpp | 12 ++++++-- .../MiddleEnd/Lights/SHLightComponent.cpp | 5 +++ .../MiddleEnd/Lights/SHLightComponent.h | 1 + .../MiddleEnd/Lights/SHLightingSubSystem.cpp | 12 ++++++-- .../MiddleEnd/Lights/SHLightingSubSystem.h | 1 + 13 files changed, 76 insertions(+), 21 deletions(-) diff --git a/Assets/Application.SHConfig b/Assets/Application.SHConfig index 370665d2..10ba697b 100644 --- a/Assets/Application.SHConfig +++ b/Assets/Application.SHConfig @@ -1,4 +1,4 @@ Start in Fullscreen: false -Starting Scene ID: 86098106 +Starting Scene ID: 87285316 Window Size: {x: 1920, y: 1080} Window Title: SHADE Engine \ No newline at end of file diff --git a/Assets/Scenes/Scene2.shade b/Assets/Scenes/Scene2.shade index 2f38a933..c8aa9c6d 100644 --- a/Assets/Scenes/Scene2.shade +++ b/Assets/Scenes/Scene2.shade @@ -5,8 +5,9 @@ Components: Transform Component: Translate: {x: 0, y: 0.304069757, z: 1.73034382} - Rotate: {x: 0, y: 0, z: 0} + Rotate: {x: -1.48352981, y: 0, z: 0} Scale: {x: 1, y: 1, z: 1} + IsActive: true Camera Component: Position: {x: 0, y: 0.304069757, z: 1.73034382} Pitch: 0 @@ -17,6 +18,7 @@ Near: 0.00999999978 Far: 10000 Perspective: true + IsActive: true Scripts: ~ - EID: 1 Name: Raccoon @@ -27,9 +29,11 @@ Translate: {x: 0, y: 0, z: 0} Rotate: {x: 0, y: 0, z: 0} Scale: {x: 1, y: 1, z: 1} + IsActive: true Renderable Component: Mesh: 149697411 Material: 126974645 + IsActive: true Scripts: ~ - EID: 3 Name: Bag @@ -40,9 +44,11 @@ Translate: {x: 0.006237939, y: -0.000393368304, z: 0} Rotate: {x: -0, y: 2.79945588, z: 0} Scale: {x: 1.0000881, y: 1, z: 1.0000881} + IsActive: true Renderable Component: Mesh: 144838771 Material: 123745521 + IsActive: true Scripts: ~ - EID: 2 Name: DirectionalLight @@ -56,6 +62,7 @@ Color: {x: 1, y: 1, z: 1, w: 1} Layer: 4294967295 Strength: 0 + IsActive: true Scripts: ~ - EID: 4 Name: AmbientLight @@ -69,4 +76,20 @@ Color: {x: 1, y: 1, z: 1, w: 1} Layer: 4294967295 Strength: 0.600000024 + IsActive: true + Scripts: ~ +- EID: 5 + Name: Floor + IsActive: true + NumberOfChildren: 0 + Components: + Transform Component: + Translate: {x: 0, y: 0.0810000002, z: 0} + Rotate: {x: -1.57079637, y: 0, z: 0} + Scale: {x: 50, y: 50, z: 50} + IsActive: true + Renderable Component: + Mesh: 141771688 + Material: 124370424 + IsActive: true Scripts: ~ \ No newline at end of file diff --git a/Assets/Shaders/DeferredComposite_CS.glsl b/Assets/Shaders/DeferredComposite_CS.glsl index 2402d4f8..576ce74b 100644 --- a/Assets/Shaders/DeferredComposite_CS.glsl +++ b/Assets/Shaders/DeferredComposite_CS.glsl @@ -47,6 +47,11 @@ layout(std430, set = 1, binding = 4) buffer AmbientLightData AmbientLightStruct aLightData[]; } AmbLightData; +// bool IsInShadow (sampler2D shadowMap, vec2 coords, float depth, mat4 lightVP) +// { +// // vec4 fragPosLightPOV = lightVP * +// } + void main() { // convenient variables @@ -68,6 +73,16 @@ void main() vec4 shadowMapColor = vec4 (1.0f); + for (int i = 0; i < lightCounts.ambientLights; ++i) + { + if ((lightLayer & AmbLightData.aLightData[i].cullingMask) != 0) + { + // Just do some add + //fragColor += pixelDiffuse.rgb * AmbLightData.aLightData[i].ambientColor.rgb * vec3 (0.5f); + fragColor += pixelDiffuse.rgb * AmbLightData.aLightData[i].ambientColor.rgb * vec3 (AmbLightData.aLightData[i].strength); + } + } + for (int i = 0; i < lightCounts.directionalLights; ++i) { if ((lightLayer & DirLightData.dLightData[i].cullingMask) != 0) @@ -81,32 +96,22 @@ void main() // Calculate the fragment color fragColor += DirLightData.dLightData[i].diffuseColor.rgb * diffuseStrength.rrr * pixelDiffuse; + // If the shadow map is enabled (test the bit) if ((DirLightData.dLightData[i].shadowData & uint(1)) == 1) { // calculate shadow map here vec2 texCoord = vec2 (gl_GlobalInvocationID.xy) / vec2 (imageSize (targetImage)); - shadowMapColor = texture (shadowMaps[0], texCoord).xxxx; } } } - for (int i = 0; i < lightCounts.ambientLights; ++i) - { - if ((lightLayer & AmbLightData.aLightData[i].cullingMask) != 0) - { - // Just do some add - //fragColor += pixelDiffuse.rgb * AmbLightData.aLightData[i].ambientColor.rgb * vec3 (0.5f); - fragColor += pixelDiffuse.rgb * AmbLightData.aLightData[i].ambientColor.rgb * vec3 (AmbLightData.aLightData[i].strength); - } - } - float ssaoVal = imageLoad (ssaoBlurredImage, globalThread).r; fragColor *= ssaoVal; // store result into result image imageStore(targetImage, ivec2(gl_GlobalInvocationID.xy), vec4(fragColor.rgb, 1.0f)); - imageStore(targetImage, ivec2(gl_GlobalInvocationID.xy), shadowMapColor); + // imageStore(targetImage, ivec2(gl_GlobalInvocationID.xy), shadowMapColor); //imageStore(targetImage, ivec2(gl_GlobalInvocationID.xy), vec4(ssaoVal.rrr, 1.0f)); } \ No newline at end of file diff --git a/Assets/Shaders/DeferredComposite_CS.shshaderb b/Assets/Shaders/DeferredComposite_CS.shshaderb index fc527efa0308db8d380e4a8cfabff95cb1ce335b..633fd1975d4df1e6788128068fcfc40efa3fb9f7 100644 GIT binary patch literal 6277 zcmZveiJR4B6~})wFvB3Ak|Lx?gS220nu&@8I50M1Gb};0H~wbkGIR5C?{x1S7NdfQ zvLsq)U#%=l4J}(S%51THwST4Ud3v5cpWl7Y@QcTn=gc|hd)D`T&-=UdA6b?aYfks7 zd0Ez#U6d`#{@#JI#aTBOYkQ`em3#t~KKqK^CTpWZg=t&; zKw~^_R~z+hgN3~}TMD199;(y^tNZrNw5V>}-0VttUK^`SG}L>ue)Q=^t7`DxYULm* zcu%&fgtrp58eVTS_vf{ar}?g(#acz&_2{+gD}GT#J4-!dp}MMC0H{KAj9bob>>Bweac5?t%|nV{2ok-fpprz5)Zz(s4KHd984< z_g?-P!&R}@YQ3E-fqRdw=|;eK&nx_$j(q=EwK5yg>3bNw*iWk8ga00|fs*g;c5`OD zZS9T?bL5Kc7JV6KU#)htQlD&3>1SW!_El{Sr0F@2+t>I^jq#cs$y@huZu7FeVCDLq zQ|`oQbLGXp#c;Er6Co>b~!5AkQ-N zmB^mC`YL$YuCCps-S=F!t84E{cHeT@uCCpBchaNp%w=9zV8)AikAc~fSYHVz+?eR&Cs+Wy2?@3rt=s2?&e-cjVYKQZI< z_dS*SQ@6j^vvcf*;WxL4HMegd;?(u=2d<3qV_E!m1!jzX z(~!L%g}Ya|KF8p$=+(W7&4Khk4lnOjeI?YD?9RIO@K@JvUE`hevRz%f{cHad+_`>! z(w%+%!>+Es>oO*!8@`fi)>B@BXWX4VEk*YX#I*OLJ9lD|{udQEe^~lkU(B5Pdq3t9 z-;i|QU*x|8+5Gxn!Cz;qA2QbxxO(Ke0=ZMyJNk($}2o zem7k9y$)^;`@W99%C|r+b@y~zp=H?`PS~^DkT7w{Io|?)OGa`&g3WEZmR(x#&uEf8X`>Y?tBxF1Wtl!3ti6 z-y6^Qd@otyqi$bE;riIuF}S*Q-vc+Vn0=`qPgtDCiKOd)D#_MT{}|kRu&?lc5ZUjB zy7eD|x*%ugQMkU=H2zy~ zdio>!rI7RK_rdR%m}I}!`ZN5wYDMj~T^=AcGH*-Sv z?ESf%w|{|nZuVAKgUZD41psz0JYmu)n>Bg@w>At;z{4Yk=M?CVs1X)~imGk$bYmfXdMZPxa=D!Xq=U;=ak9g#N8M3(KD(81Dw4471 z_$#0rlWzW-pvb=t`DRETaqq_Wcq=6C@=Tm9F=gj!Lz11T%}E}BZ-M^JNp6KZ-|~OZ z#~tujK`!k>aP4yY?1kS6nZtRphi$W1PqrO-2Q&`U1`oXxu-XE6H8k)y9MP;d?y(;qCps1&93ewkaoXapKO1dK^q_I?7kP> z`Z2rjLp}~!PumG7V&9LfJ!bblWb=u~?0x`QJZATPWS4zu`yeD{U&?U~A3}~kP9c97 ziaxZ({=NT?B>TcNJ0C@NKD`rd-pfh2xcQCwI3yPOCy-Yccuz5ppDg4o6JN+Xc1Ax1 znODEtAbrez8m=vR|1@&+K8E}mD0AHkd>*o1ypt~^ zOk9e0@_?A7`F8Welg z_8_FMv-WjJd(6u>67~@MVdi@m{F{)tnBTfb;4bGy+ryBU^P+6-1@OnAMbHlJ>M{7Y z6DIER9H;Sp6#gAZyRpmQ--VulrqJiXzn8E^^8bFq?xRQJe*l?7+%q|oFyD0aCRe{7 zZm)9n14)<18U7I2GmP)ekC4TtAoFVzGv05B`DWn8KMDT{bS~-k|5Io_6#s8|3Rxd< zf0v!3pFvMSE^C~Hic2>selZtf`g^9oggjIA1@K=%<@ L+W$+ITcQ5}wX$pv literal 6529 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 diff --git a/Assets/Shaders/TestCube_FS.glsl b/Assets/Shaders/TestCube_FS.glsl index b6a1eab6..cb7bfefd 100644 --- a/Assets/Shaders/TestCube_FS.glsl +++ b/Assets/Shaders/TestCube_FS.glsl @@ -16,11 +16,12 @@ layout(location = 0) in struct vec4 vertPos; // location 0 vec2 uv; // location = 1 vec4 normal; // location = 2 + vec4 worldPos; // location = 3 } In; // material stuff -layout(location = 3) flat in struct +layout(location = 4) flat in struct { int materialIndex; uint eid; @@ -38,12 +39,14 @@ layout(location = 1) out uint outEntityID; layout(location = 2) out uint lightLayerIndices; layout(location = 3) out vec4 normals; layout(location = 4) out vec4 albedo; +layout(location = 5) out vec4 worldSpacePosition; void main() { position = In.vertPos; normals = In.normal; albedo = texture(textures[nonuniformEXT(MatProp.data[In2.materialIndex].textureIndex)], In.uv) * MatProp.data[In2.materialIndex].color; + worldSpacePosition = In.worldPos; outEntityID = In2.eid; lightLayerIndices = In2.lightLayerIndex; diff --git a/Assets/Shaders/TestCube_FS.shshaderb b/Assets/Shaders/TestCube_FS.shshaderb index abd90cf744ad1b20429e7740fe4354edc390101c..2974523d7405e05bdcf30d419f0663694bcc271b 100644 GIT binary patch delta 444 zcmYjLu}T9`5Zv|d@=WA3sJT*L!*Ke zWC_dzo|F6A>p}7$;y!ht4I}hs>iON})eTy48Yd%>06%vmkEtD{ar$!BfnvnEuD7e| zPoDhx7Kb;00O*OI4UlWj?c~EBuKb-xPQ(;3t`>aj#Xjtdpj^RZb?{}>X3jUkkMegF zm40$&qM!X^RG#|Zx2|uTzLp`kfDquyChSab2vBcf2~U%^k)NwhfE}O)(9g9UfI9s= bO+NQ`@uq(rnEQKpL$7257KFkKDffV1b_6lJ delta 288 zcmYk0ISRr+6o%h38G=#4jo67GT4-TmqqvR>Vq@(AY%J6!3N}_=Amko`4tO6c?;r&H zpC~x+G4n6;W}@69>!p`*`YbC}c8HiU%f*Ro&r9T4F&x2oo{Pm@;aTXon(H3|Ey#FFQ diff --git a/Assets/Shaders/TestCube_VS.glsl b/Assets/Shaders/TestCube_VS.glsl index 554ce379..041c552f 100644 --- a/Assets/Shaders/TestCube_VS.glsl +++ b/Assets/Shaders/TestCube_VS.glsl @@ -17,11 +17,12 @@ layout(location = 0) out struct vec4 vertPos; // location 0 vec2 uv; // location = 1 vec4 normal; // location = 2 + vec4 worldPos; // location = 3 } Out; // material stuff -layout(location = 3) out struct +layout(location = 4) out struct { int materialIndex; uint eid; @@ -49,6 +50,8 @@ void main() // gBuffer position will be in view space Out.vertPos = modelViewMat * vec4(aVertexPos, 1.0f); + Out.worldPos = worldTransform * vec4 (aVertexPos, 1.0f); + // uvs for texturing in fragment shader Out.uv = aUV; diff --git a/Assets/Shaders/TestCube_VS.shshaderb b/Assets/Shaders/TestCube_VS.shshaderb index a1138f75c885a67d6cb7ac2abb1928fe9de3a08e..0467a41d3c9dffd337d9ea55d160e5a79bb1d13c 100644 GIT binary patch literal 3905 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 @@ -194,6 +196,7 @@ namespace SHADE // Initialize world render graph renderGraph->Init("World Render Graph", device, swapchain, &resourceManager, renderContextCmdPools); renderGraph->AddResource("Position", { SH_RENDER_GRAPH_RESOURCE_FLAGS::COLOR, SH_RENDER_GRAPH_RESOURCE_FLAGS::INPUT, SH_RENDER_GRAPH_RESOURCE_FLAGS::STORAGE }, true, windowDims.first, windowDims.second, vk::Format::eR32G32B32A32Sfloat); + renderGraph->AddResource("Position World Space", { SH_RENDER_GRAPH_RESOURCE_FLAGS::COLOR, SH_RENDER_GRAPH_RESOURCE_FLAGS::INPUT, SH_RENDER_GRAPH_RESOURCE_FLAGS::STORAGE }, true, windowDims.first, windowDims.second, vk::Format::eR32G32B32A32Sfloat); renderGraph->AddResource("Normals", { SH_RENDER_GRAPH_RESOURCE_FLAGS::COLOR, SH_RENDER_GRAPH_RESOURCE_FLAGS::INPUT, SH_RENDER_GRAPH_RESOURCE_FLAGS::STORAGE }, true, windowDims.first, windowDims.second, vk::Format::eR32G32B32A32Sfloat); //worldRenderGraph->AddResource("Tangents", { SH_ATT_DESC_TYPE_FLAGS::COLOR, SH_ATT_DESC_TYPE_FLAGS::INPUT, SH_ATT_DESC_TYPE_FLAGS::STORAGE }, windowDims.first, windowDims.second, vk::Format::eR32G32B32A32Sfloat); renderGraph->AddResource("Albedo", { SH_RENDER_GRAPH_RESOURCE_FLAGS::COLOR, SH_RENDER_GRAPH_RESOURCE_FLAGS::INPUT, SH_RENDER_GRAPH_RESOURCE_FLAGS::STORAGE }, true, windowDims.first, windowDims.second); @@ -218,7 +221,8 @@ namespace SHADE "Albedo", "Depth Buffer", "SSAO", - "SSAO Blur" + "SSAO Blur", + "Position World Space" }, {}); // no predecessors @@ -231,6 +235,7 @@ namespace SHADE gBufferSubpass->AddColorOutput("Light Layer Indices"); gBufferSubpass->AddColorOutput("Normals"); gBufferSubpass->AddColorOutput("Albedo"); + gBufferSubpass->AddColorOutput("Position World Space"); gBufferSubpass->AddDepthOutput("Depth Buffer", SH_RENDER_GRAPH_RESOURCE_FLAGS::DEPTH_STENCIL); @@ -277,7 +282,7 @@ namespace SHADE "Normals", "Albedo", "Scene", - "SSAO Blur" + "SSAO Blur", }, { SHGraphicsConstants::RenderGraphEntityNames::GBUFFER_PASS .data()}); @@ -763,6 +768,9 @@ namespace SHADE // Create new renderer for the light component and give it to the light component Handle newRenderer = resourceManager.Create(device, swapchain->GetNumImages(), descPool, SHRenderer::PROJECTION_TYPE::ORTHOGRAPHIC); lightComp->SetRenderer (newRenderer); + + // assign shadow map index to light component + lightComp->SetShadowMapIndex (lightingSubSystem->GetNumShadowMaps()); } // Add the shadow map resource to the graph diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightComponent.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightComponent.cpp index 4dc6e83e..6943ec09 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightComponent.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightComponent.cpp @@ -129,6 +129,11 @@ namespace SHADE renderer = newRenderer; } + void SHLightComponent::SetShadowMapIndex(uint32_t index) noexcept + { + lightData.shadowMapIndex = index; + } + SHLightData const& SHLightComponent::GetLightData(void) const noexcept { return lightData; diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightComponent.h b/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightComponent.h index 4019d2f4..4974f3f5 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightComponent.h +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightComponent.h @@ -55,6 +55,7 @@ namespace SHADE void SetStrength (float value) noexcept; // serialized void SetEnableShadow (bool flag) noexcept; void SetRenderer (Handle newRenderer) noexcept; + void SetShadowMapIndex (uint32_t index) noexcept; SHLightData const& GetLightData (void) const noexcept; diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightingSubSystem.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightingSubSystem.cpp index 6beac351..c3ba7ec3 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightingSubSystem.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightingSubSystem.cpp @@ -395,7 +395,7 @@ namespace SHADE switch (lightComp->GetLightData().type) { case SH_LIGHT_TYPE::DIRECTIONAL: - return SHMatrix::Transpose (SHMatrix::LookAtLH(/*lightComp->GetLightData().position*/SHVec3(-0.7768f, 3.82611f, 9.23839f), SHVec3(-0.7619f, 3.30361f, 8.38588f), SHVec3(0.0f, -1.0f, 0.0f))); + return SHMatrix::Transpose (SHMatrix::LookAtLH(/*lightComp->GetLightData().position*/SHVec3(1.27862f, 4.78952f, 4.12811f), SHVec3(-0.280564f, -0.66262f, -0.69422f), SHVec3(0.0f, -1.0f, 0.0f))); case SH_LIGHT_TYPE::POINT: return {}; case SH_LIGHT_TYPE::SPOT: @@ -478,6 +478,7 @@ namespace SHADE //#endif shadowMapSampler = inShadowMapSampler; + shadowMaps.clear(); //numLightComponents = 0; #pragma endregion } @@ -516,7 +517,7 @@ namespace SHADE if (auto renderer = light.GetRenderer()) { //SHMatrix orthoMatrix = SHMatrix::OrthographicRH() - renderer->UpdateDataManual(frameIndex, GetViewMatrix(&light), SHMatrix::OrthographicLH(12.0f, 12.0f, 0.1f, 20.0f)); + renderer->UpdateDataManual(frameIndex, GetViewMatrix(&light), SHMatrix::OrthographicLH(9.0f, 9.0f, 0.1f, 20.0f)); } auto enumValue = SHUtilities::ConvertEnum(light.GetLightData().type); @@ -595,7 +596,7 @@ namespace SHADE uint32_t SHLightingSubSystem::AddShadowMap(Handle newShadowMap, EntityID lightEntity) noexcept { // Add to container of shadow maps - shadowMapIndexing.emplace(lightEntity, shadowMaps.size()); + shadowMapIndexing.emplace(lightEntity, static_cast (shadowMaps.size())); shadowMaps.emplace_back(newShadowMap); // Just use the image view stored in the resource @@ -684,4 +685,9 @@ namespace SHADE return shadowMapImageSamplers[index]; } + uint32_t SHLightingSubSystem::GetNumShadowMaps(void) const noexcept + { + return static_cast(shadowMaps.size()); + } + } diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightingSubSystem.h b/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightingSubSystem.h index 43d901fc..7794a2fb 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightingSubSystem.h +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightingSubSystem.h @@ -223,6 +223,7 @@ namespace SHADE /*-----------------------------------------------------------------------*/ Handle GetLightDataDescriptorSet (void) const noexcept; std::tuple, Handle, vk::ImageLayout> const& GetViewSamplerLayout (uint32_t index) const noexcept; + uint32_t GetNumShadowMaps (void) const noexcept; }; } From 4cd9a6cea0af59019e70fd2780c1cc0775a4cab4 Mon Sep 17 00:00:00 2001 From: Brandon Mak Date: Wed, 11 Jan 2023 10:35:29 +0800 Subject: [PATCH 34/45] shadows WIP --- Assets/Scenes/Scene2.shade | 10 +++---- Assets/Shaders/DeferredComposite_CS.glsl | 26 ++++++++++++------ Assets/Shaders/DeferredComposite_CS.shshaderb | Bin 6277 -> 7493 bytes SHADE_Engine/src/Camera/SHCameraSystem.cpp | 4 ++- .../MiddleEnd/Interface/SHGraphicsSystem.cpp | 3 +- .../MiddleEnd/Lights/SHLightingSubSystem.cpp | 5 ++-- .../MiddleEnd/Pipeline/SHPipelineLibrary.cpp | 3 +- 7 files changed, 33 insertions(+), 18 deletions(-) diff --git a/Assets/Scenes/Scene2.shade b/Assets/Scenes/Scene2.shade index c8aa9c6d..de902c55 100644 --- a/Assets/Scenes/Scene2.shade +++ b/Assets/Scenes/Scene2.shade @@ -5,7 +5,7 @@ Components: Transform Component: Translate: {x: 0, y: 0.304069757, z: 1.73034382} - Rotate: {x: -1.48352981, y: 0, z: 0} + Rotate: {x: 0, y: 0, z: 0} Scale: {x: 1, y: 1, z: 1} IsActive: true Camera Component: @@ -26,8 +26,8 @@ NumberOfChildren: 1 Components: Transform Component: - Translate: {x: 0, y: 0, z: 0} - Rotate: {x: 0, y: 0, z: 0} + Translate: {x: -1.86388135, y: 0.0544953719, z: 0} + Rotate: {x: -0, y: 0, z: -0} Scale: {x: 1, y: 1, z: 1} IsActive: true Renderable Component: @@ -56,9 +56,9 @@ NumberOfChildren: 0 Components: Light Component: - Position: {x: 0, y: 0, z: 0} + Position: {x: 3, y: 4.5, z: 7} Type: Directional - Direction: {x: 0, y: 0, z: 1} + Direction: {x: -0.298000008, y: 0.522498012, z: 0.798600018} Color: {x: 1, y: 1, z: 1, w: 1} Layer: 4294967295 Strength: 0 diff --git a/Assets/Shaders/DeferredComposite_CS.glsl b/Assets/Shaders/DeferredComposite_CS.glsl index 576ce74b..51f147bb 100644 --- a/Assets/Shaders/DeferredComposite_CS.glsl +++ b/Assets/Shaders/DeferredComposite_CS.glsl @@ -24,7 +24,8 @@ layout(set = 3, binding = 1, rgba32f) uniform image2D normals; layout(set = 3, binding = 2, rgba8) uniform image2D albedo; layout(set = 3, binding = 3, r32ui) uniform uimage2D lightLayerData; layout(set = 3, binding = 4, r8) uniform image2D ssaoBlurredImage; -layout(set = 3, binding = 5, rgba8) uniform image2D targetImage; +layout(set = 3, binding = 5, rgba8) uniform image2D positionWorldSpace; +layout(set = 3, binding = 6, rgba8) uniform image2D targetImage; layout (set = 4, binding = 0) uniform sampler2D shadowMaps[]; // for textures (global) @@ -47,10 +48,12 @@ layout(std430, set = 1, binding = 4) buffer AmbientLightData AmbientLightStruct aLightData[]; } AmbLightData; -// bool IsInShadow (sampler2D shadowMap, vec2 coords, float depth, mat4 lightVP) -// { -// // vec4 fragPosLightPOV = lightVP * -// } +float CalcShadowValue (sampler2D shadowMap, vec4 worldSpaceFragPos, mat4 lightPV) +{ + vec4 fragPosLightPOV = lightPV * worldSpaceFragPos; + vec3 converted = (fragPosLightPOV.xyz / fragPosLightPOV.w) * vec3(0.5f) + vec3(0.5f); + return step (fragPosLightPOV.z, texture(shadowMap, converted.xy).r); +} void main() { @@ -61,6 +64,9 @@ void main() vec3 pixelDiffuse = imageLoad (albedo, globalThread).rgb; // Get position of fragment in world space + vec4 positionWorld = vec4 (imageLoad (positionWorldSpace, globalThread).rgb, 1.0f); + + // Get position of fragment in view spacee vec3 positionView = imageLoad (positions, globalThread).rgb; // normal of fragment @@ -100,7 +106,7 @@ void main() if ((DirLightData.dLightData[i].shadowData & uint(1)) == 1) { // calculate shadow map here - vec2 texCoord = vec2 (gl_GlobalInvocationID.xy) / vec2 (imageSize (targetImage)); + fragColor *= CalcShadowValue (shadowMaps[0], positionWorld, DirLightData.dLightData[i].pvMatrix).xxx; } } } @@ -111,7 +117,11 @@ void main() // store result into result image imageStore(targetImage, ivec2(gl_GlobalInvocationID.xy), vec4(fragColor.rgb, 1.0f)); - // imageStore(targetImage, ivec2(gl_GlobalInvocationID.xy), shadowMapColor); - //imageStore(targetImage, ivec2(gl_GlobalInvocationID.xy), vec4(ssaoVal.rrr, 1.0f)); + // vec2 normTexCoords = vec2 (gl_GlobalInvocationID.xy) / vec2 (1024.0f); + // vec4 shadowMapVal = texture(shadowMaps[0], normTexCoords); + // if (normTexCoords.x > 1.0f || normTexCoords.y > 1.0f) + // shadowMapVal = vec4(0.0f); + + // imageStore(targetImage, ivec2(gl_GlobalInvocationID.xy), shadowMapVal.xxxx); } \ No newline at end of file diff --git a/Assets/Shaders/DeferredComposite_CS.shshaderb b/Assets/Shaders/DeferredComposite_CS.shshaderb index 633fd1975d4df1e6788128068fcfc40efa3fb9f7..8a11aa08d53003ad9e277c52698e550336f1e4bb 100644 GIT binary patch literal 7493 zcmZ{n33#1V5r+R}2MR6wUQ!UPQh{Qnl$NEWG*nVrEEaGf+$J~am7CmfbJG??2qKH9 zC|Wmg7X-lt6mdlmRNPk-S40GNL0nh`eBb|`Nq_o0o<83*GvCaaGw1wsPH(yw@15nN zwPnA~ESr{Xoo$xhA?eEQ9 z%SYGO21<=eZFKq4G_MCaR@qptF0Bj=O^kCQ&TGq-AxqV@<-wYEM|Qk%wegCRPqzL% zt~2Y~lF#?moU^9jTT>}-z$90Dc4~od?!7%b4Q{knA1PIvk=D>Z#f|6lEG|EvzS3Fc zdUK6+&*GMr8l~nMHj8K1Q>)ep&G+CpnED>c(N51;LnV)C&(1;Shuu?~7;TKR^RAqO z&QjadMoZN^#CaY3bB?_|R;!FQk|%ikaeS;6G|`=Tyj@-zSz9Sj&1lwrE_}Ynw0=AB z7r`wl#IA1CCk7g>-Spv(T(RA}F6UX-c%xn(9d3A3Q@nLm#+Rg9u$i~6fr%>DWOzks z{0z>mGrI(?xPJ4Ln{)IzO8LIy{5!Hs;h0lk-Ct{V6@2royRsY5mo~5B)R}JHTSx9E zWb?VBd#=uNUt88M@4kxldq(o^Yp~hk&pIQ0ZD4Huic+Iq*@!x|hHp=^Ut(Wf*{9*Q zthsm|`W=IXoqK<7f@5BR^*lPWTc%=9$h*ICc7CPve!W9qvu2K^`3b#0_rOo}F-_=Q zxesovR4-WFJ$VsMpJb%STGX>F&2@kK=2U>cizmlkO#- z@9s8WFQD!FurKgj!=8=q`D^CJ2j~XI#GQ-$)+gsYe}l4le48nvHWE zj_)GL)&|xKk{kok9hAw(XXxF8lB(HLf(tr!H#rD3vxEu%%{E!T70|R zv#q#!&ACi_)(Cq~;_XA@y2-y)ijvzEduycmtWUpd8!NvXw%<-Y{M(}Im!Hkd?U2ql zuXFXA*ItviZu7by=gIGk?N7UI;5Z=Jv(O`cA9Ul*pay!uW9CW9g5x!rUBb$}hsN?OPZ5 zjzl+~@qWLhNbA#I9In>}T=UrEFxH&f%MurMU$SG5C+7C#QLb?^`u|(QbzS3>G~ZZr zYM+|8uzfQf#t$Mr2lwt8LrFJZak!7!z&XRoVXQf|*Co!gJOkZ)?mNCQKNmBED!eb4DFkpnJ~xuT1_9^5_N?B<0yB~Jqj%c(Sx&gWL)o$M*6FZ69)s~5T;nk0LSRp7`wsRL zY~Re|3%33>TiB-+Z0}vUU>on>CXwHKV+Gs$;NKPD*S@M?JO7q~?YnzN!8YH01>5)i z{(^11zXi>I1pD)hjsT0nIoQ5;M?E7pG_y6Z2YKPHiH0+#~!q_4Q{o3ZuZna=Anbo0qypK5svy8Jxw zDCc%L(qUct-U{TbOWiuWQ*Q%3$@W~{4x+A2=-q3 z(ax{XEc+d}2Q+{&p7rm+@xXoDmu&m|0rWqBsM}ok0_ROf{t@VR-u=m5n0n$**gF8% zGpGLeHh)IfA26T2_ZQ$f#&`H@;*5_omh+8>y(+cit|+yyMS2#>IE%lbdlvD2{T*HI z3SfSHa?ZaR>HKSu&VLB`Pw;TE7a;!y7J~Tw_HT4!|o%0W8C{eAo}7Ebp4L_zv4yc&X>0iW1eQFyuI*0T_-Rx literal 6277 zcmZveiJR4B6~})wFvB3Ak|Lx?gS220nu&@8I50M1Gb};0H~wbkGIR5C?{x1S7NdfQ zvLsq)U#%=l4J}(S%51THwST4Ud3v5cpWl7Y@QcTn=gc|hd)D`T&-=UdA6b?aYfks7 zd0Ez#U6d`#{@#JI#aTBOYkQ`em3#t~KKqK^CTpWZg=t&; zKw~^_R~z+hgN3~}TMD199;(y^tNZrNw5V>}-0VttUK^`SG}L>ue)Q=^t7`DxYULm* zcu%&fgtrp58eVTS_vf{ar}?g(#acz&_2{+gD}GT#J4-!dp}MMC0H{KAj9bob>>Bweac5?t%|nV{2ok-fpprz5)Zz(s4KHd984< z_g?-P!&R}@YQ3E-fqRdw=|;eK&nx_$j(q=EwK5yg>3bNw*iWk8ga00|fs*g;c5`OD zZS9T?bL5Kc7JV6KU#)htQlD&3>1SW!_El{Sr0F@2+t>I^jq#cs$y@huZu7FeVCDLq zQ|`oQbLGXp#c;Er6Co>b~!5AkQ-N zmB^mC`YL$YuCCps-S=F!t84E{cHeT@uCCpBchaNp%w=9zV8)AikAc~fSYHVz+?eR&Cs+Wy2?@3rt=s2?&e-cjVYKQZI< z_dS*SQ@6j^vvcf*;WxL4HMegd;?(u=2d<3qV_E!m1!jzX z(~!L%g}Ya|KF8p$=+(W7&4Khk4lnOjeI?YD?9RIO@K@JvUE`hevRz%f{cHad+_`>! z(w%+%!>+Es>oO*!8@`fi)>B@BXWX4VEk*YX#I*OLJ9lD|{udQEe^~lkU(B5Pdq3t9 z-;i|QU*x|8+5Gxn!Cz;qA2QbxxO(Ke0=ZMyJNk($}2o zem7k9y$)^;`@W99%C|r+b@y~zp=H?`PS~^DkT7w{Io|?)OGa`&g3WEZmR(x#&uEf8X`>Y?tBxF1Wtl!3ti6 z-y6^Qd@otyqi$bE;riIuF}S*Q-vc+Vn0=`qPgtDCiKOd)D#_MT{}|kRu&?lc5ZUjB zy7eD|x*%ugQMkU=H2zy~ zdio>!rI7RK_rdR%m}I}!`ZN5wYDMj~T^=AcGH*-Sv z?ESf%w|{|nZuVAKgUZD41psz0JYmu)n>Bg@w>At;z{4Yk=M?CVs1X)~imGk$bYmfXdMZPxa=D!Xq=U;=ak9g#N8M3(KD(81Dw4471 z_$#0rlWzW-pvb=t`DRETaqq_Wcq=6C@=Tm9F=gj!Lz11T%}E}BZ-M^JNp6KZ-|~OZ z#~tujK`!k>aP4yY?1kS6nZtRphi$W1PqrO-2Q&`U1`oXxu-XE6H8k)y9MP;d?y(;qCps1&93ewkaoXapKO1dK^q_I?7kP> z`Z2rjLp}~!PumG7V&9LfJ!bblWb=u~?0x`QJZATPWS4zu`yeD{U&?U~A3}~kP9c97 ziaxZ({=NT?B>TcNJ0C@NKD`rd-pfh2xcQCwI3yPOCy-Yccuz5ppDg4o6JN+Xc1Ax1 znODEtAbrez8m=vR|1@&+K8E}mD0AHkd>*o1ypt~^ zOk9e0@_?A7`F8Welg z_8_FMv-WjJd(6u>67~@MVdi@m{F{)tnBTfb;4bGy+ryBU^P+6-1@OnAMbHlJ>M{7Y z6DIER9H;Sp6#gAZyRpmQ--VulrqJiXzn8E^^8bFq?xRQJe*l?7+%q|oFyD0aCRe{7 zZm)9n14)<18U7I2GmP)ekC4TtAoFVzGv05B`DWn8KMDT{bS~-k|5Io_6#s8|3Rxd< zf0v!3pFvMSE^C~Hic2>selZtf`g^9oggjIA1@K=%<@ L+W$+ITcQ5}wX$pv diff --git a/SHADE_Engine/src/Camera/SHCameraSystem.cpp b/SHADE_Engine/src/Camera/SHCameraSystem.cpp index 924100d4..703de2c0 100644 --- a/SHADE_Engine/src/Camera/SHCameraSystem.cpp +++ b/SHADE_Engine/src/Camera/SHCameraSystem.cpp @@ -313,7 +313,9 @@ namespace SHADE camera.orthoProjMatrix(2, 3) = -n / (f-n); camera.orthoProjMatrix(3, 3) = 1.0f; - //camera.orthoProjMatrix = SHMatrix::OrthographicRH(camera.GetWidth(), camera.GetHeight(), camera.GetNear(), camera.GetFar()); + //camera.perspProjMatrix = SHMatrix::OrthographicLH(9.0f, 9.0f, 0.1f, 20.0f); + camera.orthoProjMatrix = SHMatrix::OrthographicRH(camera.GetWidth(), camera.GetHeight(), camera.GetNear(), camera.GetFar()); + //camera.perspProjMatrix = SHMatrix::OrthographicLH(4.0f, 4.0f, 0.1f, 200.0f); //camera.projMatrix.Transpose(); camera.dirtyProj = false; diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp index 64fc2431..14326b93 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp @@ -283,6 +283,7 @@ namespace SHADE "Albedo", "Scene", "SSAO Blur", + "Position World Space" }, { SHGraphicsConstants::RenderGraphEntityNames::GBUFFER_PASS .data()}); @@ -290,7 +291,7 @@ namespace SHADE /*-----------------------------------------------------------------------*/ /* DEFERRED COMPOSITE SUBPASS INIT */ /*-----------------------------------------------------------------------*/ - auto deferredCompositeCompute = deferredCompositeNode->AddNodeCompute(SHGraphicsConstants::RenderGraphEntityNames::DEFERRED_COMPOSITE_COMPUTE.data(), deferredCompositeShader, {"Position", "Normals", "Albedo", "Light Layer Indices", "SSAO Blur", "Scene"}, {}, SHLightingSubSystem::MAX_SHADOWS); + auto deferredCompositeCompute = deferredCompositeNode->AddNodeCompute(SHGraphicsConstants::RenderGraphEntityNames::DEFERRED_COMPOSITE_COMPUTE.data(), deferredCompositeShader, {"Position", "Normals", "Albedo", "Light Layer Indices", "SSAO Blur", "Position World Space", "Scene"}, {}, SHLightingSubSystem::MAX_SHADOWS); deferredCompositeCompute->AddPreComputeFunction([=](Handle cmdBuffer, uint32_t frameIndex) { lightingSubSystem->PrepareShadowMapsForRead(cmdBuffer); diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightingSubSystem.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightingSubSystem.cpp index c3ba7ec3..31f95921 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightingSubSystem.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightingSubSystem.cpp @@ -395,7 +395,8 @@ namespace SHADE switch (lightComp->GetLightData().type) { case SH_LIGHT_TYPE::DIRECTIONAL: - return SHMatrix::Transpose (SHMatrix::LookAtLH(/*lightComp->GetLightData().position*/SHVec3(1.27862f, 4.78952f, 4.12811f), SHVec3(-0.280564f, -0.66262f, -0.69422f), SHVec3(0.0f, -1.0f, 0.0f))); + return SHMatrix::Transpose(SHMatrix::LookAtLH(lightComp->GetLightData().position, lightComp->GetLightData().direction, SHVec3(0.0f, -1.0f, 0.0f))); + //return SHMatrix::Transpose(SHMatrix::LookAtLH(/*lightComp->GetLightData().position*/SHVec3(1.27862f, 4.78952f, 4.12811f), SHVec3(-0.280564f, -0.66262f, -0.69422f), SHVec3(0.0f, -1.0f, 0.0f))); case SH_LIGHT_TYPE::POINT: return {}; case SH_LIGHT_TYPE::SPOT: @@ -517,7 +518,7 @@ namespace SHADE if (auto renderer = light.GetRenderer()) { //SHMatrix orthoMatrix = SHMatrix::OrthographicRH() - renderer->UpdateDataManual(frameIndex, GetViewMatrix(&light), SHMatrix::OrthographicLH(9.0f, 9.0f, 0.1f, 20.0f)); + renderer->UpdateDataManual(frameIndex, GetViewMatrix(&light), SHMatrix::OrthographicLH(5.0f, 5.0f, 0.1f, 20.0f)); } auto enumValue = SHUtilities::ConvertEnum(light.GetLightData().type); diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Pipeline/SHPipelineLibrary.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Pipeline/SHPipelineLibrary.cpp index 6d7e6104..a5dd929c 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Pipeline/SHPipelineLibrary.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Pipeline/SHPipelineLibrary.cpp @@ -17,7 +17,7 @@ namespace SHADE SHPipelineLayoutParams params { - .shaderModules = std::move (modules), + .shaderModules = std::move(modules), .predefinedDescSetLayouts = SHGraphicsPredefinedData::GetSystemData(SHGraphicsPredefinedData::SystemType::BATCHING).descSetLayouts }; @@ -35,6 +35,7 @@ namespace SHADE auto const& subpassColorReferences = subpass->GetColorAttachmentReferences(); colorBlendState.attachments.reserve(subpassColorReferences.size()); + for (auto& att : subpassColorReferences) { colorBlendState.attachments.push_back(vk::PipelineColorBlendAttachmentState From f217562fefe0f546dbdb2d760c8a0320e43da6a4 Mon Sep 17 00:00:00 2001 From: Brandon Mak Date: Wed, 11 Jan 2023 20:04:53 +0800 Subject: [PATCH 35/45] Shadows are sort of working --- Assets/Application.SHConfig | 2 +- Assets/Scenes/MainGame.shade | 9 +++++++-- Assets/Shaders/DeferredComposite_CS.glsl | 14 +++++++++++++- Assets/Shaders/DeferredComposite_CS.shshaderb | Bin 7493 -> 8333 bytes SHADE_Engine/src/Camera/SHCameraSystem.cpp | 2 +- .../MiddleEnd/Interface/SHGraphicsSystem.cpp | 9 +++++++-- .../MiddleEnd/Interface/SHGraphicsSystem.h | 1 + .../MiddleEnd/Lights/SHLightingSubSystem.cpp | 4 ++-- .../MiddleEnd/Pipeline/SHPipelineLibrary.cpp | 4 +++- .../MiddleEnd/Pipeline/SHPipelineLibrary.h | 3 ++- 10 files changed, 37 insertions(+), 11 deletions(-) diff --git a/Assets/Application.SHConfig b/Assets/Application.SHConfig index 10ba697b..370665d2 100644 --- a/Assets/Application.SHConfig +++ b/Assets/Application.SHConfig @@ -1,4 +1,4 @@ Start in Fullscreen: false -Starting Scene ID: 87285316 +Starting Scene ID: 86098106 Window Size: {x: 1920, y: 1080} Window Title: SHADE Engine \ No newline at end of file diff --git a/Assets/Scenes/MainGame.shade b/Assets/Scenes/MainGame.shade index 49602e78..69bb9e7d 100644 --- a/Assets/Scenes/MainGame.shade +++ b/Assets/Scenes/MainGame.shade @@ -8440,10 +8440,15 @@ IsActive: true NumberOfChildren: 0 Components: + Transform Component: + Translate: {x: 2.05652523, y: 1.65113854, z: -6.62914371} + Rotate: {x: -0, y: 0, z: -0} + Scale: {x: 1, y: 1, z: 1} + IsActive: true Light Component: - Position: {x: 0, y: 0, z: 0} + Position: {x: 0, y: 1.5, z: -6.71799994} Type: Directional - Direction: {x: 15, y: 90, z: 15} + Direction: {x: 0, y: 0, z: -1.11899996} Color: {x: 1, y: 1, z: 1, w: 1} Layer: 4294967295 Strength: 1 diff --git a/Assets/Shaders/DeferredComposite_CS.glsl b/Assets/Shaders/DeferredComposite_CS.glsl index 51f147bb..b31daf25 100644 --- a/Assets/Shaders/DeferredComposite_CS.glsl +++ b/Assets/Shaders/DeferredComposite_CS.glsl @@ -52,7 +52,19 @@ float CalcShadowValue (sampler2D shadowMap, vec4 worldSpaceFragPos, mat4 lightPV { vec4 fragPosLightPOV = lightPV * worldSpaceFragPos; vec3 converted = (fragPosLightPOV.xyz / fragPosLightPOV.w) * vec3(0.5f) + vec3(0.5f); - return step (fragPosLightPOV.z, texture(shadowMap, converted.xy).r); + + float sampledDepth = texture(shadowMap, converted.xy).r; + + if (converted.x < 0.0f || converted.x > 1.0f || converted.y < 0.0f || converted.y > 1.0f) + return 1.0f; + + if (fragPosLightPOV.z > sampledDepth && fragPosLightPOV.w > 0.0f) + { + return 0.3f; + } + else + return 1.0f; + // return step (fragPosLightPOV.z, ); } void main() diff --git a/Assets/Shaders/DeferredComposite_CS.shshaderb b/Assets/Shaders/DeferredComposite_CS.shshaderb index 8a11aa08d53003ad9e277c52698e550336f1e4bb..31ea035c0a64e3e947bae4ceb483ce0661300999 100644 GIT binary patch literal 8333 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 X46+VodvI={ixhA?eEQ9 z%SYGO21<=eZFKq4G_MCaR@qptF0Bj=O^kCQ&TGq-AxqV@<-wYEM|Qk%wegCRPqzL% zt~2Y~lF#?moU^9jTT>}-z$90Dc4~od?!7%b4Q{knA1PIvk=D>Z#f|6lEG|EvzS3Fc zdUK6+&*GMr8l~nMHj8K1Q>)ep&G+CpnED>c(N51;LnV)C&(1;Shuu?~7;TKR^RAqO z&QjadMoZN^#CaY3bB?_|R;!FQk|%ikaeS;6G|`=Tyj@-zSz9Sj&1lwrE_}Ynw0=AB z7r`wl#IA1CCk7g>-Spv(T(RA}F6UX-c%xn(9d3A3Q@nLm#+Rg9u$i~6fr%>DWOzks z{0z>mGrI(?xPJ4Ln{)IzO8LIy{5!Hs;h0lk-Ct{V6@2royRsY5mo~5B)R}JHTSx9E zWb?VBd#=uNUt88M@4kxldq(o^Yp~hk&pIQ0ZD4Huic+Iq*@!x|hHp=^Ut(Wf*{9*Q zthsm|`W=IXoqK<7f@5BR^*lPWTc%=9$h*ICc7CPve!W9qvu2K^`3b#0_rOo}F-_=Q zxesovR4-WFJ$VsMpJb%STGX>F&2@kK=2U>cizmlkO#- z@9s8WFQD!FurKgj!=8=q`D^CJ2j~XI#GQ-$)+gsYe}l4le48nvHWE zj_)GL)&|xKk{kok9hAw(XXxF8lB(HLf(tr!H#rD3vxEu%%{E!T70|R zv#q#!&ACi_)(Cq~;_XA@y2-y)ijvzEduycmtWUpd8!NvXw%<-Y{M(}Im!Hkd?U2ql zuXFXA*ItviZu7by=gIGk?N7UI;5Z=Jv(O`cA9Ul*pay!uW9CW9g5x!rUBb$}hsN?OPZ5 zjzl+~@qWLhNbA#I9In>}T=UrEFxH&f%MurMU$SG5C+7C#QLb?^`u|(QbzS3>G~ZZr zYM+|8uzfQf#t$Mr2lwt8LrFJZak!7!z&XRoVXQf|*Co!gJOkZ)?mNCQKNmBED!eb4DFkpnJ~xuT1_9^5_N?B<0yB~Jqj%c(Sx&gWL)o$M*6FZ69)s~5T;nk0LSRp7`wsRL zY~Re|3%33>TiB-+Z0}vUU>on>CXwHKV+Gs$;NKPD*S@M?JO7q~?YnzN!8YH01>5)i z{(^11zXi>I1pD)hjsT0nIoQ5;M?E7pG_y6Z2YKPHiH0+#~!q_4Q{o3ZuZna=Anbo0qypK5svy8Jxw zDCc%L(qUct-U{TbOWiuWQ*Q%3$@W~{4x+A2=-q3 z(ax{XEc+d}2Q+{&p7rm+@xXoDmu&m|0rWqBsM}ok0_ROf{t@VR-u=m5n0n$**gF8% zGpGLeHh)IfA26T2_ZQ$f#&`H@;*5_omh+8>y(+cit|+yyMS2#>IE%lbdlvD2{T*HI z3SfSHa?ZaR>HKSu&VLB`Pw;TE7a;!y7J~Tw_HT4!|o%0W8C{eAo}7Ebp4L_zv4yc&X>0iW1eQFyuI*0T_-Rx diff --git a/SHADE_Engine/src/Camera/SHCameraSystem.cpp b/SHADE_Engine/src/Camera/SHCameraSystem.cpp index 703de2c0..6feece48 100644 --- a/SHADE_Engine/src/Camera/SHCameraSystem.cpp +++ b/SHADE_Engine/src/Camera/SHCameraSystem.cpp @@ -315,7 +315,7 @@ namespace SHADE //camera.perspProjMatrix = SHMatrix::OrthographicLH(9.0f, 9.0f, 0.1f, 20.0f); camera.orthoProjMatrix = SHMatrix::OrthographicRH(camera.GetWidth(), camera.GetHeight(), camera.GetNear(), camera.GetFar()); - //camera.perspProjMatrix = SHMatrix::OrthographicLH(4.0f, 4.0f, 0.1f, 200.0f); + //camera.perspProjMatrix = SHMatrix::OrthographicLH(5.0f, 5.0f, 0.1f, 20.0f); //camera.projMatrix.Transpose(); camera.dirtyProj = false; diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp index 14326b93..79053c2f 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp @@ -181,6 +181,8 @@ namespace SHADE // Create Default Viewport worldViewport = AddViewport(vk::Viewport(0.0f, 0.0f, static_cast(window->GetWindowSize().first), static_cast(window->GetWindowSize().second), 0.0f, 1.0f)); + shadowMapViewport = AddViewport(vk::Viewport(0.0f, 0.0f, static_cast(SHLightingSubSystem::SHADOW_MAP_WIDTH), static_cast(SHLightingSubSystem::SHADOW_MAP_HEIGHT), 0.0f, 1.0f)); + std::vector> renderContextCmdPools{ swapchain->GetNumImages() }; for (uint32_t i = 0; i < renderContextCmdPools.size(); ++i) { @@ -781,7 +783,7 @@ namespace SHADE auto shadowMapNode = renderGraph->AddNodeAfter(SHGraphicsConstants::RenderGraphEntityNames::SHADOW_MAP_PASS.data() + resourceName, {resourceName.c_str()}, SHGraphicsConstants::RenderGraphEntityNames::GBUFFER_PASS.data()); // Add a subpass to render to that shadow map - auto newSubpass = shadowMapNode->RuntimeAddSubpass(resourceName + " Subpass", worldViewport, lightComp->GetRenderer()); + auto newSubpass = shadowMapNode->RuntimeAddSubpass(resourceName + " Subpass", shadowMapViewport, lightComp->GetRenderer()); newSubpass->AddDepthOutput(resourceName, SH_RENDER_GRAPH_RESOURCE_FLAGS::DEPTH); // regenerate the node @@ -793,8 +795,11 @@ namespace SHADE SHPipelineLibrary tempLibrary{}; Handle rgNode = renderGraph->GetNode(SHGraphicsConstants::RenderGraphEntityNames::SHADOW_MAP_PASS.data()); + SHRasterizationState rasterState{}; + rasterState.cull_mode = vk::CullModeFlagBits::eBack; + tempLibrary.Init(device); - tempLibrary.CreateGraphicsPipelines({ shadowMapVS, {} }, shadowMapNode->GetRenderpass(), newSubpass, SHGraphicsPredefinedData::GetShadowMapViState()); + tempLibrary.CreateGraphicsPipelines({ shadowMapVS, {} }, shadowMapNode->GetRenderpass(), newSubpass, SHGraphicsPredefinedData::GetShadowMapViState(), rasterState); shadowMapPipeline = tempLibrary.GetGraphicsPipeline({ shadowMapVS, {} }); } newSubpass->SetCompanionSubpass(companionSubpass, shadowMapPipeline); // set companion subpass and pipeline diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.h b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.h index b8c43c75..9e30e204 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.h +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.h @@ -441,6 +441,7 @@ namespace SHADE #endif Handle worldViewport; // Whole screen + Handle shadowMapViewport; std::vector> viewports; // Additional viewports // Renderers diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightingSubSystem.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightingSubSystem.cpp index 31f95921..2e3b21d9 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightingSubSystem.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightingSubSystem.cpp @@ -395,7 +395,7 @@ namespace SHADE switch (lightComp->GetLightData().type) { case SH_LIGHT_TYPE::DIRECTIONAL: - return SHMatrix::Transpose(SHMatrix::LookAtLH(lightComp->GetLightData().position, lightComp->GetLightData().direction, SHVec3(0.0f, -1.0f, 0.0f))); + return SHMatrix::Transpose(SHMatrix::LookAtLH(lightComp->GetLightData().position, SHVec3::Normalise (lightComp->GetLightData().direction), SHVec3(0.0f, -1.0f, 0.0f))); //return SHMatrix::Transpose(SHMatrix::LookAtLH(/*lightComp->GetLightData().position*/SHVec3(1.27862f, 4.78952f, 4.12811f), SHVec3(-0.280564f, -0.66262f, -0.69422f), SHVec3(0.0f, -1.0f, 0.0f))); case SH_LIGHT_TYPE::POINT: return {}; @@ -518,7 +518,7 @@ namespace SHADE if (auto renderer = light.GetRenderer()) { //SHMatrix orthoMatrix = SHMatrix::OrthographicRH() - renderer->UpdateDataManual(frameIndex, GetViewMatrix(&light), SHMatrix::OrthographicLH(5.0f, 5.0f, 0.1f, 20.0f)); + renderer->UpdateDataManual(frameIndex, GetViewMatrix(&light), SHMatrix::OrthographicLH(30.0f, 30.0f, 1.0f, 50.0f)); } auto enumValue = SHUtilities::ConvertEnum(light.GetLightData().type); diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Pipeline/SHPipelineLibrary.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Pipeline/SHPipelineLibrary.cpp index a5dd929c..74795034 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Pipeline/SHPipelineLibrary.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Pipeline/SHPipelineLibrary.cpp @@ -7,7 +7,7 @@ namespace SHADE { - Handle SHPipelineLibrary::CreateGraphicsPipelines(std::pair, Handle> const& vsFsPair, Handle renderpass, Handle subpass, SHVertexInputState const& viState/* = SHGraphicsPredefinedData::GetDefaultViState()*/) noexcept + Handle SHPipelineLibrary::CreateGraphicsPipelines(std::pair, Handle> const& vsFsPair, Handle renderpass, Handle subpass, SHVertexInputState const& viState/* = SHGraphicsPredefinedData::GetDefaultViState()*/, SHRasterizationState const& rasterState) noexcept { std::vector> modules{}; if (vsFsPair.first) @@ -53,6 +53,8 @@ namespace SHADE } newPipeline->GetPipelineState().SetColorBlenState(colorBlendState); + + newPipeline->GetPipelineState().SetRasterizationState(rasterState); // Actually construct the pipeline newPipeline->ConstructPipeline(); diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Pipeline/SHPipelineLibrary.h b/SHADE_Engine/src/Graphics/MiddleEnd/Pipeline/SHPipelineLibrary.h index b7485e50..ca46c71a 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Pipeline/SHPipelineLibrary.h +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Pipeline/SHPipelineLibrary.h @@ -34,7 +34,8 @@ namespace SHADE std::pair, Handle> const& vsFsPair, Handle renderpass, Handle subpass, - SHVertexInputState const& viState = SHGraphicsPredefinedData::GetDefaultViState() + SHVertexInputState const& viState = SHGraphicsPredefinedData::GetDefaultViState(), + SHRasterizationState const& rasterState = SHRasterizationState{} ) noexcept; Handle GetGraphicsPipeline (std::pair, Handle> const& vsFsPair) noexcept; bool CheckGraphicsPipelineExistence (std::pair, Handle> const& vsFsPair) noexcept; From 5aa7bfe03e5b1937d43f570db51cef6786862e01 Mon Sep 17 00:00:00 2001 From: maverickdgg Date: Mon, 16 Jan 2023 07:34:44 +0800 Subject: [PATCH 36/45] button fixed --- Assets/Editor/Editor.SHConfig | 4 ++++ Assets/Scenes/UI Test.shade.shmeta | 2 +- SHADE_Engine/src/UI/SHUISystem.cpp | 2 +- 3 files changed, 6 insertions(+), 2 deletions(-) create mode 100644 Assets/Editor/Editor.SHConfig diff --git a/Assets/Editor/Editor.SHConfig b/Assets/Editor/Editor.SHConfig new file mode 100644 index 00000000..51425027 --- /dev/null +++ b/Assets/Editor/Editor.SHConfig @@ -0,0 +1,4 @@ +Start Maximized: true +Working Scene ID: 97161771 +Window Size: {x: 1920, y: 1080} +Style: 0 \ No newline at end of file diff --git a/Assets/Scenes/UI Test.shade.shmeta b/Assets/Scenes/UI Test.shade.shmeta index ad821810..9b0a85f5 100644 --- a/Assets/Scenes/UI Test.shade.shmeta +++ b/Assets/Scenes/UI Test.shade.shmeta @@ -1,3 +1,3 @@ Name: UI Test -ID: 88543249 +ID: 92992815 Type: 5 diff --git a/SHADE_Engine/src/UI/SHUISystem.cpp b/SHADE_Engine/src/UI/SHUISystem.cpp index 95663bc0..cd4ed79a 100644 --- a/SHADE_Engine/src/UI/SHUISystem.cpp +++ b/SHADE_Engine/src/UI/SHUISystem.cpp @@ -158,7 +158,7 @@ namespace SHADE SHVec2 mousePos; SHVec2 windowSize; #ifdef SHEDITOR - windowSize = SHEditorWindowManager::GetEditorWindow()->windowSize; + windowSize = SHEditorWindowManager::GetEditorWindow()->beginContentRegionAvailable; mousePos = SHEditorWindowManager::GetEditorWindow()->viewportMousePos; //mousePos.y = windowSize.y - mousePos.y; SHLOG_INFO("mouse pos: {}, {}", mousePos.x, mousePos.y) From 5190c490c9e3a6805cd9b27126c07d1e4852c6fb Mon Sep 17 00:00:00 2001 From: maverickdgg Date: Mon, 16 Jan 2023 11:36:12 +0800 Subject: [PATCH 37/45] added events --- Assets/Scenes/UI Test.shade | 4 +- Assets/Scenes/UI Test.shade.shmeta | 2 +- SHADE_Engine/src/Events/SHEventDefines.h | 1 + .../src/UI/Events/SHButtonClickEvent.h | 16 +++ SHADE_Engine/src/UI/SHSliderComponent.cpp | 39 ++++++++ SHADE_Engine/src/UI/SHSliderComponent.h | 41 ++++++++ SHADE_Engine/src/UI/SHUISystem.cpp | 98 ++++++++++++++++--- SHADE_Engine/src/UI/SHUISystem.h | 16 ++- 8 files changed, 196 insertions(+), 21 deletions(-) create mode 100644 SHADE_Engine/src/UI/Events/SHButtonClickEvent.h create mode 100644 SHADE_Engine/src/UI/SHSliderComponent.cpp create mode 100644 SHADE_Engine/src/UI/SHSliderComponent.h diff --git a/Assets/Scenes/UI Test.shade b/Assets/Scenes/UI Test.shade index 0aea6f72..d9ce5026 100644 --- a/Assets/Scenes/UI Test.shade +++ b/Assets/Scenes/UI Test.shade @@ -34,7 +34,7 @@ NumberOfChildren: 0 Components: Transform Component: - Translate: {x: 153.399994, y: 0, z: 0} + Translate: {x: 0, y: -3.9000001, z: 0} Rotate: {x: 0, y: 0, z: 0} Scale: {x: 1, y: 1, z: 1} IsActive: true @@ -45,7 +45,7 @@ Toggle Button Component: Non Toggled Texture: 0 Toggled Texture: 0 - Value: false + Value: true IsActive: true Scripts: ~ - EID: 1 diff --git a/Assets/Scenes/UI Test.shade.shmeta b/Assets/Scenes/UI Test.shade.shmeta index 9b0a85f5..0ce3b040 100644 --- a/Assets/Scenes/UI Test.shade.shmeta +++ b/Assets/Scenes/UI Test.shade.shmeta @@ -1,3 +1,3 @@ Name: UI Test -ID: 92992815 +ID: 92642496 Type: 5 diff --git a/SHADE_Engine/src/Events/SHEventDefines.h b/SHADE_Engine/src/Events/SHEventDefines.h index d7bbf5f0..1ad458c4 100644 --- a/SHADE_Engine/src/Events/SHEventDefines.h +++ b/SHADE_Engine/src/Events/SHEventDefines.h @@ -18,4 +18,5 @@ constexpr SHEventIdentifier SH_PHYSICS_COLLIDER_REMOVED_EVENT { 9 }; constexpr SHEventIdentifier SH_EDITOR_ON_PLAY_EVENT { 10 }; constexpr SHEventIdentifier SH_EDITOR_ON_PAUSE_EVENT { 11 }; constexpr SHEventIdentifier SH_EDITOR_ON_STOP_EVENT { 12 }; +constexpr SHEventIdentifier SH_BUTTON_CLICK_EVENT { 13 }; diff --git a/SHADE_Engine/src/UI/Events/SHButtonClickEvent.h b/SHADE_Engine/src/UI/Events/SHButtonClickEvent.h new file mode 100644 index 00000000..35bcdc61 --- /dev/null +++ b/SHADE_Engine/src/UI/Events/SHButtonClickEvent.h @@ -0,0 +1,16 @@ +#pragma once + + +#include "ECS_Base/SHECSMacros.h" + +namespace SHADE +{ + struct SHButtonClickEvent + { + EntityID EID; + // value of the toggle button, default to false if its a button and not a toggle button + bool value{false}; + }; + + +} diff --git a/SHADE_Engine/src/UI/SHSliderComponent.cpp b/SHADE_Engine/src/UI/SHSliderComponent.cpp new file mode 100644 index 00000000..56d1d89b --- /dev/null +++ b/SHADE_Engine/src/UI/SHSliderComponent.cpp @@ -0,0 +1,39 @@ +#include "SHpch.h" +#include "SHSliderComponent.h" + +namespace SHADE +{ + SHSliderComponent::SHSliderComponent() + :size(1.0f), isHovered(false), isClicked(false), value(0.0f) + { + + } + + + float SHSliderComponent::GetValue() const noexcept + { + return value; + } + + void SHSliderComponent::SetValue(float value) noexcept + { + this->value = value; + } + + + +} + + +RTTR_REGISTRATION +{ + using namespace SHADE; + using namespace rttr; + + registration::class_("Slider Component") + .property("Slider Value", &SHSliderComponent::GetValue, &SHSliderComponent::SetValue) + + ; + + +} \ No newline at end of file diff --git a/SHADE_Engine/src/UI/SHSliderComponent.h b/SHADE_Engine/src/UI/SHSliderComponent.h new file mode 100644 index 00000000..bdc57c7e --- /dev/null +++ b/SHADE_Engine/src/UI/SHSliderComponent.h @@ -0,0 +1,41 @@ +#pragma once + +#include + +#include "SH_API.h" +#include "ECS_Base/Components/SHComponent.h" +#include "Math/Vector/SHVec3.h" +#include "Math/Vector/SHVec2.h" +#include "Assets/SHAssetMacros.h" + +namespace SHADE +{ + + class SH_API SHSliderComponent final: public SHComponent + { + public: + SHSliderComponent(); + virtual ~SHSliderComponent() = default; + + SHVec2 size; + + + float GetValue() const noexcept; + + + void SetValue(float value) noexcept; + + + friend class SHUISystem; + private: + + bool isHovered; + bool isClicked; + + float value; + + RTTR_ENABLE() + }; + + +} \ No newline at end of file diff --git a/SHADE_Engine/src/UI/SHUISystem.cpp b/SHADE_Engine/src/UI/SHUISystem.cpp index cd4ed79a..bb98939b 100644 --- a/SHADE_Engine/src/UI/SHUISystem.cpp +++ b/SHADE_Engine/src/UI/SHUISystem.cpp @@ -10,6 +10,13 @@ #include "Editor/SHEditor.h" #include "Resource/SHResourceManager.h" #include "Input/SHInputManager.h" +#include "SHUIComponent.h" +#include "SHButtonComponent.h" +#include "SHToggleButtonComponent.h" +#include "SHSliderComponent.h" +#include "SHCanvasComponent.h" +#include "Events/SHEventManager.hpp" +#include "Events/SHButtonClickEvent.h" namespace SHADE { @@ -164,32 +171,60 @@ namespace SHADE SHLOG_INFO("mouse pos: {}, {}", mousePos.x, mousePos.y) mousePos /= windowSize; SHLOG_INFO("mouse pos normalized: {}, {}", mousePos.x, mousePos.y) + + + +#else + + int x, y; + SHInputManager::GetMouseScreenPosition(&x, &y); + mousePos.x = x; + mousePos.y = y; + auto ws = SHSystemManager::GetSystem()->GetWindow()->GetWindowSize(); + windowSize = { ws.first,ws.second }; + mousePos /= windowSize; #endif SHVec2 camSize{ cameraSystem->GetCameraWidthHeight(0)}; //SHLOG_INFO("TopExtent: {}, {}", topExtent.x, topExtent.y) - topExtent = CanvasToScreenPoint(topExtent); - btmExtent = CanvasToScreenPoint(btmExtent); + topExtent = CanvasToScreenPoint(topExtent,true); + btmExtent = CanvasToScreenPoint(btmExtent,true); //SHLOG_INFO("TopExtent: {}, {} Btm Extent: {}, {}", topExtent.x, topExtent.y, btmExtent.x, btmExtent.y) - topExtent /= camSize; - btmExtent /= camSize; + comp.isClicked = false; if (mousePos.x >= topExtent.x && mousePos.x <= btmExtent.x && mousePos.y >= topExtent.y && mousePos.y <= btmExtent.y) { comp.isHovered = true; +#ifdef SHEDITOR + if (SHSystemManager::GetSystem()->editorState == SHEditor::State::PLAY) + { + if (SHInputManager::GetKeyUp(SHInputManager::SH_KEYCODE::LMB)) + { + comp.isClicked = true; + SHButtonClickEvent clickEvent; + clickEvent.EID = comp.GetEID(); + SHEventManager::BroadcastEvent(clickEvent, SH_BUTTON_CLICK_EVENT); + } + } +#else if (SHInputManager::GetKeyUp(SHInputManager::SH_KEYCODE::LMB)) { comp.isClicked = true; + SHButtonClickEvent clickEvent; + clickEvent.EID = comp.GetEID(); + SHEventManager::BroadcastEvent(clickEvent, SH_BUTTON_CLICK_EVENT); } - SHLOG_INFO("HOVERED") +#endif + + //SHLOG_INFO("HOVERED") } else { comp.isHovered = false; - SHLOG_INFO("NOT HOVERED") + //SHLOG_INFO("NOT HOVERED") } @@ -222,9 +257,25 @@ namespace SHADE SHVec2 mousePos; SHVec2 windowSize; + #ifdef SHEDITOR - windowSize = SHEditorWindowManager::GetEditorWindow()->windowSize; + windowSize = SHEditorWindowManager::GetEditorWindow()->beginContentRegionAvailable; mousePos = SHEditorWindowManager::GetEditorWindow()->viewportMousePos; + //mousePos.y = windowSize.y - mousePos.y; + SHLOG_INFO("mouse pos: {}, {}", mousePos.x, mousePos.y) + mousePos /= windowSize; + SHLOG_INFO("mouse pos normalized: {}, {}", mousePos.x, mousePos.y) + + + +#else + + int x, y; + SHInputManager::GetMouseScreenPosition(&x, &y); + mousePos.x = x; + mousePos.y = y; + auto ws = SHSystemManager::GetSystem()->GetWindow()->GetWindowSize(); + windowSize = { ws.first,ws.second }; mousePos /= windowSize; #endif @@ -232,10 +283,9 @@ namespace SHADE - topExtent = CanvasToScreenPoint(topExtent); - btmExtent = CanvasToScreenPoint(btmExtent); - topExtent /= camSize; - btmExtent /= camSize; + topExtent = CanvasToScreenPoint(topExtent,true); + btmExtent = CanvasToScreenPoint(btmExtent, true); + comp.isClicked = false; @@ -243,11 +293,30 @@ namespace SHADE && mousePos.y >= topExtent.y && mousePos.y <= btmExtent.y) { comp.isHovered = true; +#ifdef SHEDITOR + if (SHSystemManager::GetSystem()->editorState == SHEditor::State::PLAY) + { + if (SHInputManager::GetKeyUp(SHInputManager::SH_KEYCODE::LMB)) + { + comp.isClicked = true; + comp.value = !comp.value; + SHButtonClickEvent clickEvent; + clickEvent.EID = comp.GetEID(); + clickEvent.value = comp.value; + SHEventManager::BroadcastEvent(clickEvent, SH_BUTTON_CLICK_EVENT); + } + } +#else if (SHInputManager::GetKeyUp(SHInputManager::SH_KEYCODE::LMB)) { comp.isClicked = true; comp.value = !comp.value; + SHButtonClickEvent clickEvent; + clickEvent.EID = comp.GetEID(); + clickEvent.value = comp.value; + SHEventManager::BroadcastEvent(clickEvent, SH_BUTTON_CLICK_EVENT); } +#endif } else { @@ -284,7 +353,7 @@ namespace SHADE } } - SHVec2 SHUISystem::CanvasToScreenPoint(SHVec2& const canvasPoint) noexcept + SHVec2 SHUISystem::CanvasToScreenPoint(SHVec2& const canvasPoint, bool normalized) noexcept { SHVec2 result{canvasPoint}; @@ -296,7 +365,10 @@ namespace SHADE result.y *= -1.0f; result += camSize * 0.5f; - return result; + if (normalized) + return result / camSize; + else + return result; } diff --git a/SHADE_Engine/src/UI/SHUISystem.h b/SHADE_Engine/src/UI/SHUISystem.h index a5ba8c4f..ae1091ec 100644 --- a/SHADE_Engine/src/UI/SHUISystem.h +++ b/SHADE_Engine/src/UI/SHUISystem.h @@ -3,15 +3,20 @@ #include "SH_API.h" #include "ECS_Base/System/SHSystem.h" #include "ECS_Base/System/SHSystemRoutine.h" -#include "SHUIComponent.h" -#include "SHButtonComponent.h" -#include "SHToggleButtonComponent.h" -#include "SHCanvasComponent.h" + #include "Scene/SHSceneGraph.h" #include "Scene/SHSceneManager.h" +#include "Math/Vector/SHVec2.h" namespace SHADE { + + class SHButtonComponent; + class SHUIComponent; + class SHToggleButtonComponent; + class SHSliderComponent; + class SHCanvasComponent; + class SH_API SHUISystem final: public SHSystem { public: @@ -67,7 +72,8 @@ namespace SHADE void UpdateButtonComponent(SHButtonComponent& comp) noexcept; void UpdateToggleButtonComponent(SHToggleButtonComponent& comp) noexcept; void UpdateCanvasComponent(SHCanvasComponent& comp) noexcept; - SHVec2 CanvasToScreenPoint(SHVec2& const canvasPoint) noexcept; + + SHVec2 CanvasToScreenPoint(SHVec2& const canvasPoint, bool normalized) noexcept; From 02ba0c6dc91b8ca172659c3499617f4729a75a6d Mon Sep 17 00:00:00 2001 From: maverickdgg Date: Mon, 16 Jan 2023 11:44:34 +0800 Subject: [PATCH 38/45] merge --- Assets/Scenes/UI_Test.shade.shmeta | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Assets/Scenes/UI_Test.shade.shmeta b/Assets/Scenes/UI_Test.shade.shmeta index 0ce3b040..77355480 100644 --- a/Assets/Scenes/UI_Test.shade.shmeta +++ b/Assets/Scenes/UI_Test.shade.shmeta @@ -1,3 +1,3 @@ -Name: UI Test -ID: 92642496 +Name: UI_Test +ID: 87244611 Type: 5 From a41354f2cedf88697a94b3cb2e4668c693688712 Mon Sep 17 00:00:00 2001 From: maverickdgg Date: Mon, 16 Jan 2023 14:35:16 +0800 Subject: [PATCH 39/45] Added changing texture of buttons --- Assets/Application.SHConfig | 2 +- Assets/Scenes/UI_Test.shade | 2 +- SHADE_Engine/src/UI/SHButtonComponent.h | 4 +- SHADE_Engine/src/UI/SHToggleButtonComponent.h | 3 + SHADE_Engine/src/UI/SHUISystem.cpp | 120 ++++++++++++------ 5 files changed, 89 insertions(+), 42 deletions(-) diff --git a/Assets/Application.SHConfig b/Assets/Application.SHConfig index 5673556d..ee5e42a8 100644 --- a/Assets/Application.SHConfig +++ b/Assets/Application.SHConfig @@ -1,4 +1,4 @@ Start in Fullscreen: false -Starting Scene ID: 97158628 +Starting Scene ID: 87244611 Window Size: {x: 1920, y: 1080} Window Title: SHADE Engine \ No newline at end of file diff --git a/Assets/Scenes/UI_Test.shade b/Assets/Scenes/UI_Test.shade index d9ce5026..0026a48b 100644 --- a/Assets/Scenes/UI_Test.shade +++ b/Assets/Scenes/UI_Test.shade @@ -14,7 +14,7 @@ NumberOfChildren: 0 Components: Transform Component: - Translate: {x: -3.5999999, y: 3.0999999, z: 0} + Translate: {x: 0, y: 0, z: 0} Rotate: {x: 0, y: 0, z: 0} Scale: {x: 1, y: 1, z: 1} IsActive: true diff --git a/SHADE_Engine/src/UI/SHButtonComponent.h b/SHADE_Engine/src/UI/SHButtonComponent.h index be6ada3e..3aac09e6 100644 --- a/SHADE_Engine/src/UI/SHButtonComponent.h +++ b/SHADE_Engine/src/UI/SHButtonComponent.h @@ -32,8 +32,10 @@ namespace SHADE friend class SHUISystem; private: - + //Set to true when mouse is hovering over the button. bool isHovered; + //This is set to true when the mouse clicks down, and set back to false when mouse releases. + //The event for the button click will be broadcasted when mouse release. bool isClicked; AssetID defaultTexture; AssetID hoveredTexture; diff --git a/SHADE_Engine/src/UI/SHToggleButtonComponent.h b/SHADE_Engine/src/UI/SHToggleButtonComponent.h index 3217c892..2c77f3ba 100644 --- a/SHADE_Engine/src/UI/SHToggleButtonComponent.h +++ b/SHADE_Engine/src/UI/SHToggleButtonComponent.h @@ -33,7 +33,10 @@ namespace SHADE friend class SHUISystem; private: + //Set to true when mouse is hovering over the button. bool isHovered; + //This is set to true when the mouse clicks down, and set back to false when mouse releases. + //The event for the button click will be broadcasted when mouse release. bool isClicked; bool value; AssetID defaultTexture; diff --git a/SHADE_Engine/src/UI/SHUISystem.cpp b/SHADE_Engine/src/UI/SHUISystem.cpp index bb98939b..84f6a21c 100644 --- a/SHADE_Engine/src/UI/SHUISystem.cpp +++ b/SHADE_Engine/src/UI/SHUISystem.cpp @@ -9,6 +9,7 @@ #include "Editor/EditorWindow/ViewportWindow/SHEditorViewport.h" #include "Editor/SHEditor.h" #include "Resource/SHResourceManager.h" +#include "Assets/SHAssetManager.h" #include "Input/SHInputManager.h" #include "SHUIComponent.h" #include "SHButtonComponent.h" @@ -168,9 +169,9 @@ namespace SHADE windowSize = SHEditorWindowManager::GetEditorWindow()->beginContentRegionAvailable; mousePos = SHEditorWindowManager::GetEditorWindow()->viewportMousePos; //mousePos.y = windowSize.y - mousePos.y; - SHLOG_INFO("mouse pos: {}, {}", mousePos.x, mousePos.y) + //SHLOG_INFO("mouse pos: {}, {}", mousePos.x, mousePos.y) mousePos /= windowSize; - SHLOG_INFO("mouse pos normalized: {}, {}", mousePos.x, mousePos.y) + //SHLOG_INFO("mouse pos normalized: {}, {}", mousePos.x, mousePos.y) @@ -193,31 +194,25 @@ namespace SHADE //SHLOG_INFO("TopExtent: {}, {} Btm Extent: {}, {}", topExtent.x, topExtent.y, btmExtent.x, btmExtent.y) - comp.isClicked = false; + //comp.isClicked = false; if (mousePos.x >= topExtent.x && mousePos.x <= btmExtent.x && mousePos.y >= topExtent.y && mousePos.y <= btmExtent.y) { comp.isHovered = true; -#ifdef SHEDITOR - if (SHSystemManager::GetSystem()->editorState == SHEditor::State::PLAY) - { - if (SHInputManager::GetKeyUp(SHInputManager::SH_KEYCODE::LMB)) + #ifdef SHEDITOR + //if (SHSystemManager::GetSystem()->editorState == SHEditor::State::PLAY) + { + if (SHInputManager::GetKeyDown(SHInputManager::SH_KEYCODE::LMB)) + { + comp.isClicked = true; + } + } + #else + if (SHInputManager::GetKeyDown(SHInputManager::SH_KEYCODE::LMB)) { comp.isClicked = true; - SHButtonClickEvent clickEvent; - clickEvent.EID = comp.GetEID(); - SHEventManager::BroadcastEvent(clickEvent, SH_BUTTON_CLICK_EVENT); } - } -#else - if (SHInputManager::GetKeyUp(SHInputManager::SH_KEYCODE::LMB)) - { - comp.isClicked = true; - SHButtonClickEvent clickEvent; - clickEvent.EID = comp.GetEID(); - SHEventManager::BroadcastEvent(clickEvent, SH_BUTTON_CLICK_EVENT); - } -#endif + #endif //SHLOG_INFO("HOVERED") } @@ -226,15 +221,46 @@ namespace SHADE comp.isHovered = false; //SHLOG_INFO("NOT HOVERED") } - + if (comp.isClicked && SHInputManager::GetKeyUp(SHInputManager::SH_KEYCODE::LMB)) + { + comp.isClicked = false; + SHButtonClickEvent clickEvent; + clickEvent.EID = comp.GetEID(); + SHEventManager::BroadcastEvent(clickEvent, SH_BUTTON_CLICK_EVENT); + } if (SHComponentManager::HasComponent(comp.GetEID())) { - /*auto renderable = SHComponentManager::GetComponent_s(comp.GetEID()); + auto renderable = SHComponentManager::GetComponent_s(comp.GetEID()); auto texture = SHResourceManager::Get(comp.GetDefaultTexture()); auto material = renderable->GetModifiableMaterial(); - material->SetProperty("texture", comp.GetDefaultTexture());*/ + if(!comp.isHovered && !comp.isClicked) + if (SHAssetManager::GetType(comp.GetDefaultTexture()) == AssetType::TEXTURE) + { + material->SetProperty("data.textureIndex", comp.GetDefaultTexture()); + //SHLOG_INFO("SETTING DEFAULT TEXTURE") + } + + if (comp.isHovered) + { + if (SHAssetManager::GetType(comp.GetHoveredTexture()) == AssetType::TEXTURE) + { + material->SetProperty("data.textureIndex", comp.GetHoveredTexture()); + //SHLOG_INFO("SETTING HOVERED TEXTURE") + } + } + else + { + if (SHAssetManager::GetType(comp.GetClickedTexture()) == AssetType::TEXTURE) + { + material->SetProperty("data.textureIndex", comp.GetClickedTexture()); + SHLOG_INFO("SETTING CLICKED TEXTURE") + } + } + + + } } @@ -262,9 +288,9 @@ namespace SHADE windowSize = SHEditorWindowManager::GetEditorWindow()->beginContentRegionAvailable; mousePos = SHEditorWindowManager::GetEditorWindow()->viewportMousePos; //mousePos.y = windowSize.y - mousePos.y; - SHLOG_INFO("mouse pos: {}, {}", mousePos.x, mousePos.y) + //SHLOG_INFO("mouse pos: {}, {}", mousePos.x, mousePos.y) mousePos /= windowSize; - SHLOG_INFO("mouse pos normalized: {}, {}", mousePos.x, mousePos.y) + //SHLOG_INFO("mouse pos normalized: {}, {}", mousePos.x, mousePos.y) @@ -296,25 +322,15 @@ namespace SHADE #ifdef SHEDITOR if (SHSystemManager::GetSystem()->editorState == SHEditor::State::PLAY) { - if (SHInputManager::GetKeyUp(SHInputManager::SH_KEYCODE::LMB)) + if (SHInputManager::GetKeyDown(SHInputManager::SH_KEYCODE::LMB)) { comp.isClicked = true; - comp.value = !comp.value; - SHButtonClickEvent clickEvent; - clickEvent.EID = comp.GetEID(); - clickEvent.value = comp.value; - SHEventManager::BroadcastEvent(clickEvent, SH_BUTTON_CLICK_EVENT); } } #else - if (SHInputManager::GetKeyUp(SHInputManager::SH_KEYCODE::LMB)) + if (SHInputManager::GetKeyDown(SHInputManager::SH_KEYCODE::LMB)) { comp.isClicked = true; - comp.value = !comp.value; - SHButtonClickEvent clickEvent; - clickEvent.EID = comp.GetEID(); - clickEvent.value = comp.value; - SHEventManager::BroadcastEvent(clickEvent, SH_BUTTON_CLICK_EVENT); } #endif } @@ -324,13 +340,39 @@ namespace SHADE } + if (comp.isClicked && SHInputManager::GetKeyUp(SHInputManager::SH_KEYCODE::LMB)) + { + comp.isClicked = false; + comp.value = !comp.value; + SHButtonClickEvent clickEvent; + clickEvent.EID = comp.GetEID(); + clickEvent.value = comp.value; + SHEventManager::BroadcastEvent(clickEvent, SH_BUTTON_CLICK_EVENT); + } + if (SHComponentManager::HasComponent(comp.GetEID())) { - /*auto renderable = SHComponentManager::GetComponent_s(comp.GetEID()); + auto renderable = SHComponentManager::GetComponent_s(comp.GetEID()); auto texture = SHResourceManager::Get(comp.GetDefaultTexture()); auto material = renderable->GetModifiableMaterial(); - material->SetProperty("texture", comp.GetDefaultTexture());*/ + if (comp.GetValue() == false) + { + if (SHAssetManager::GetType(comp.GetDefaultTexture()) == AssetType::TEXTURE) + { + material->SetProperty("data.textureIndex", comp.GetDefaultTexture()); + //SHLOG_INFO("SETTING DEFAULT TEXTURE") + } + } + else + { + if (SHAssetManager::GetType(comp.GetToggledTexture()) == AssetType::TEXTURE) + { + material->SetProperty("data.textureIndex", comp.GetToggledTexture()); + //SHLOG_INFO("SETTING DEFAULT TEXTURE") + } + } + } } From b60304457977b9e874b3ff44606a25f5f0916966 Mon Sep 17 00:00:00 2001 From: Kah Wei Date: Mon, 16 Jan 2023 14:39:35 +0800 Subject: [PATCH 40/45] Fixed validation errors caused by debug draw and fixed SHDebugDraw::WireCapsule not being static --- .../Graphics/MiddleEnd/Interface/SHDebugDrawSystem.cpp | 9 ++++++++- SHADE_Engine/src/Tools/SHDebugDraw.h | 4 ++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHDebugDrawSystem.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHDebugDrawSystem.cpp index ae8c62b2..5a694516 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHDebugDrawSystem.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHDebugDrawSystem.cpp @@ -104,6 +104,10 @@ namespace SHADE auto subPass = renderGraph->GetNode("Debug Draw")->GetSubpass("Debug Draw"); subPass->AddExteriorDrawCalls([this](Handle cmdBuffer, Handle renderer, uint32_t frameIndex) { + // Set line width first + cmdBuffer->SetLineWidth(LineWidth); + + // Draw const uint32_t FRAME_IDX = gfxSystem->GetCurrentFrameIndex(); cmdBuffer->BeginLabeledSegment("SHDebugDraw (No Depth Test)"); { @@ -128,6 +132,10 @@ namespace SHADE auto subPassWithDepth = renderGraph->GetNode("Debug Draw with Depth")->GetSubpass("Debug Draw with Depth"); subPassWithDepth->AddExteriorDrawCalls([this](Handle cmdBuffer, Handle renderer, uint32_t frameIndex) { + // Set line width first + cmdBuffer->SetLineWidth(LineWidth); + + // Draw const uint32_t FRAME_IDX = gfxSystem->GetCurrentFrameIndex(); cmdBuffer->BeginLabeledSegment("SHDebugDraw (Depth Tested)"); { @@ -506,7 +514,6 @@ namespace SHADE if (batch.NumPoints[frameIndex] > 0) { cmdBuffer->BindPipeline(batch.Pipeline); - cmdBuffer->SetLineWidth(LineWidth); cmdBuffer->BindVertexBuffer(0, batch.VertexBuffers[frameIndex], 0); cmdBuffer->DrawArrays(batch.NumPoints[frameIndex], 1, 0, 0); } diff --git a/SHADE_Engine/src/Tools/SHDebugDraw.h b/SHADE_Engine/src/Tools/SHDebugDraw.h index 3d7bee2f..c775a514 100644 --- a/SHADE_Engine/src/Tools/SHDebugDraw.h +++ b/SHADE_Engine/src/Tools/SHDebugDraw.h @@ -205,7 +205,7 @@ namespace SHADE /// /// Colour to draw with. /// Whether or not drawn object will be occluded. - void WireCapsule(const SHVec3& position, const SHQuaternion& rotation, float height, float radius, const SHColour& color = SHColour::WHITE, bool depthTested = false); + static void WireCapsule(const SHVec3& position, const SHQuaternion& rotation, float height, float radius, const SHColour& color = SHColour::WHITE, bool depthTested = false); /*---------------------------------------------------------------------------------*/ /* Persistent Draw Function Class "Folder" */ @@ -388,7 +388,7 @@ namespace SHADE /// /// Colour to draw with. /// Whether or not drawn object will be occluded. - void WireCapsule(const SHVec3& position, const SHQuaternion& rotation, float height, float radius, const SHColour& color = SHColour::WHITE, bool depthTested = false); + static void WireCapsule(const SHVec3& position, const SHQuaternion& rotation, float height, float radius, const SHColour& color = SHColour::WHITE, bool depthTested = false); /// /// Clears any persistent drawn debug primitives. /// From 1e351366afccf40c5723f087ad2b4fd4fd7be9ec Mon Sep 17 00:00:00 2001 From: maverickdgg Date: Mon, 16 Jan 2023 14:44:20 +0800 Subject: [PATCH 41/45] fix clicked texture to take priority over hovered texture --- SHADE_Engine/src/UI/SHUISystem.cpp | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/SHADE_Engine/src/UI/SHUISystem.cpp b/SHADE_Engine/src/UI/SHUISystem.cpp index 84f6a21c..11808038 100644 --- a/SHADE_Engine/src/UI/SHUISystem.cpp +++ b/SHADE_Engine/src/UI/SHUISystem.cpp @@ -232,7 +232,7 @@ namespace SHADE if (SHComponentManager::HasComponent(comp.GetEID())) { auto renderable = SHComponentManager::GetComponent_s(comp.GetEID()); - auto texture = SHResourceManager::Get(comp.GetDefaultTexture()); + //auto texture = SHResourceManager::Get(comp.GetDefaultTexture()); auto material = renderable->GetModifiableMaterial(); if(!comp.isHovered && !comp.isClicked) @@ -240,9 +240,16 @@ namespace SHADE { material->SetProperty("data.textureIndex", comp.GetDefaultTexture()); //SHLOG_INFO("SETTING DEFAULT TEXTURE") + } + else if (comp.isClicked) + { + if (SHAssetManager::GetType(comp.GetClickedTexture()) == AssetType::TEXTURE) + { + material->SetProperty("data.textureIndex", comp.GetClickedTexture()); + //SHLOG_INFO("SETTING CLICKED TEXTURE") + } } - - if (comp.isHovered) + else { if (SHAssetManager::GetType(comp.GetHoveredTexture()) == AssetType::TEXTURE) { @@ -250,14 +257,6 @@ namespace SHADE //SHLOG_INFO("SETTING HOVERED TEXTURE") } } - else - { - if (SHAssetManager::GetType(comp.GetClickedTexture()) == AssetType::TEXTURE) - { - material->SetProperty("data.textureIndex", comp.GetClickedTexture()); - SHLOG_INFO("SETTING CLICKED TEXTURE") - } - } @@ -353,7 +352,7 @@ namespace SHADE if (SHComponentManager::HasComponent(comp.GetEID())) { auto renderable = SHComponentManager::GetComponent_s(comp.GetEID()); - auto texture = SHResourceManager::Get(comp.GetDefaultTexture()); + //auto texture = SHResourceManager::Get(comp.GetDefaultTexture()); auto material = renderable->GetModifiableMaterial(); if (comp.GetValue() == false) From cdb5102630f84e10757bb2b01860cd880b067fd8 Mon Sep 17 00:00:00 2001 From: maverickdgg Date: Mon, 16 Jan 2023 14:51:06 +0800 Subject: [PATCH 42/45] Added a 0 check for button textures. --- SHADE_Engine/src/UI/SHUISystem.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/SHADE_Engine/src/UI/SHUISystem.cpp b/SHADE_Engine/src/UI/SHUISystem.cpp index 11808038..c75af66f 100644 --- a/SHADE_Engine/src/UI/SHUISystem.cpp +++ b/SHADE_Engine/src/UI/SHUISystem.cpp @@ -236,14 +236,14 @@ namespace SHADE auto material = renderable->GetModifiableMaterial(); if(!comp.isHovered && !comp.isClicked) - if (SHAssetManager::GetType(comp.GetDefaultTexture()) == AssetType::TEXTURE) + if (comp.GetDefaultTexture() != 0 && SHAssetManager::GetType(comp.GetDefaultTexture()) == AssetType::TEXTURE) { material->SetProperty("data.textureIndex", comp.GetDefaultTexture()); //SHLOG_INFO("SETTING DEFAULT TEXTURE") } else if (comp.isClicked) { - if (SHAssetManager::GetType(comp.GetClickedTexture()) == AssetType::TEXTURE) + if (comp.GetClickedTexture() != 0 && SHAssetManager::GetType(comp.GetClickedTexture()) == AssetType::TEXTURE) { material->SetProperty("data.textureIndex", comp.GetClickedTexture()); //SHLOG_INFO("SETTING CLICKED TEXTURE") @@ -251,7 +251,7 @@ namespace SHADE } else { - if (SHAssetManager::GetType(comp.GetHoveredTexture()) == AssetType::TEXTURE) + if (comp.GetHoveredTexture() != 0 && SHAssetManager::GetType(comp.GetHoveredTexture()) == AssetType::TEXTURE) { material->SetProperty("data.textureIndex", comp.GetHoveredTexture()); //SHLOG_INFO("SETTING HOVERED TEXTURE") @@ -357,7 +357,7 @@ namespace SHADE auto material = renderable->GetModifiableMaterial(); if (comp.GetValue() == false) { - if (SHAssetManager::GetType(comp.GetDefaultTexture()) == AssetType::TEXTURE) + if (comp.GetDefaultTexture()!= 0 && SHAssetManager::GetType(comp.GetDefaultTexture()) == AssetType::TEXTURE) { material->SetProperty("data.textureIndex", comp.GetDefaultTexture()); //SHLOG_INFO("SETTING DEFAULT TEXTURE") @@ -365,7 +365,7 @@ namespace SHADE } else { - if (SHAssetManager::GetType(comp.GetToggledTexture()) == AssetType::TEXTURE) + if (comp.GetToggledTexture() != 0 && SHAssetManager::GetType(comp.GetToggledTexture()) == AssetType::TEXTURE) { material->SetProperty("data.textureIndex", comp.GetToggledTexture()); //SHLOG_INFO("SETTING DEFAULT TEXTURE") From 1526176c58c22c24b7deade29420a03b95714d55 Mon Sep 17 00:00:00 2001 From: Brandon Mak Date: Mon, 16 Jan 2023 15:06:46 +0800 Subject: [PATCH 43/45] Shadows WIP --- Assets/Shaders/DeferredComposite_CS.glsl | 2 +- Assets/Shaders/DeferredComposite_CS.shshaderb | Bin 8333 -> 8317 bytes .../src/Graphics/Images/SHVkSampler.cpp | 1 + .../MiddleEnd/Interface/SHGraphicsSystem.cpp | 2 +- .../MiddleEnd/Lights/SHLightingSubSystem.cpp | 2 +- 5 files changed, 4 insertions(+), 3 deletions(-) diff --git a/Assets/Shaders/DeferredComposite_CS.glsl b/Assets/Shaders/DeferredComposite_CS.glsl index b31daf25..d28eaec0 100644 --- a/Assets/Shaders/DeferredComposite_CS.glsl +++ b/Assets/Shaders/DeferredComposite_CS.glsl @@ -60,7 +60,7 @@ float CalcShadowValue (sampler2D shadowMap, vec4 worldSpaceFragPos, mat4 lightPV if (fragPosLightPOV.z > sampledDepth && fragPosLightPOV.w > 0.0f) { - return 0.3f; + return 0.0f; } else return 1.0f; diff --git a/Assets/Shaders/DeferredComposite_CS.shshaderb b/Assets/Shaders/DeferredComposite_CS.shshaderb index 31ea035c0a64e3e947bae4ceb483ce0661300999..ceca4e13568ca092b20096b7eec9b7c432767466 100644 GIT binary patch literal 8317 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 X46+VodvI={i(); lightingSubSystem->Init(device, descPool, &resourceManager, samplerCache.GetSampler (device, SHVkSamplerParams { - // nothing for now + .addressMode = vk::SamplerAddressMode::eClampToBorder, }) ); diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightingSubSystem.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightingSubSystem.cpp index 2e3b21d9..9acdfed0 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightingSubSystem.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightingSubSystem.cpp @@ -518,7 +518,7 @@ namespace SHADE if (auto renderer = light.GetRenderer()) { //SHMatrix orthoMatrix = SHMatrix::OrthographicRH() - renderer->UpdateDataManual(frameIndex, GetViewMatrix(&light), SHMatrix::OrthographicLH(30.0f, 30.0f, 1.0f, 50.0f)); + renderer->UpdateDataManual(frameIndex, GetViewMatrix(&light), SHMatrix::OrthographicLH(10.0f, 10.0f, 1.0f, 50.0f)); } auto enumValue = SHUtilities::ConvertEnum(light.GetLightData().type); From fe39be0d61acbbe80d9426ff728a67e9e9d2e1aa Mon Sep 17 00:00:00 2001 From: maverickdgg Date: Mon, 16 Jan 2023 15:17:06 +0800 Subject: [PATCH 44/45] Added asset browser tool tip that shows asset id --- .../Editor/EditorWindow/AssetBrowser/SHAssetBrowser.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/SHADE_Engine/src/Editor/EditorWindow/AssetBrowser/SHAssetBrowser.cpp b/SHADE_Engine/src/Editor/EditorWindow/AssetBrowser/SHAssetBrowser.cpp index bd39b38e..a1bb29ca 100644 --- a/SHADE_Engine/src/Editor/EditorWindow/AssetBrowser/SHAssetBrowser.cpp +++ b/SHADE_Engine/src/Editor/EditorWindow/AssetBrowser/SHAssetBrowser.cpp @@ -262,6 +262,13 @@ namespace SHADE } } + if (ImGui::IsItemHovered()) + { + ImGui::BeginTooltip(); + ImGui::Text("AssetID: %zu | Path: %s", asset->id, asset->path.c_str()); + ImGui::EndTooltip(); + } + //TODO: Combine Draw asset and Draw Folder recursive drawing const ImColor treeLineColor = ImGui::GetColorU32(ImGuiCol_CheckMark); const float horizontalOffset = 0.0f; From e115d4b96588a8af86021d2bb0dcd0553488c2e5 Mon Sep 17 00:00:00 2001 From: Brandon Mak Date: Mon, 16 Jan 2023 15:33:20 +0800 Subject: [PATCH 45/45] Reverted light properties back to main --- Assets/Scenes/MainGame.shade | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/Assets/Scenes/MainGame.shade b/Assets/Scenes/MainGame.shade index 69bb9e7d..49602e78 100644 --- a/Assets/Scenes/MainGame.shade +++ b/Assets/Scenes/MainGame.shade @@ -8440,15 +8440,10 @@ IsActive: true NumberOfChildren: 0 Components: - Transform Component: - Translate: {x: 2.05652523, y: 1.65113854, z: -6.62914371} - Rotate: {x: -0, y: 0, z: -0} - Scale: {x: 1, y: 1, z: 1} - IsActive: true Light Component: - Position: {x: 0, y: 1.5, z: -6.71799994} + Position: {x: 0, y: 0, z: 0} Type: Directional - Direction: {x: 0, y: 0, z: -1.11899996} + Direction: {x: 15, y: 90, z: 15} Color: {x: 1, y: 1, z: 1, w: 1} Layer: 4294967295 Strength: 1