diff --git a/SHADE_Application/src/Application/SBApplication.cpp b/SHADE_Application/src/Application/SBApplication.cpp index c6da6f1f..861a92d6 100644 --- a/SHADE_Application/src/Application/SBApplication.cpp +++ b/SHADE_Application/src/Application/SBApplication.cpp @@ -81,9 +81,9 @@ namespace Sandbox SHADE::SHSystemManager::RegisterRoutine(); SHADE::SHSystemManager::RegisterRoutine(); - SHADE::SHSystemManager::RegisterRoutine(); - SHADE::SHSystemManager::RegisterRoutine(); - SHADE::SHSystemManager::RegisterRoutine(); + //SHADE::SHSystemManager::RegisterRoutine(); + //SHADE::SHSystemManager::RegisterRoutine(); + //SHADE::SHSystemManager::RegisterRoutine(); SHADE::SHComponentManager::CreateComponentSparseSet(); SHADE::SHComponentManager::CreateComponentSparseSet(); diff --git a/SHADE_Application/src/Scenes/SBTestScene.cpp b/SHADE_Application/src/Scenes/SBTestScene.cpp index c3f95aec..f1d656ee 100644 --- a/SHADE_Application/src/Scenes/SBTestScene.cpp +++ b/SHADE_Application/src/Scenes/SBTestScene.cpp @@ -99,7 +99,7 @@ namespace Sandbox renderable.GetModifiableMaterial()->SetProperty("data.color", SHVec4(1.0f, 0.0f, 0.0f, 1.0f)); //Set initial positions - transform.SetWorldPosition(TEST_OBJ_START_POS + SHVec3{ x * TEST_OBJ_SPACING.x, y * TEST_OBJ_SPACING.y, SHMath::GenerateRandomNumber(-3.5f, -5.0f)}); + transform.SetWorldPosition(TEST_OBJ_START_POS + SHVec3{ x * TEST_OBJ_SPACING.x, y * TEST_OBJ_SPACING.y, SHMath::GenerateRandomNumber(-3.5f, -5.0f) }); //transform.SetWorldPosition({-1.0f, -1.0f, -1.0f}); transform.SetWorldRotation(SHMath::GenerateRandomNumber(), SHMath::GenerateRandomNumber(), SHMath::GenerateRandomNumber()); transform.SetWorldScale(TEST_OBJ_SCALE); @@ -135,12 +135,12 @@ namespace Sandbox floorRenderable.SetMaterial(customMat); floorRenderable.GetModifiableMaterial()->SetProperty("data.color", SHVec4(1.0f, 1.0f, 1.0f, 1.0f)); - floorTransform.SetWorldScale({7.5f, 0.5f, 7.5}); - floorTransform.SetWorldPosition({0.0f, -3.0f, -5.0f}); + floorTransform.SetWorldScale({ 7.5f, 0.5f, 7.5 }); + floorTransform.SetWorldPosition({ 0.0f, -3.0f, -5.0f }); floorRigidBody.SetType(SHRigidBodyComponent::Type::STATIC); - auto* floorBox = floorCollider.AddBoundingBox(); + auto* floorBox = floorCollider.AddBoundingBox(); floorBox->SetHalfExtents(floorTransform.GetWorldScale() * 0.5f); // Create blank entity with a script diff --git a/SHADE_Engine/src/Graphics/Buffers/SHVkBuffer.h b/SHADE_Engine/src/Graphics/Buffers/SHVkBuffer.h index 648a07e8..e931fec5 100644 --- a/SHADE_Engine/src/Graphics/Buffers/SHVkBuffer.h +++ b/SHADE_Engine/src/Graphics/Buffers/SHVkBuffer.h @@ -105,6 +105,17 @@ namespace SHADE vk::Buffer GetVkBuffer (void) const noexcept; vk::BufferUsageFlags GetUsageBits(void) const noexcept; + template + T GetDataFromMappedPointer(uint32_t index) const noexcept + { + if (mappedPtr && index < sizeStored / sizeof (T)) + { + return (static_cast(mappedPtr))[index]; + } + else + return {}; + }; + }; } diff --git a/SHADE_Engine/src/Graphics/Commands/SHVkCommandBuffer.cpp b/SHADE_Engine/src/Graphics/Commands/SHVkCommandBuffer.cpp index 9ebbd227..4501ba7b 100644 --- a/SHADE_Engine/src/Graphics/Commands/SHVkCommandBuffer.cpp +++ b/SHADE_Engine/src/Graphics/Commands/SHVkCommandBuffer.cpp @@ -461,6 +461,11 @@ namespace SHADE ); } + void SHVkCommandBuffer::CopyImageToBuffer(const vk::Image& src, const vk::Buffer& dst, const std::vector& copyInfo) + { + vkCommandBuffer.copyImageToBuffer (src, vk::ImageLayout::eTransferSrcOptimal, dst, copyInfo); + } + void SHVkCommandBuffer::PipelineBarrier( vk::PipelineStageFlags srcStage, vk::PipelineStageFlags dstStage, diff --git a/SHADE_Engine/src/Graphics/Commands/SHVkCommandBuffer.h b/SHADE_Engine/src/Graphics/Commands/SHVkCommandBuffer.h index c18527b3..9416a1aa 100644 --- a/SHADE_Engine/src/Graphics/Commands/SHVkCommandBuffer.h +++ b/SHADE_Engine/src/Graphics/Commands/SHVkCommandBuffer.h @@ -120,7 +120,8 @@ namespace SHADE void DrawMultiIndirect (Handle indirectDrawData, uint32_t drawCount); // Buffer Copy - void CopyBufferToImage (const vk::Buffer& src, const vk::Image& dst, const std::vector& copyInfo); + void CopyBufferToImage (const vk::Buffer& src, const vk::Image& dst, const std::vector& copyInfo); + void CopyImageToBuffer (const vk::Image& src, const vk::Buffer& dst, const std::vector& copyInfo); // memory barriers void PipelineBarrier ( diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Batching/SHBatch.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Batching/SHBatch.cpp index 181c1f22..2705b4d1 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Batching/SHBatch.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Batching/SHBatch.cpp @@ -110,6 +110,7 @@ namespace SHADE // Clear CPU buffers drawData.clear(); transformData.clear(); + eidData.clear(); matPropsData.reset(); matPropsDataSize = 0; @@ -119,6 +120,7 @@ namespace SHADE { drawDataBuffer[i].Free(); transformDataBuffer[i].Free(); + eidBuffer[i].Free(); matPropsBuffer[i].Free(); } } @@ -206,7 +208,31 @@ namespace SHADE transformDataBuffer[frameIndex]->WriteToMemory(transformData.data(), static_cast(transformData.size() * sizeof(SHMatrix)), 0, 0); } - void SHBatch::Build(Handle _device, Handle descPool, uint32_t frameIndex) + void SHBatch::UpdateEIDBuffer(uint32_t frameIndex) + { + if (frameIndex >= SHGraphicsConstants::NUM_FRAME_BUFFERS) + { + SHLOG_WARNING("[SHBatch] Attempted to update eid buffers with an invalid frame index."); + return; + } + + // Reset Transform Data + eidData.clear(); + + // Populate on the CPU + for (auto& subBatch : subBatches) + for (const SHRenderable* renderable : subBatch.Renderables) + { + eidData.emplace_back(renderable->GetEID()); + } + + // Transfer to GPU + if (eidBuffer[frameIndex]) + eidBuffer[frameIndex]->WriteToMemory(eidData.data(), static_cast(eidData.size() * sizeof(EntityID)), 0, 0); + + } + + void SHBatch::Build(Handle _device, Handle descPool, uint32_t frameIndex) { if (frameIndex >= SHGraphicsConstants::NUM_FRAME_BUFFERS) { @@ -237,6 +263,11 @@ namespace SHADE // - Transform data transformData.reserve(numTotalElements); transformData.clear(); + // - EID data + eidData.reserve(numTotalElements); + eidData.clear(); + + // - Material Properties Data const Handle SHADER_INFO = pipeline->GetPipelineLayout()->GetShaderBlockInterface ( @@ -277,7 +308,8 @@ namespace SHADE for (const SHRenderable* renderable : subBatch.Renderables) { // Transform - auto transform = SHComponentManager::GetComponent_s(renderable->GetEID()); + EntityID eid = renderable->GetEID(); + auto transform = SHComponentManager::GetComponent_s(eid); if (!transform) { SHLOG_WARNING("[SHBatch] Entity contianing a SHRenderable with no SHTransformComponent found!"); @@ -287,6 +319,8 @@ namespace SHADE { transformData.emplace_back(transform->GetTRS()); } + + eidData.emplace_back(eid); // Material Properties if (!EMPTY_MAT_PROPS) @@ -317,6 +351,12 @@ namespace SHADE device, transformDataBuffer[frameIndex], transformData.data(), TF_DATA_BYTES, BuffUsage::eVertexBuffer ); + const uint32_t EID_DATA_BYTES = static_cast(eidData.size() * sizeof(EntityID)); + SHVkUtil::EnsureBufferAndCopyHostVisibleData + ( + device, eidBuffer[frameIndex], eidData.data(), EID_DATA_BYTES, + BuffUsage::eVertexBuffer + ); // - Material Properties Buffer rebuildMaterialBuffers(frameIndex, descPool); @@ -339,6 +379,7 @@ namespace SHADE static std::array dynamicOffset { 0 }; cmdBuffer->BindPipeline(pipeline); cmdBuffer->BindVertexBuffer(SHGraphicsConstants::VertexBufferBindings::TRANSFORM, transformDataBuffer[frameIndex], 0); + cmdBuffer->BindVertexBuffer(SHGraphicsConstants::VertexBufferBindings::EID, eidBuffer[frameIndex], 0); if (matPropsDescSet[frameIndex]) { cmdBuffer->BindDescriptorSet diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Batching/SHBatch.h b/SHADE_Engine/src/Graphics/MiddleEnd/Batching/SHBatch.h index abe691ca..37c57396 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Batching/SHBatch.h +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Batching/SHBatch.h @@ -22,6 +22,7 @@ of DigiPen Institute of Technology is prohibited. #include "Graphics/MiddleEnd/Interface/SHMaterial.h" #include "Math/SHMatrix.h" #include "Graphics/MiddleEnd/Interface/SHGraphicsConstants.h" +#include "ECS_Base/SHECSMacros.h" namespace SHADE { @@ -78,6 +79,7 @@ namespace SHADE void Clear(); void UpdateMaterialBuffer(uint32_t frameIndex, Handle descPool); void UpdateTransformBuffer(uint32_t frameIndex); + void UpdateEIDBuffer(uint32_t frameIndex); void Build(Handle device, Handle descPool, uint32_t frameIndex) ; void Draw(Handle cmdBuffer, uint32_t frameIndex); @@ -109,14 +111,16 @@ namespace SHADE // CPU Buffers std::vector drawData; std::vector transformData; + std::vector eidData; std::unique_ptr matPropsData; Byte matPropsDataSize = 0; Byte singleMatPropAlignedSize = 0; - Byte singleMatPropSize = 0; + Byte singleMatPropSize = 0; bool isCPUBuffersDirty = true; // GPU Buffers TripleBuffer drawDataBuffer; TripleBuffer transformDataBuffer; + TripleBuffer eidBuffer; TripleBuffer matPropsBuffer; TripleDescSet matPropsDescSet; diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Batching/SHSuperBatch.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Batching/SHSuperBatch.cpp index 0d75dca8..add51196 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Batching/SHSuperBatch.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Batching/SHSuperBatch.cpp @@ -83,8 +83,9 @@ namespace SHADE { for (auto& batch : batches) { - batch.UpdateMaterialBuffer(frameIndex, descPool); + batch.UpdateMaterialBuffer(frameIndex, descPool); batch.UpdateTransformBuffer(frameIndex); + batch.UpdateEIDBuffer(frameIndex); } } diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/GlobalData/SHGraphicsGlobalData.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/GlobalData/SHGraphicsGlobalData.cpp index 6a7b23f2..d8b1bad1 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/GlobalData/SHGraphicsGlobalData.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/GlobalData/SHGraphicsGlobalData.cpp @@ -91,9 +91,10 @@ namespace SHADE { defaultVertexInputState.AddBinding(false, false, { SHVertexAttribute(SHAttribFormat::FLOAT_3D) }); // positions at binding 0 defaultVertexInputState.AddBinding(false, false, { SHVertexAttribute(SHAttribFormat::FLOAT_2D) }); // UVs at binding 1 - defaultVertexInputState.AddBinding(false, false, {SHVertexAttribute(SHAttribFormat::FLOAT_3D)}); // Normals at binding 2 - 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(false, false, { SHVertexAttribute(SHAttribFormat::FLOAT_3D) }); // Normals at binding 2 + 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_1D) }); // EID at binding 8 } void SHGraphicsGlobalData::Init(Handle logicalDevice) noexcept diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsConstants.h b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsConstants.h index 0818ebab..ac2f1f8c 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsConstants.h +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsConstants.h @@ -144,6 +144,14 @@ namespace SHADE */ /***************************************************************************/ static constexpr uint32_t TRANSFORM = 4; + /***************************************************************************/ + /*! + \brief + Vertex buffer bindings for the eid buffer. + */ + /***************************************************************************/ + static constexpr uint32_t EID = 5; + }; /*******************************************************************************/ diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp index 6957aa93..09f1c93e 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp @@ -32,6 +32,7 @@ of DigiPen Institute of Technology is prohibited. #include "Graphics/Buffers/SHVkBuffer.h" #include "Graphics/Images/SHVkSampler.h" #include "Assets/Asset Types/SHTextureAsset.h" +#include "Graphics/MiddleEnd/Interface/SHMousePickSystem.h" namespace SHADE { @@ -143,26 +144,22 @@ namespace SHADE // Initialize world render graph worldRenderGraph->Init(device, swapchain); + worldRenderGraph->AddResource("Present", SH_ATT_DESC_TYPE::COLOR_PRESENT, windowDims.first, windowDims.second); worldRenderGraph->AddResource("Depth Buffer", SH_ATT_DESC_TYPE::DEPTH_STENCIL, windowDims.first, windowDims.second, vk::Format::eD32SfloatS8Uint); + worldRenderGraph->AddResource("Entity ID", SH_ATT_DESC_TYPE::COLOR, windowDims.first, windowDims.second, vk::Format::eR32Uint, 1, vk::ImageUsageFlagBits::eTransferSrc); + //worldRenderGraph->AddResource("Position", SH_ATT_DESC_TYPE::COLOR, windowDims.first, windowDims.second, vk::Format::eR16G16B16A16Sfloat); //worldRenderGraph->AddResource("Normals", SH_ATT_DESC_TYPE::COLOR, windowDims.first, windowDims.second, vk::Format::eR16G16B16A16Sfloat); //worldRenderGraph->AddResource("Composite", SH_ATT_DESC_TYPE::COLOR, windowDims.first, windowDims.second, vk::Format::eR16G16B16A16Sfloat); //worldRenderGraph->AddResource("Scene", SH_ATT_DESC_TYPE::COLOR, windowDims.first, windowDims.second, vk::Format::eB8G8R8A8Unorm); - worldRenderGraph->AddResource("Present", SH_ATT_DESC_TYPE::COLOR_PRESENT, windowDims.first, windowDims.second); - auto node = worldRenderGraph->AddNode("G-Buffer", { /*"Composite", "Position", */"Depth Buffer", "Present" }, {}); // no predecessors + auto node = worldRenderGraph->AddNode("G-Buffer", { "Entity ID", "Depth Buffer", "Present"}, {}); // no predecessors //First subpass to write to G-Buffer auto gBufferWriteSubpass = node->AddSubpass("G-Buffer Write"); - //gBufferWriteSubpass->AddColorOutput("Scene"); gBufferWriteSubpass->AddColorOutput("Present"); + gBufferWriteSubpass->AddColorOutput("Entity ID"); gBufferWriteSubpass->AddDepthOutput ("Depth Buffer", SH_ATT_DESC_TYPE::DEPTH_STENCIL); - //writeSubpass->AddColorOutput("Normals"); - // //Second subpass to read from G-Buffer - //auto compositeSubpass = node->AddSubpass("G-Buffer Composite"); - //compositeSubpass->AddColorOutput("Present"); // TODO: This should be "Composite" and then composite will write to swapchain image "Present" - //compositeSubpass->AddInput("Normals"); - //compositeSubpass->AddInput("Position"); // TODO: Use macro to add this node when SH_EDITOR is enabled auto imguiNode = worldRenderGraph->AddNode("ImGui Node", { "Present" }, {"G-Buffer"}); @@ -201,6 +198,15 @@ namespace SHADE cubeFS->Reflect(); defaultMaterial = AddMaterial(cubeVS, cubeFS, gBufferWriteSubpass); + + mousePickSystem = resourceManager.Create(); + + std::vector> cmdPools; + cmdPools.reserve(swapchain->GetNumImages()); + for (uint32_t i = 0; i < swapchain->GetNumImages(); ++i) + cmdPools.push_back(renderContext.GetFrameData(i).cmdPoolHdls[0]); + + mousePickSystem->Init(device, cmdPools, worldRenderGraph->GetRenderGraphResource("Entity ID")); } /***************************************************************************/ @@ -400,10 +406,10 @@ namespace SHADE } - const uint32_t CURR_FRAME_IDX = renderContext.GetCurrentFrame(); auto& currFrameData = renderContext.GetCurrentFrameData(); + mousePickSystem->Run(graphicsQueue, CURR_FRAME_IDX); // #BackEndTest: queues an image for presentation if (auto result = graphicsQueue->Present(swapchain, { currFrameData.semRenderFinishHdl }, CURR_FRAME_IDX); result != vk::Result::eSuccess) diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.h b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.h index c89e6ebc..3160cd57 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.h +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.h @@ -52,6 +52,7 @@ namespace SHADE class SHVkShaderModule; class SHMaterial; class SHMaterialInstance; + class SHMousePickSystem; /*---------------------------------------------------------------------------------*/ /* Type Definitions */ @@ -268,6 +269,7 @@ namespace SHADE Handle GetQueue() const { return graphicsQueue; } Handle GetDescriptorPool() const { return descPool; } Handle GetDefaultViewport() const {return defaultViewport;} + Handle GetMousePickSystem(void) const noexcept {return mousePickSystem;}; //SHRenderGraph const& GetRenderGraph(void) const noexcept; //Handle GetRenderPass() const { return renderPass; } @@ -294,7 +296,7 @@ namespace SHADE SHWindow* window = nullptr; // Middle End Resources - ResourceManager resourceManager; + ResourceManager resourceManager; SHMeshLibrary meshLibrary; SHTextureLibrary texLibrary; SHSamplerCache samplerCache; @@ -322,5 +324,8 @@ namespace SHADE Handle defaultMaterial; Handle worldRenderGraph; + + // Sub systems + Handle mousePickSystem; }; } \ No newline at end of file diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHMousePickSystem.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHMousePickSystem.cpp new file mode 100644 index 00000000..ee8665d5 --- /dev/null +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHMousePickSystem.cpp @@ -0,0 +1,71 @@ +#include "SHpch.h" +#include "SHMousePickSystem.h" +#include "Input/SHInputManager.h" +#include "Graphics/Commands/SHVkCommandPool.h" +#include "Graphics/Devices/SHVkLogicalDevice.h" +#include "Graphics/Synchronization/SHVkFence.h" +#include "Graphics/Buffers/SHVkBuffer.h" +#include "Graphics/SHVkUtil.h" + +namespace SHADE +{ + void SHMousePickSystem::Init(Handle logicalDevice, std::span> cmdPools, Handle eidAttachment) noexcept + { + pickedEID = 0; + + // Create command buffers + for (auto& pool : cmdPools) + { + commandBuffers.push_back(pool->RequestCommandBuffer (SH_CMD_BUFFER_TYPE::PRIMARY)); + } + + // assign the attachment + entityIDAttachment = eidAttachment; + + // Create the fence + afterCopyFence = logicalDevice->CreateFence(); + + uint32_t bufferSize = entityIDAttachment->GetWidth() * eidAttachment->GetHeight() * SHVkUtil::GetBytesPerPixelFromFormat(entityIDAttachment->GetResourceFormat()); + + // Create the buffer + imageDataDstBuffer = logicalDevice->CreateBuffer(bufferSize, nullptr, bufferSize, vk::BufferUsageFlagBits::eTransferDst, VMA_MEMORY_USAGE_AUTO, VMA_ALLOCATION_CREATE_MAPPED_BIT | VMA_ALLOCATION_CREATE_HOST_ACCESS_SEQUENTIAL_WRITE_BIT); + } + + void SHMousePickSystem::Run(Handle queue, uint32_t frameIndex) noexcept + { + // if input detected + if (SHInputManager::GetKey(SHInputManager::SH_KEYCODE::LEFT_CTRL) && SHInputManager::GetKeyUp(SHInputManager::SH_KEYCODE::LMB)) + { + afterCopyFence->Reset(); + + // begin command buffer for recording + commandBuffers[frameIndex]->BeginRecording(); + + // transition the image for optimized copying + entityIDAttachment->TransitionImage (vk::ImageLayout::eColorAttachmentOptimal, vk::ImageLayout::eTransferSrcOptimal, commandBuffers[frameIndex], vk::PipelineStageFlagBits::eColorAttachmentOutput, vk::PipelineStageFlagBits::eTransfer, 0); + + // copy the image here. Last argument is 0 because the attachment isn't a swapchain image. + entityIDAttachment->CopyToBuffer(imageDataDstBuffer, commandBuffers[frameIndex], 0); + + // end command buffer for recording + commandBuffers[frameIndex]->EndRecording(); + + // submit the command buffer to copy image to buffer + queue->SubmitCommandBuffer({ commandBuffers[frameIndex] }, {}, {}, vk::PipelineStageFlagBits::eColorAttachmentOutput, afterCopyFence); + + // wait for the copy to be done + afterCopyFence->Wait(true, std::numeric_limits::max()); + + int mouseX = 0, mouseY = 0; + SHInputManager::GetMouseWindowPosition(&mouseX, &mouseY); + + pickedEID = imageDataDstBuffer->GetDataFromMappedPointer(mouseY * entityIDAttachment->GetWidth() + mouseX); + } + } + + EntityID SHMousePickSystem::GetPickedEntity(void) const noexcept + { + return pickedEID; + } + +} diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHMousePickSystem.h b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHMousePickSystem.h new file mode 100644 index 00000000..080a192c --- /dev/null +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHMousePickSystem.h @@ -0,0 +1,47 @@ +#pragma once + +#include "Graphics/RenderGraph/SHRenderGraphResource.h" +#include "ECS_Base/SHECSMacros.h" +#include "Math/Vector/SHVec2.h" +#include + +namespace SHADE +{ + class SHVkLogicalDevice; + class SHVkCommandPool; + class SHVkCommandBuffer; + class SHVkFence; + class SHVkQueue; + class SHVkBuffer; + + class SHMousePickSystem + { + private: + //! Handle to the render graph resource that will contain the entity IDs + Handle entityIDAttachment; + + //! Command buffers meant for copying image to buffer + std::vector> commandBuffers; + + //! After the attachment has copied its data to a buffer, we want to signal this fence + Handle afterCopyFence; + + //! buffer to contain the attachment data after copying + Handle imageDataDstBuffer; + + //! eid picked from screen + EntityID pickedEID; + public: + /*-----------------------------------------------------------------------*/ + /* PUBLIC MEMBER FUNCTIONS */ + /*-----------------------------------------------------------------------*/ + void Init(Handle logicalDevice, std::span> cmdPools, Handle eidAttachment) noexcept; + void Run (Handle queue, uint32_t frameIndex) noexcept; + + /*-----------------------------------------------------------------------*/ + /* SETTERS AND GETTERS */ + /*-----------------------------------------------------------------------*/ + EntityID GetPickedEntity (void) const noexcept; + + }; +} \ No newline at end of file diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Pipeline/SHPipelineLibrary.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Pipeline/SHPipelineLibrary.cpp index 10b42a9e..682b549c 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Pipeline/SHPipelineLibrary.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Pipeline/SHPipelineLibrary.cpp @@ -2,6 +2,8 @@ #include "SHPipelineLibrary.h" #include "Graphics/Devices/SHVkLogicalDevice.h" #include "Graphics/MiddleEnd/GlobalData/SHGraphicsGlobalData.h" +#include "Graphics/RenderGraph/SHSubpass.h" +#include "Graphics/SHVkUtil.h" namespace SHADE { @@ -20,6 +22,31 @@ namespace SHADE // Create the pipeline and configure the default vertex input state auto newPipeline = logicalDevice->CreateGraphicsPipeline(pipelineLayout, nullptr, renderpass, subpass); newPipeline->GetPipelineState().SetVertexInputState(SHGraphicsGlobalData::GetDefaultViState()); + + SHColorBlendState colorBlendState{}; + colorBlendState.logic_op_enable = VK_FALSE; + colorBlendState.logic_op = vk::LogicOp::eCopy; + + auto const& subpassColorReferences = subpass->GetColorAttachmentReferences(); + colorBlendState.attachments.reserve(subpassColorReferences.size()); + + for (auto& att : subpassColorReferences) + { + colorBlendState.attachments.push_back(vk::PipelineColorBlendAttachmentState + { + .blendEnable = SHVkUtil::IsBlendCompatible (subpass->GetFormatFromAttachmentReference(att.attachment)) ? true : false, + .srcColorBlendFactor = vk::BlendFactor::eSrcAlpha, + .dstColorBlendFactor = vk::BlendFactor::eOneMinusSrcAlpha, + .colorBlendOp = vk::BlendOp::eAdd, + .srcAlphaBlendFactor = vk::BlendFactor::eOne, + .dstAlphaBlendFactor = vk::BlendFactor::eZero, + .alphaBlendOp = vk::BlendOp::eAdd, + .colorWriteMask = vk::ColorComponentFlagBits::eR | vk::ColorComponentFlagBits::eG | vk::ColorComponentFlagBits::eB | vk::ColorComponentFlagBits::eA, + } + ); + } + + newPipeline->GetPipelineState().SetColorBlenState(colorBlendState); // Actually construct the pipeline newPipeline->ConstructPipeline(); diff --git a/SHADE_Engine/src/Graphics/Pipeline/SHPipelineState.h b/SHADE_Engine/src/Graphics/Pipeline/SHPipelineState.h index 2769d6cc..4c8d679a 100644 --- a/SHADE_Engine/src/Graphics/Pipeline/SHPipelineState.h +++ b/SHADE_Engine/src/Graphics/Pipeline/SHPipelineState.h @@ -137,22 +137,9 @@ namespace SHADE { VkBool32 logic_op_enable{ VK_FALSE }; - vk::LogicOp logic_op{ VK_LOGIC_OP_COPY }; + vk::LogicOp logic_op{ vk::LogicOp::eCopy }; - std::vector attachments = - { - vk::PipelineColorBlendAttachmentState - { - .blendEnable = true, - .srcColorBlendFactor = vk::BlendFactor::eSrcAlpha, - .dstColorBlendFactor = vk::BlendFactor::eOneMinusSrcAlpha, - .colorBlendOp = vk::BlendOp::eAdd, - .srcAlphaBlendFactor = vk::BlendFactor::eOne, - .dstAlphaBlendFactor = vk::BlendFactor::eZero, - .alphaBlendOp = vk::BlendOp::eAdd, - .colorWriteMask = vk::ColorComponentFlagBits::eR | vk::ColorComponentFlagBits::eG | vk::ColorComponentFlagBits::eB | vk::ColorComponentFlagBits::eA, - } - }; + std::vector attachments{}; }; // TODO: Specialization constants diff --git a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraph.cpp b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraph.cpp index cad6a78e..1861f6d2 100644 --- a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraph.cpp +++ b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraph.cpp @@ -40,7 +40,7 @@ namespace SHADE */ /***************************************************************************/ - void SHRenderGraph::AddResource(std::string resourceName, SH_ATT_DESC_TYPE type, uint32_t w /*= static_cast(-1)*/, uint32_t h /*= static_cast(-1)*/, vk::Format format/* = vk::Format::eB8G8R8A8Unorm*/, uint8_t levels /*= 1*/, vk::ImageCreateFlagBits createFlags /*= {}*/) + void SHRenderGraph::AddResource(std::string resourceName, SH_ATT_DESC_TYPE type, 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)) @@ -50,7 +50,7 @@ namespace SHADE format = swapchainHdl->GetSurfaceFormatKHR().format; } - graphResources.try_emplace(resourceName, resourceManager.Create(logicalDeviceHdl, swapchainHdl, resourceName, type, format, w, h, levels, createFlags)); + graphResources.try_emplace(resourceName, resourceManager.Create(logicalDeviceHdl, swapchainHdl, resourceName, type, format, w, h, levels, usageFlags, createFlags)); } /***************************************************************************/ @@ -498,4 +498,13 @@ namespace SHADE } + Handle SHRenderGraph::GetRenderGraphResource(std::string const& resourceName) const noexcept + { + if (graphResources.contains(resourceName)) + { + return graphResources.at(resourceName); + } + return {}; + } + } \ No newline at end of file diff --git a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraph.h b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraph.h index a3140a4f..cfc29bc2 100644 --- a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraph.h +++ b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraph.h @@ -75,7 +75,7 @@ namespace SHADE /* PUBLIC MEMBER FUNCTIONS */ /*-----------------------------------------------------------------------*/ void Init (Handle const& logicalDevice, Handle const& swapchain) noexcept; - void AddResource (std::string resourceName, SH_ATT_DESC_TYPE type, uint32_t w = static_cast(-1), uint32_t h = static_cast(-1), vk::Format format = vk::Format::eB8G8R8A8Unorm, uint8_t levels = 1, vk::ImageCreateFlagBits createFlags = {}); + void AddResource(std::string resourceName, SH_ATT_DESC_TYPE type, 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 = {}); Handle AddNode (std::string nodeName, std::initializer_list resourceNames, std::initializer_list predecessorNodes) noexcept; void Generate (void) noexcept; void Execute (uint32_t frameIndex, Handle cmdBuffer, Handle descPool) noexcept; @@ -85,7 +85,8 @@ namespace SHADE /*-----------------------------------------------------------------------*/ /* SETTERS AND GETTERS */ /*-----------------------------------------------------------------------*/ - Handle GetNode (std::string const& nodeName) const noexcept; + Handle GetNode (std::string const& nodeName) const noexcept; + Handle GetRenderGraphResource (std::string const& resourceName) const noexcept; }; } diff --git a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNode.cpp b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNode.cpp index 05232af3..ea09dd47 100644 --- a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNode.cpp +++ b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNode.cpp @@ -261,6 +261,7 @@ namespace SHADE return {}; } + Handle pipeline = pipelineLibrary.GetDrawPipline(vsFsPair); if (!pipeline) { @@ -301,4 +302,12 @@ namespace SHADE return subpasses[subpassIndexing.at(subpassName.data())]; } + Handle SHRenderGraphNode::GetResource(uint32_t resourceIndex) const noexcept + { + if (resourceIndex < attResources.size()) + return attResources[resourceIndex]; + else + 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 c713f402..28527a92 100644 --- a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNode.h +++ b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNode.h @@ -105,6 +105,7 @@ namespace SHADE /*-----------------------------------------------------------------------*/ Handle GetRenderpass(void) const noexcept; Handle GetSubpass(std::string_view subpassName) const noexcept; + Handle GetResource (uint32_t resourceIndex) const noexcept; friend class SHRenderGraph; }; diff --git a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphResource.cpp b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphResource.cpp index cc881867..bcd1dc9f 100644 --- a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphResource.cpp +++ b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphResource.cpp @@ -3,6 +3,8 @@ #include "Graphics/Devices/SHVkLogicalDevice.h" #include "Graphics/Swapchain/SHVkSwapchain.h" #include "Graphics/Images/SHVkImageView.h" +#include "Graphics/Buffers/SHVkBuffer.h" +#include "Graphics/SHVkUtil.h" namespace SHADE { @@ -43,7 +45,7 @@ namespace SHADE */ /***************************************************************************/ - SHRenderGraphResource::SHRenderGraphResource(Handle const& logicalDevice, Handle const& swapchain, std::string const& name, SH_ATT_DESC_TYPE type, vk::Format format, uint32_t w, uint32_t h, uint8_t levels, vk::ImageCreateFlagBits createFlags) noexcept + SHRenderGraphResource::SHRenderGraphResource(Handle const& logicalDevice, Handle const& swapchain, std::string const& name, SH_ATT_DESC_TYPE type, vk::Format format, uint32_t w, uint32_t h, uint8_t levels, vk::ImageUsageFlagBits usageFlags, vk::ImageCreateFlagBits createFlags) noexcept : logicalDevice {logicalDevice} , swapchain{ swapchain } , resourceType{ type } @@ -59,7 +61,7 @@ namespace SHADE if (resourceType != SH_ATT_DESC_TYPE::COLOR_PRESENT) { imageAspectFlags = vk::ImageAspectFlags{}; - usage = {}; + usage = usageFlags; // Check the resource type and set image usage flags and image aspect flags accordingly switch (resourceType) @@ -242,4 +244,59 @@ namespace SHADE } } + void SHRenderGraphResource::TransitionImage(vk::ImageLayout oldLayout, vk::ImageLayout newLayout, Handle commandBuffer, vk::PipelineStageFlagBits srcStage, vk::PipelineStageFlagBits dstStage, uint32_t frameIndex) noexcept + { + vk::ImageMemoryBarrier barrier; + barrier.oldLayout = oldLayout; + barrier.newLayout = newLayout; + barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; + barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; + barrier.image = images[frameIndex]->GetVkImage(), + barrier.subresourceRange.aspectMask = vk::ImageAspectFlagBits::eColor; // TODO: Need to change this to base it off image format. + barrier.subresourceRange.baseMipLevel = 0; + barrier.subresourceRange.levelCount = mipLevels; + barrier.subresourceRange.baseArrayLayer = 0; + barrier.subresourceRange.layerCount = 1; // always 1 since we wont have array of images for attachments + + commandBuffer->PipelineBarrier(srcStage, dstStage, {}, {}, {}, {barrier}); + } + + void SHRenderGraphResource::CopyToBuffer(Handle dstBuffer, Handle commandBuffer, uint32_t frameIndex) const noexcept + { + vk::ImageSubresourceLayers subResource + { + .aspectMask = SHVkUtil::IsDepthOnlyFormat(resourceFormat) ? vk::ImageAspectFlagBits::eDepth : vk::ImageAspectFlagBits::eColor, + .mipLevel = 0, + .baseArrayLayer = 0, + .layerCount = 1 + }; + + vk::BufferImageCopy region + { + .bufferOffset = 0, + .bufferRowLength = 0, + .bufferImageHeight = 0, + .imageSubresource = subResource, + .imageOffset = vk::Offset3D {0,0,0}, + .imageExtent = vk::Extent3D {width, height, 1} + }; + + commandBuffer->CopyImageToBuffer(images[frameIndex]->GetVkImage(), dstBuffer->GetVkBuffer(), {region}); + } + + vk::Format SHRenderGraphResource::GetResourceFormat(void) const noexcept + { + return resourceFormat; + } + + uint32_t SHRenderGraphResource::GetWidth(void) const noexcept + { + return width; + } + + uint32_t SHRenderGraphResource::GetHeight(void) const noexcept + { + return height; + } + } \ No newline at end of file diff --git a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphResource.h b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphResource.h index ebb699d8..66f0677b 100644 --- a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphResource.h +++ b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphResource.h @@ -13,6 +13,8 @@ namespace SHADE class SHVkImageView; class SHVkLogicalDevice; class SHVkSwapchain; + class SHVkCommandBuffer; + class SHVkBuffer; class SH_API SHRenderGraphResource { @@ -65,12 +67,24 @@ namespace SHADE /*-----------------------------------------------------------------------*/ /* CTORS AND DTORS */ /*-----------------------------------------------------------------------*/ - SHRenderGraphResource(Handle const& logicalDevice, Handle const& swapchain, std::string const& name, SH_ATT_DESC_TYPE type, vk::Format format, uint32_t w, uint32_t h, uint8_t levels, vk::ImageCreateFlagBits createFlags) noexcept; + SHRenderGraphResource(Handle const& logicalDevice, Handle const& swapchain, std::string const& name, SH_ATT_DESC_TYPE type, vk::Format format, uint32_t w, uint32_t h, uint8_t levels, vk::ImageUsageFlagBits usageFlags, vk::ImageCreateFlagBits createFlags) noexcept; SHRenderGraphResource(SHRenderGraphResource&& rhs) noexcept; SHRenderGraphResource& operator=(SHRenderGraphResource&& rhs) noexcept; ~SHRenderGraphResource(void) noexcept; + /*-----------------------------------------------------------------------*/ + /* PUBLIC MEMBER FUNCTIONS */ + /*-----------------------------------------------------------------------*/ void HandleResize (uint32_t newWidth, uint32_t newHeight) noexcept; + void TransitionImage(vk::ImageLayout oldLayout, vk::ImageLayout newLayout, Handle commandBuffer, vk::PipelineStageFlagBits srcStage, vk::PipelineStageFlagBits dstStage, uint32_t frameIndex) noexcept; + void CopyToBuffer (Handle dstBuffer, Handle commandBuffer, uint32_t frameIndex = 0) const noexcept; + + /*-----------------------------------------------------------------------*/ + /* SETTERS AND GETTERS */ + /*-----------------------------------------------------------------------*/ + vk::Format GetResourceFormat (void) const noexcept; + uint32_t GetWidth (void) const noexcept; + uint32_t GetHeight (void) const noexcept; friend class SHRenderGraphNode; friend class SHRenderGraph; diff --git a/SHADE_Engine/src/Graphics/RenderGraph/SHSubpass.cpp b/SHADE_Engine/src/Graphics/RenderGraph/SHSubpass.cpp index 007502dd..abd3a7be 100644 --- a/SHADE_Engine/src/Graphics/RenderGraph/SHSubpass.cpp +++ b/SHADE_Engine/src/Graphics/RenderGraph/SHSubpass.cpp @@ -2,6 +2,8 @@ #include "SHSubpass.h" #include "Graphics/MiddleEnd/Batching/SHSuperBatch.h" #include "Graphics/Devices/SHVkLogicalDevice.h" +#include "SHRenderGraphNode.h" +#include "SHRenderGraphResource.h" namespace SHADE { @@ -207,4 +209,15 @@ namespace SHADE { return superBatch; } + + std::vector const& SHSubpass::GetColorAttachmentReferences(void) const noexcept + { + return colorReferences; + } + + vk::Format SHSubpass::GetFormatFromAttachmentReference(uint32_t attachmentReference) const noexcept + { + return parentNode->GetResource(attachmentReference)->GetResourceFormat(); + } + } \ No newline at end of file diff --git a/SHADE_Engine/src/Graphics/RenderGraph/SHSubpass.h b/SHADE_Engine/src/Graphics/RenderGraph/SHSubpass.h index b8b8717f..aba282b9 100644 --- a/SHADE_Engine/src/Graphics/RenderGraph/SHSubpass.h +++ b/SHADE_Engine/src/Graphics/RenderGraph/SHSubpass.h @@ -86,7 +86,8 @@ namespace SHADE 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; friend class SHRenderGraphNode; friend class SHRenderGraph; diff --git a/SHADE_Engine/src/Graphics/SHVkUtil.cpp b/SHADE_Engine/src/Graphics/SHVkUtil.cpp index e4f9f37e..c8c563a1 100644 --- a/SHADE_Engine/src/Graphics/SHVkUtil.cpp +++ b/SHADE_Engine/src/Graphics/SHVkUtil.cpp @@ -23,6 +23,38 @@ namespace SHADE IsDepthOnlyFormat(format); } + bool SHVkUtil::IsBlendCompatible(vk::Format format) noexcept + { + // TODO: Update with all formats + switch (format) + { + case vk::Format::eR32Sint: + case vk::Format::eR32G32Sint: + case vk::Format::eR32G32B32Sint: + case vk::Format::eR32G32B32A32Sint: + return false; + case vk::Format::eR32Sfloat: + case vk::Format::eR32G32Sfloat: + case vk::Format::eR32G32B32Sfloat: + case vk::Format::eR32G32B32A32Sfloat: + return true; + } + return false; + } + + uint32_t SHVkUtil::GetBytesPerPixelFromFormat(vk::Format format) noexcept + { + // TODO: Update with all formats + switch (format) + { + case vk::Format::eR32Sint: + case vk::Format::eR32Uint: + case vk::Format::eR32Sfloat: + return 4; + } + return 0; + } + void SHVkUtil::EnsureBufferAndCopyData(Handle device, Handle cmdBuffer, Handle& bufferHandle, void* src, uint32_t size, vk::BufferUsageFlagBits usage) { if (bufferHandle) diff --git a/SHADE_Engine/src/Graphics/SHVkUtil.h b/SHADE_Engine/src/Graphics/SHVkUtil.h index cba5b062..ca3b6f83 100644 --- a/SHADE_Engine/src/Graphics/SHVkUtil.h +++ b/SHADE_Engine/src/Graphics/SHVkUtil.h @@ -19,9 +19,12 @@ namespace SHADE /*---------------------------------------------------------------------------------*/ class SHVkUtil { - public: - static bool IsDepthOnlyFormat (vk::Format format) noexcept; - static bool IsDepthStencilAttachment(vk::Format format) noexcept; + public: + static bool IsDepthOnlyFormat (vk::Format format) noexcept; + static bool IsDepthStencilAttachment (vk::Format format) noexcept; + static bool IsBlendCompatible (vk::Format format) noexcept; + static uint32_t GetBytesPerPixelFromFormat (vk::Format format) noexcept; + /***********************************************************************************/ /*! diff --git a/SHADE_Engine/src/Physics/SHPhysicsSystem.cpp b/SHADE_Engine/src/Physics/SHPhysicsSystem.cpp index c5a7aa57..7dc6c44e 100644 --- a/SHADE_Engine/src/Physics/SHPhysicsSystem.cpp +++ b/SHADE_Engine/src/Physics/SHPhysicsSystem.cpp @@ -198,9 +198,9 @@ namespace SHADE void SHPhysicsSystem::AddRigidBody(EntityID entityID) noexcept { - #ifdef _DEBUG - SHLOG_INFO("Adding a Rigidbody to the Physics World.") - #endif + //#ifdef _DEBUG + // SHLOG_INFO("Adding a Rigidbody to the Physics World.") + //#endif auto* physicsObject = CreatePhysicsObject(entityID); @@ -214,9 +214,9 @@ namespace SHADE void SHPhysicsSystem::AddCollider(EntityID entityID) noexcept { - #ifdef _DEBUG - SHLOG_INFO("Adding a Collider to the Physics World.") - #endif + //#ifdef _DEBUG + // SHLOG_INFO("Adding a Collider to the Physics World.") + //#endif auto* physicsObject = CreatePhysicsObject(entityID); @@ -375,7 +375,7 @@ namespace SHADE const auto it = map.find(entityID); if (it == map.end()) { - SHLOG_ERROR("Entity {} is not in the physics system!", entityID) + //SHLOG_ERROR("Entity {} is not in the physics system!", entityID) return nullptr; } diff --git a/SHADE_Engine/src/Scene/SHSceneGraph.cpp b/SHADE_Engine/src/Scene/SHSceneGraph.cpp index 3fe85809..bbbdb7e4 100644 --- a/SHADE_Engine/src/Scene/SHSceneGraph.cpp +++ b/SHADE_Engine/src/Scene/SHSceneGraph.cpp @@ -571,9 +571,9 @@ namespace SHADE { SHSceneNode* newNode = new SHSceneNode{entityID}; - #ifdef _DEBUG - SHLOG_INFO("Allocated a new Scene Node for Entity {}!", entityID) - #endif + //#ifdef _DEBUG + // SHLOG_INFO("Allocated a new Scene Node for Entity {}!", entityID) + //#endif entityNodeMap.emplace(entityID, newNode); return newNode; diff --git a/TempShaderFolder/TestCubeFs.glsl b/TempShaderFolder/TestCubeFs.glsl index 3a25ad71..18890c92 100644 --- a/TempShaderFolder/TestCubeFs.glsl +++ b/TempShaderFolder/TestCubeFs.glsl @@ -22,6 +22,7 @@ layout(location = 0) in struct layout(location = 2) flat in struct { int materialIndex; + uint eid; } In2; //layout (set = 0, binding = ) @@ -33,12 +34,13 @@ layout (set = 3, binding = 0) buffer MaterialProperties // For materials } MatProp; layout(location = 0) out vec4 outColor; +layout(location = 1) out uint outEntityID; void main() { - outColor = texture(textures[nonuniformEXT(MatProp.data[In2.materialIndex].textureIndex)], In.uv) + MatProp.data[In2.materialIndex].color / MatProp.data[In2.materialIndex].alpha; + outEntityID = In2.eid; //outColor = vec4 (1.0f); } \ No newline at end of file diff --git a/TempShaderFolder/TestCubeFs.spv b/TempShaderFolder/TestCubeFs.spv index 07f67a45..bde62136 100644 Binary files a/TempShaderFolder/TestCubeFs.spv and b/TempShaderFolder/TestCubeFs.spv differ diff --git a/TempShaderFolder/TestCubeVs.glsl b/TempShaderFolder/TestCubeVs.glsl index eb5b2dff..b7453f13 100644 --- a/TempShaderFolder/TestCubeVs.glsl +++ b/TempShaderFolder/TestCubeVs.glsl @@ -8,6 +8,7 @@ layout(location = 1) in vec2 aUV; layout(location = 2) in vec3 aNormal; layout(location = 3) in vec3 aTangent; layout(location = 4) in mat4 worldTransform; +layout(location = 8) in uint eid; layout(location = 0) out struct @@ -21,6 +22,8 @@ layout(location = 0) out struct layout(location = 2) out struct { int materialIndex; + uint eid; + } Out2; layout(set = 2, binding = 0) uniform CameraData @@ -33,6 +36,7 @@ void main() { Out.uv = aUV; Out2.materialIndex = gl_InstanceIndex; + Out2.eid = eid; gl_Position = cameraData.vpMat * worldTransform * vec4 (aVertexPos, 1.0f); Out.vertColor = vec4 (aVertexPos, 1.0f); } \ No newline at end of file diff --git a/TempShaderFolder/TestCubeVs.spv b/TempShaderFolder/TestCubeVs.spv index dfc9eda1..1662cfbd 100644 Binary files a/TempShaderFolder/TestCubeVs.spv and b/TempShaderFolder/TestCubeVs.spv differ