From 8ad0eee032563d6366d285f731a8edc910aef5bb Mon Sep 17 00:00:00 2001 From: Kah Wei Date: Mon, 19 Sep 2022 21:31:23 +0800 Subject: [PATCH] Fixed vertex data buffer being incorrect --- .../src/Application/SBApplication.cpp | 2 +- .../MiddleEnd/Interface/SHGraphicsSystem.cpp | 14 +++++++------- .../MiddleEnd/Meshes/SHPrimitiveGenerator.cpp | 4 ++-- .../MiddleEnd/Meshes/SHPrimitiveGenerator.h | 6 ++++++ .../src/Graphics/Pipeline/SHPipelineState.cpp | 2 ++ .../src/Graphics/Pipeline/SHVkPipeline.cpp | 2 +- TempShaderFolder/TestCubeFs.glsl | 2 +- TempShaderFolder/TestCubeFs.spv | Bin 632 -> 592 bytes 8 files changed, 20 insertions(+), 12 deletions(-) diff --git a/SHADE_Application/src/Application/SBApplication.cpp b/SHADE_Application/src/Application/SBApplication.cpp index c804bf5e..805e8148 100644 --- a/SHADE_Application/src/Application/SBApplication.cpp +++ b/SHADE_Application/src/Application/SBApplication.cpp @@ -73,7 +73,7 @@ namespace Sandbox auto& renderable = *SHADE::SHComponentManager::GetComponent_s(entity); renderable.Mesh = CUBE_MESH; renderable.SetMaterial(matInst); - renderable.TransformMatrix.Scale(2.0f, 2.0f, 2.0f); + renderable.TransformMatrix.Translate(0.0f, 0.0f, 2.0f); } void SBApplication::Update(void) diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp index 9c9606b2..ea18b817 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp @@ -121,11 +121,11 @@ namespace SHADE // Initialize world render graph worldRenderGraph->Init(device, swapchain, &defaultVertexInputState, &globalDescSetLayouts); - 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("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("Present", SH_ATT_DESC_TYPE::COLOR_PRESENT, windowDims.first, windowDims.second); - auto node = worldRenderGraph->AddNode("G-Buffer", { "Composite", "Position", "Normals", "Present" }, {}); // no predecessors + auto node = worldRenderGraph->AddNode("G-Buffer", { /*"Composite", "Position", "Normals",*/ "Present" }, {}); // no predecessors //First subpass to write to G-Buffer auto gBufferWriteSubpass = node->AddSubpass("G-Buffer Write"); @@ -485,9 +485,9 @@ 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) } void SHGraphicsSystem::BeginRoutine::Execute(double) noexcept diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Meshes/SHPrimitiveGenerator.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Meshes/SHPrimitiveGenerator.cpp index 36fa0b26..2080265b 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Meshes/SHPrimitiveGenerator.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Meshes/SHPrimitiveGenerator.cpp @@ -193,7 +193,7 @@ namespace SHADE Handle SHPrimitiveGenerator::Cube(SHMeshLibrary& meshLibrary) noexcept { - SHMeshData meshData = Cube(); + static SHMeshData meshData = Cube(); return meshLibrary.AddMesh ( meshData.VertexPositions.size(), @@ -208,7 +208,7 @@ namespace SHADE Handle SHPrimitiveGenerator::Cube(SHGraphicsSystem& gfxSystem) noexcept { - SHMeshData meshData = Cube(); + static SHMeshData meshData = Cube(); return gfxSystem.AddMesh ( meshData.VertexPositions.size(), diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Meshes/SHPrimitiveGenerator.h b/SHADE_Engine/src/Graphics/MiddleEnd/Meshes/SHPrimitiveGenerator.h index e338a9d8..dd059a29 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Meshes/SHPrimitiveGenerator.h +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Meshes/SHPrimitiveGenerator.h @@ -79,5 +79,11 @@ namespace SHADE */ /***********************************************************************************/ [[nodiscard]] static Handle Cube(SHGraphicsSystem& gfxSystem) noexcept; + + private: + /*---------------------------------------------------------------------------------*/ + /* Helper Functions */ + /*---------------------------------------------------------------------------------*/ + [[nodiscard]] static SHMeshData genCubeData() noexcept; }; } \ No newline at end of file diff --git a/SHADE_Engine/src/Graphics/Pipeline/SHPipelineState.cpp b/SHADE_Engine/src/Graphics/Pipeline/SHPipelineState.cpp index e7c245db..f8934bf6 100644 --- a/SHADE_Engine/src/Graphics/Pipeline/SHPipelineState.cpp +++ b/SHADE_Engine/src/Graphics/Pipeline/SHPipelineState.cpp @@ -204,6 +204,8 @@ namespace SHADE // Offset is 0 at first (for first element) uint32_t offset = 0; + binding.binding = static_cast(bindings.size() - 1); + // for every attribute passed in for (auto const& attrib : inAttribs) { diff --git a/SHADE_Engine/src/Graphics/Pipeline/SHVkPipeline.cpp b/SHADE_Engine/src/Graphics/Pipeline/SHVkPipeline.cpp index 6a20ab55..1c47c21a 100644 --- a/SHADE_Engine/src/Graphics/Pipeline/SHVkPipeline.cpp +++ b/SHADE_Engine/src/Graphics/Pipeline/SHVkPipeline.cpp @@ -206,7 +206,7 @@ namespace SHADE */ /***************************************************************************/ SHVkPipeline::SHVkPipeline(Handle const& inLogicalDeviceHdl, Handle const& inPipelineLayout, SHVkPipelineState const* const state, Handle const& renderpassHdl, Handle subpass, SH_PIPELINE_TYPE type) noexcept - : pipelineState{ } // copy the pipeline state + : pipelineState{ } , pipelineType {type} , vkPipeline {VK_NULL_HANDLE} , logicalDeviceHdl{ inLogicalDeviceHdl } diff --git a/TempShaderFolder/TestCubeFs.glsl b/TempShaderFolder/TestCubeFs.glsl index dc069eda..7d49eda4 100644 --- a/TempShaderFolder/TestCubeFs.glsl +++ b/TempShaderFolder/TestCubeFs.glsl @@ -68,5 +68,5 @@ void main() //outColor.a = diffuseColor.a; - outColor = In.vertColor; + outColor = vec4 (1.0f); } \ No newline at end of file diff --git a/TempShaderFolder/TestCubeFs.spv b/TempShaderFolder/TestCubeFs.spv index f0dbc4493589074291db908844fbb1e8c2e3fb59..669dc8b8a5cbe234e67679632cc1f1c6cc42a491 100644 GIT binary patch delta 185 zcmeyta)E`HnMs+Qfq{{Mi-DJceKvc2Qo@C@=eZVj1JXiU;(OR0Ga{<4fZ+=>_EuCzzxJ8F=Q+U)C)2bB(DI}#|xwx gffyua4dwHJ#3m~;$&1(lRdWJ)Ad~(A)mZ>B0Eo*FbpQYW delta 225 zcmcb>@`Ht!nMs+Qfq{{Mi-DIxXd