From 8e8fa1cd6de41f7748c073fc5234296b302be2cc Mon Sep 17 00:00:00 2001 From: antopilo Date: Thu, 9 Jan 2025 19:21:53 -0500 Subject: [PATCH] Fixed color attachments not working --- Editor/src/Windows/EditorInterface.cpp | 21 +++++++------- .../Vulkan/Pipeline/RenderPipeline.cpp | 1 + .../src/Rendering/Vulkan/PipelineBuilder.cpp | 29 ++++++++++++------- .../Rendering/Vulkan/VulkanSceneRenderer.cpp | 6 ++-- Nuake/src/Window.cpp | 1 + Resources/Shaders/Vulkan/triangle.frag | 2 +- 6 files changed, 35 insertions(+), 25 deletions(-) diff --git a/Editor/src/Windows/EditorInterface.cpp b/Editor/src/Windows/EditorInterface.cpp index fdc84a95..bf7bcffe 100644 --- a/Editor/src/Windows/EditorInterface.cpp +++ b/Editor/src/Windows/EditorInterface.cpp @@ -626,40 +626,39 @@ namespace Nuake { framebuffer->QueueResize(viewportPanelSize * Engine::GetProject()->Settings.ResolutionScale); Ref texture = framebuffer->GetTexture(); + VkDescriptorSet textureDesc = VkRenderer::Get().GetDrawImage()->GetImGuiDescriptorSet(); + + auto& pipeline = VkRenderer::Get().GetRenderPipeline(); if (SelectedViewport == 1) { + textureDesc = pipeline.GetRenderPass("GBuffer").GetAttachment("Albedo").Image->GetImGuiDescriptorSet(); texture = Engine::GetCurrentScene()->m_SceneRenderer->GetGBuffer().GetTexture(GL_COLOR_ATTACHMENT0); } else if (SelectedViewport == 2) { + textureDesc = pipeline.GetRenderPass("GBuffer").GetAttachment("Normal").Image->GetImGuiDescriptorSet(); texture = Engine::GetCurrentScene()->m_SceneRenderer->GetGBuffer().GetTexture(GL_COLOR_ATTACHMENT1); } else if (SelectedViewport == 3) { + textureDesc = pipeline.GetRenderPass("GBuffer").GetDepthAttachment().Image->GetImGuiDescriptorSet(); texture = Engine::GetCurrentScene()->m_SceneRenderer->GetScaledDepthTexture(); } else if (SelectedViewport == 4) { + textureDesc = pipeline.GetRenderPass("GBuffer").GetAttachment("Material").Image->GetImGuiDescriptorSet(); texture = Engine::GetCurrentScene()->m_SceneRenderer->GetVelocityTexture(); } - else if (SelectedViewport == 5) - { - texture = Engine::GetCurrentScene()->m_SceneRenderer->GetGBuffer().GetTexture(GL_COLOR_ATTACHMENT6); - } - else if (SelectedViewport == 6) - { - texture = Engine::GetCurrentScene()->GetEnvironment()->mSSAO->GetOuput()->GetTexture(); - } ImVec2 imagePos = ImGui::GetWindowPos() + ImGui::GetCursorPos(); Input::SetEditorViewportSize(m_ViewportPos, viewportPanelSize); ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0, 0)); m_ViewportPos = { imagePos.x, imagePos.y }; - ImGui::Image(VkRenderer::Get().GetDrawImage()->GetImGuiDescriptorSet(), regionAvail, {0, 1}, {1, 0}); + ImGui::Image(textureDesc, regionAvail, {0, 1}, {1, 0}); ImGui::PopStyleVar(); const Vector2& mousePos = Input::GetMousePosition(); - + const ImVec2& windowPos = ImGui::GetWindowPos(); const auto windowPosNuake = Vector2(windowPos.x, windowPos.y); const ImVec2& windowSize = ImGui::GetWindowSize(); @@ -1973,7 +1972,7 @@ namespace Nuake { ImGui::PushStyleColor(ImGuiCol_FrameBg, IM_COL32(20, 20, 20, 0)); ImGui::PushStyleColor(ImGuiCol_FrameBgHovered, IM_COL32(20, 20, 20, 60)); ImGui::PushStyleColor(ImGuiCol_FrameBgHovered, IM_COL32(33, 33, 33, 45)); - const char* items[] = { "Shaded", "Albedo", "Normal", "Depth", "Velocity", "UV", "SSAO"}; + const char* items[] = { "Shaded", "Albedo", "Normal", "Depth", "Material", "UV", "SSAO"}; ImGui::SetNextItemWidth(128); if (ImGui::BeginCombo("##Output", items[SelectedViewport])) { diff --git a/Nuake/src/Rendering/Vulkan/Pipeline/RenderPipeline.cpp b/Nuake/src/Rendering/Vulkan/Pipeline/RenderPipeline.cpp index 5b9d7589..5231ad7f 100644 --- a/Nuake/src/Rendering/Vulkan/Pipeline/RenderPipeline.cpp +++ b/Nuake/src/Rendering/Vulkan/Pipeline/RenderPipeline.cpp @@ -283,6 +283,7 @@ void RenderPass::Build() { formats.push_back(static_cast(Attachments[i].Format)); } + pipelineBuilder.SetColorAttachments(formats); // Set depth attachment, for now we assume every pass has a depth attachment if (HasDepthTest) diff --git a/Nuake/src/Rendering/Vulkan/PipelineBuilder.cpp b/Nuake/src/Rendering/Vulkan/PipelineBuilder.cpp index 1ba435c0..f3538866 100644 --- a/Nuake/src/Rendering/Vulkan/PipelineBuilder.cpp +++ b/Nuake/src/Rendering/Vulkan/PipelineBuilder.cpp @@ -50,6 +50,12 @@ VkPipeline PipelineBuilder::BuildPipeline(VkDevice device) colorBlending.attachmentCount = ColorBlendAttachment.size(); colorBlending.pAttachments = ColorBlendAttachment.data(); + if (ColorBlendAttachment.size() == 0) + { + Logger::Log("Forgot blend attachment!", "vulkan", CRITICAL); + assert(false && "Error"); + } + // completely clear VertexInputStateCreateInfo, as we have no need for it VkPipelineVertexInputStateCreateInfo _vertexInputInfo = { .sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO }; @@ -211,15 +217,18 @@ void PipelineBuilder::EnableBlendingAdditive() void PipelineBuilder::EnableBlendingAlphaBlend(size_t count) { - VkPipelineColorBlendAttachmentState colorBlend = {}; - colorBlend.colorWriteMask = VK_COLOR_COMPONENT_R_BIT | VK_COLOR_COMPONENT_G_BIT | VK_COLOR_COMPONENT_B_BIT | VK_COLOR_COMPONENT_A_BIT; - colorBlend.blendEnable = VK_TRUE; - colorBlend.srcColorBlendFactor = VK_BLEND_FACTOR_SRC_ALPHA; - colorBlend.dstColorBlendFactor = VK_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA; - colorBlend.colorBlendOp = VK_BLEND_OP_ADD; - colorBlend.srcAlphaBlendFactor = VK_BLEND_FACTOR_ONE; - colorBlend.dstAlphaBlendFactor = VK_BLEND_FACTOR_ZERO; - colorBlend.alphaBlendOp = VK_BLEND_OP_ADD; + for (int i = 0; i < count; i++) + { + VkPipelineColorBlendAttachmentState colorBlend = {}; + colorBlend.colorWriteMask = VK_COLOR_COMPONENT_R_BIT | VK_COLOR_COMPONENT_G_BIT | VK_COLOR_COMPONENT_B_BIT | VK_COLOR_COMPONENT_A_BIT; + colorBlend.blendEnable = VK_TRUE; + colorBlend.srcColorBlendFactor = VK_BLEND_FACTOR_SRC_ALPHA; + colorBlend.dstColorBlendFactor = VK_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA; + colorBlend.colorBlendOp = VK_BLEND_OP_ADD; + colorBlend.srcAlphaBlendFactor = VK_BLEND_FACTOR_ONE; + colorBlend.dstAlphaBlendFactor = VK_BLEND_FACTOR_ZERO; + colorBlend.alphaBlendOp = VK_BLEND_OP_ADD; - ColorBlendAttachment.push_back(colorBlend); + ColorBlendAttachment.push_back(colorBlend); + } } \ No newline at end of file diff --git a/Nuake/src/Rendering/Vulkan/VulkanSceneRenderer.cpp b/Nuake/src/Rendering/Vulkan/VulkanSceneRenderer.cpp index 91bfce95..847e73e4 100644 --- a/Nuake/src/Rendering/Vulkan/VulkanSceneRenderer.cpp +++ b/Nuake/src/Rendering/Vulkan/VulkanSceneRenderer.cpp @@ -252,7 +252,7 @@ void VkSceneRenderer::CreatePipelines() auto& gBufferPass = GBufferPipeline.AddPass("GBuffer"); gBufferPass.SetShaders(Shaders["basic_vert"], Shaders["basic_frag"]); gBufferPass.AddAttachment("Albedo", ImageFormat::RGBA8); - gBufferPass.AddAttachment("Normal", ImageFormat::RGBA16F); + gBufferPass.AddAttachment("Normal", ImageFormat::RGBA8); gBufferPass.AddAttachment("Material", ImageFormat::RGBA8); gBufferPass.AddAttachment("Depth", ImageFormat::D32F, ImageUsage::Depth); gBufferPass.SetPushConstant(modelPushConstant); @@ -353,7 +353,7 @@ void VkSceneRenderer::CreatePipelines() }); - /* + auto& shadingPass = GBufferPipeline.AddPass("Shading"); shadingPass.SetShaders(Shaders["shading_vert"], Shaders["shading_frag"]); shadingPass.SetPushConstant(shadingPushConstant); @@ -434,7 +434,7 @@ void VkSceneRenderer::CreatePipelines() vkCmdBindIndexBuffer(ctx.commandBuffer, quadMesh->GetIndexBuffer()->GetBuffer(), 0, VK_INDEX_TYPE_UINT32); vkCmdDrawIndexed(ctx.commandBuffer, quadMesh->GetIndexBuffer()->GetSize() / sizeof(uint32_t), 1, 0, 0, 0); }); - */ + GBufferPipeline.Build(); } diff --git a/Nuake/src/Window.cpp b/Nuake/src/Window.cpp index 444c8c56..0a009d7f 100644 --- a/Nuake/src/Window.cpp +++ b/Nuake/src/Window.cpp @@ -245,6 +245,7 @@ void Window::EndDraw() vkRenderer.GetCurrentCmdBuffer() }; + GPUResources::Get().RecreateBindlessTextures(); vkRenderer.DrawScene(ctx); } } diff --git a/Resources/Shaders/Vulkan/triangle.frag b/Resources/Shaders/Vulkan/triangle.frag index bfb13279..14168cff 100644 --- a/Resources/Shaders/Vulkan/triangle.frag +++ b/Resources/Shaders/Vulkan/triangle.frag @@ -92,7 +92,7 @@ PSOutput main(PSInput input) albedoColor.xyz = albedoSample.xyz; } output.oColor0 = albedoColor; - output.oColor0 = float4(normal, 1.0); + // MATERIAL PROPERTIES float metalnessValue = inMaterial.metalnessValue; if(inMaterial.hasMetalness == 1)