Fixed color attachments not working

This commit is contained in:
antopilo
2025-01-09 19:21:53 -05:00
parent a197ab62a6
commit 8e8fa1cd6d
6 changed files with 35 additions and 25 deletions

View File

@@ -626,40 +626,39 @@ namespace Nuake {
framebuffer->QueueResize(viewportPanelSize * Engine::GetProject()->Settings.ResolutionScale);
Ref<Texture> 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]))
{

View File

@@ -283,6 +283,7 @@ void RenderPass::Build()
{
formats.push_back(static_cast<VkFormat>(Attachments[i].Format));
}
pipelineBuilder.SetColorAttachments(formats);
// Set depth attachment, for now we assume every pass has a depth attachment
if (HasDepthTest)

View File

@@ -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);
}
}

View File

@@ -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>(modelPushConstant);
@@ -353,7 +353,7 @@ void VkSceneRenderer::CreatePipelines()
});
/*
auto& shadingPass = GBufferPipeline.AddPass("Shading");
shadingPass.SetShaders(Shaders["shading_vert"], Shaders["shading_frag"]);
shadingPass.SetPushConstant<ShadingPushConstant>(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();
}

View File

@@ -245,6 +245,7 @@ void Window::EndDraw()
vkRenderer.GetCurrentCmdBuffer()
};
GPUResources::Get().RecreateBindlessTextures();
vkRenderer.DrawScene(ctx);
}
}

View File

@@ -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)