Merge pull request #326 from SHADE-DP/SP3-1-Rendering

Fixed UI Rendering
This commit is contained in:
XiaoQiDigipen 2023-01-31 22:53:03 +08:00 committed by GitHub
commit ab48efce30
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
18 changed files with 112 additions and 56 deletions

View File

@ -1,4 +1,4 @@
Start in Fullscreen: false
Starting Scene ID: 87244611
Starting Scene ID: 97158628
Window Size: {x: 1920, y: 1080}
Window Title: SHADE Engine

View File

@ -1,6 +1,6 @@
- VertexShader: 46580970
FragmentShader: 35983630
SubPass: G-Buffer Write
SubPass: UI
Properties:
data.color: {x: 1, y: 1, z: 1, w: 1}
data.textureIndex: 54324293

View File

@ -1,6 +1,6 @@
- VertexShader: 46580970
FragmentShader: 35983630
SubPass: G-Buffer Write
SubPass: UI
Properties:
data.color: {x: 1, y: 1, z: 1, w: 1}
data.textureIndex: 54429632

View File

@ -1,6 +1,6 @@
- VertexShader: 46580970
FragmentShader: 35983630
SubPass: G-Buffer Write
SubPass: UI
Properties:
data.color: {x: 1, y: 1, z: 1, w: 1}
data.textureIndex: 57302694

View File

@ -33,18 +33,11 @@ layout (std430, set = 2, binding = 0) buffer MaterialProperties // For mater
MatPropData data[];
} MatProp;
layout(location = 0) out vec4 position;
layout(location = 0) out vec4 fragColor;
layout(location = 1) out uint outEntityID;
layout(location = 2) out uint lightLayerIndices;
layout(location = 3) out vec4 normals;
layout(location = 4) out vec4 albedo;
void main()
{
position = In.vertPos;
normals = In.normal;
albedo = texture(textures[nonuniformEXT(MatProp.data[In2.materialIndex].textureIndex)], In.uv);
fragColor = texture(textures[nonuniformEXT(MatProp.data[In2.materialIndex].textureIndex)], In.uv);
outEntityID = In2.eid;
lightLayerIndices = In2.lightLayerIndex;
}

Binary file not shown.

View File

@ -314,7 +314,7 @@ namespace SHADE
camera.orthoProjMatrix(3, 3) = 1.0f;
//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.orthoProjMatrix = SHMatrix::OrthographicLH(camera.GetWidth(), camera.GetHeight(), camera.GetNear(), camera.GetFar());
//camera.perspProjMatrix = SHMatrix::OrthographicLH(5.0f, 5.0f, 0.1f, 20.0f);
//camera.projMatrix.Transpose();

View File

@ -1,8 +1,11 @@
#include "SHpch.h"
#include <memory>
#include <imgui.h>
#include "Serialization/SHSerializationHelper.hpp"
#include "SHMaterialInspector.h"
#include "Editor/SHImGuiHelpers.hpp"
#include <imgui.h>
#include "Assets/SHAssetManager.h"
#include "Editor/IconsMaterialDesign.h"
@ -89,11 +92,17 @@ namespace SHADE
if (vertShader && fragShader && gfxSystem)
{
// - Retrieve pipeline from pipeline library
auto renderPass = gfxSystem->GetPrimaryRenderpass();
auto subPass = renderPass->GetSubpass(currentMatSpec->subpassName);
auto pipeline = renderPass->GetOrCreatePipeline({ vertShader, fragShader }, subPass);
// - Set Pipeline
matHandle->SetPipeline(pipeline);
auto subPass = gfxSystem->GetUsableSubpass(currentMatSpec->subpassName);
if (subPass)
{
// Set Pipeline if valid
auto pipeline = subPass->GetParentNode()->GetOrCreatePipeline({vertShader, fragShader}, subPass);
matHandle->SetPipeline(pipeline);
}
else
{
SHLOG_ERROR("[SHMaterialInspector] Failed to find material subpass of type \"{}\"", currentMatSpec->subpassName);
}
}
}
@ -176,7 +185,7 @@ namespace SHADE
const std::string VERT_SHADER_NAME = VERT_SHADER_INFO ? VERT_SHADER_INFO->name : "Unknown Shader";
isDirty |= SHEditorWidgets::DragDropReadOnlyField<AssetID>
(
"Fragment Shader", VERT_SHADER_NAME.data(),
"Vertex Shader", VERT_SHADER_NAME.data(),
[this]() { return currentMatSpec->vertexShader; },
[this](const AssetID& id) { currentMatSpec->vertexShader = id; },
SHDragDrop::DRAG_RESOURCE
@ -191,6 +200,37 @@ namespace SHADE
SHDragDrop::DRAG_RESOURCE
);
// Subpass
const auto& SP_NAMES = SHGraphicsConstants::RenderGraphEntityNames::USABLE_SUBPASSES;
ImGui::Text("Subpass");
ImGui::SameLine();
if (ImGui::BeginCombo("##", currentMatSpec->subpassName.data(), ImGuiComboFlags_None))
{
for (const auto& NAME : SP_NAMES)
{
const bool IS_SELECTED = currentMatSpec->subpassName == NAME;
if (ImGui::Selectable(NAME.data(), IS_SELECTED))
{
isDirty = true;
SHCommandManager::PerformCommand
(
std::reinterpret_pointer_cast<SHBaseCommand>(std::make_shared<SHCommand<std::string>>
(
currentMatSpec->subpassName,
std::string(NAME),
[&](const std::string& newName){ currentMatSpec->subpassName = newName; }
)),
false
);
}
if (IS_SELECTED)
{
ImGui::SetItemDefaultFocus();
}
}
ImGui::EndCombo();
}
// Load the shader to access it's data
auto fragShader = SHResourceManager::LoadOrGet<SHVkShaderModule>(currentMatSpec->fragShader);
if (!fragShader)

View File

@ -98,9 +98,9 @@ namespace SHADE
static bool IsItemHovered();
/*-----------------------------------------------------------------------------*/
/* ImGui Wrapper Functions - Menu */
/*-----------------------------------------------------------------------------*/
static bool BeginMenu(const std::string& label);
/* ImGui Wrapper Functions - Menu */
/*-----------------------------------------------------------------------------*/
static bool BeginMenu(const std::string& label);
static bool BeginMenu(const std::string& label, const char* icon);
static void EndMenu();
static void BeginTooltip();
@ -164,8 +164,8 @@ namespace SHADE
/// </summary>
/// <param name="title">Text to display.</param>
/// <returns>True if button was pressed.</returns>
static bool Button(const std::string& title);
static bool Selectable(const std::string& label);
static bool Button(const std::string& title);
static bool Selectable(const std::string& label);
static bool Selectable(const std::string& label, const char* icon);
/// <summary>
/// Creates a checkbox widget for boolean input.

View File

@ -13,6 +13,7 @@ of DigiPen Institute of Technology is prohibited.
// STL Includes
#include <cstdint>
#include <string>
namespace SHADE
{
@ -114,7 +115,14 @@ namespace SHADE
static constexpr std::string_view DEFERRED_COMPOSITE_COMPUTE = "Deferred Composite";
static constexpr std::string_view GBUFFER_WRITE_SUBPASS = "G-Buffer Write";
static constexpr std::string_view UI_SUBPASS = "UI";
static constexpr std::array USABLE_SUBPASSES =
{
GBUFFER_WRITE_SUBPASS,
UI_SUBPASS
};
};
struct DescriptorSetBindings

View File

@ -133,6 +133,9 @@ namespace SHADE
//SHAssetManager::CompileAsset("../../Assets/Shaders/PureCopy_CS.glsl", false);
//SHAssetManager::CompileAsset("../../Assets/Shaders/TestCube_VS.glsl", false);
//SHAssetManager::CompileAsset("../../Assets/Shaders/TestCube_FS.glsl", false);
//SHAssetManager::CompileAsset("../../Assets/Shaders/UI_VS.glsl", false);
//SHAssetManager::CompileAsset("../../Assets/Shaders/UI_FS.glsl", false);
//SHAssetManager::CompileAsset("../../Assets/Shaders/Text_VS.glsl", false);
// Load Built In Shaders
static constexpr AssetID VS_DEFAULT = 39210065; defaultVertShader = SHResourceManager::LoadOrGet<SHVkShaderModule>(VS_DEFAULT);
@ -232,7 +235,7 @@ namespace SHADE
/*-----------------------------------------------------------------------*/
/* G-BUFFER SUBPASS INIT */
/*-----------------------------------------------------------------------*/
auto gBufferSubpass = gBufferNode->AddSubpass("G-Buffer Write", worldViewport, worldRenderer);
auto gBufferSubpass = gBufferNode->AddSubpass(SHGraphicsConstants::RenderGraphEntityNames::GBUFFER_WRITE_SUBPASS.data(), worldViewport, worldRenderer);
gBufferSubpass->AddColorOutput("Position");
gBufferSubpass->AddColorOutput("Entity ID");
gBufferSubpass->AddColorOutput("Light Layer Indices");
@ -241,6 +244,7 @@ namespace SHADE
gBufferSubpass->AddColorOutput("Position World Space");
gBufferSubpass->AddDepthOutput("Depth Buffer", SH_RENDER_GRAPH_RESOURCE_FLAGS::DEPTH_STENCIL);
usableSubpassesMapping.emplace (std::string (SHGraphicsConstants::RenderGraphEntityNames::GBUFFER_WRITE_SUBPASS.data()), gBufferSubpass);
/*-----------------------------------------------------------------------*/
/* SSAO PASS AND DATA INIT */
@ -319,7 +323,7 @@ namespace SHADE
/* SCREEN SPACE PASS */
/*-----------------------------------------------------------------------*/
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);
auto uiSubpass = screenSpaceNode->AddSubpass(SHGraphicsConstants::RenderGraphEntityNames::UI_SUBPASS.data(), worldViewport, screenRenderer);
uiSubpass->AddColorOutput("Scene");
uiSubpass->AddColorOutput("Entity ID");
uiSubpass->AddExteriorDrawCalls([=](Handle<SHVkCommandBuffer> cmdBuffer, Handle<SHRenderer> renderer, uint32_t frameIndex)
@ -327,6 +331,8 @@ namespace SHADE
textRenderingSubSystem->Render(cmdBuffer, renderer, frameIndex);
});
usableSubpassesMapping.emplace(SHGraphicsConstants::RenderGraphEntityNames::UI_SUBPASS.data(), uiSubpass);
/*-----------------------------------------------------------------------*/
/* RENDER TO SWAPCHAIN IMAGE FOR PRESENT PASS */
/*-----------------------------------------------------------------------*/
@ -416,12 +422,12 @@ namespace SHADE
.addressMode = vk::SamplerAddressMode::eClampToBorder,
})
);
textRenderingSubSystem = resourceManager.Create<SHTextRenderingSubSystem>();
// initialize the text renderer
auto uiNode = renderGraph->GetNode(SHGraphicsConstants::RenderGraphEntityNames::SCREEN_SPACE_PASS.data());
textRenderingSubSystem->Init(device, uiNode->GetRenderpass(), uiNode->GetSubpass("UI"), descPool, textVS, textFS);
textRenderingSubSystem->Init(device, uiNode->GetRenderpass(), uiNode->GetSubpass(SHGraphicsConstants::RenderGraphEntityNames::UI_SUBPASS), descPool, textVS, textFS);
SHGlobalDescriptorSets::SetLightingSubSystem(lightingSubSystem);
@ -448,7 +454,7 @@ namespace SHADE
defaultMaterial = AddMaterial
(
defaultVertShader, defaultFragShader,
renderGraph->GetNode(SHGraphicsConstants::RenderGraphEntityNames::GBUFFER_PASS.data())->GetSubpass("G-Buffer Write")
renderGraph->GetNode(SHGraphicsConstants::RenderGraphEntityNames::GBUFFER_PASS.data())->GetSubpass(SHGraphicsConstants::RenderGraphEntityNames::GBUFFER_WRITE_SUBPASS)
);
defaultMaterial->SetProperty("data.textureIndex", defaultTexture->TextureArrayIndex);
defaultAnimMaterial = AddMaterial
@ -573,7 +579,7 @@ namespace SHADE
else
renderer->UpdateData(frameIndex);
#else
renderers[renIndex]->UpdateDataAndBind(frameIndex);
renderer->UpdateData(frameIndex);
#endif
}
@ -589,16 +595,8 @@ namespace SHADE
renderGraph->Begin(frameIndex);
auto cmdBuffer = renderGraph->GetCommandBuffer(frameIndex);
// Bind all the buffers required for meshes
for (auto& [buffer, bindingPoint] : MESH_DATA)
{
if (buffer->GetUsageBits() & vk::BufferUsageFlagBits::eVertexBuffer)
cmdBuffer->BindVertexBuffer(bindingPoint, buffer, 0);
else if (buffer->GetUsageBits() & vk::BufferUsageFlagBits::eIndexBuffer)
cmdBuffer->BindIndexBuffer(buffer, 0);
}
renderGraph->Execute(frameIndex, descPool);
renderGraph->Execute(frameIndex, descPool, MESH_DATA);
renderGraph->End(frameIndex);
graphicsQueue->SubmitCommandBuffer
@ -774,7 +772,7 @@ namespace SHADE
auto const& EVENT_DATA = reinterpret_cast<const SHEventSpec<SHLightEnableShadowEvent>*>(eventPtr.get())->data;
auto* lightComp = SHComponentManager::GetComponent<SHLightComponent>(EVENT_DATA->lightEntity);
std::string resourceName = "ShadowMap " + std::to_string(EVENT_DATA->lightEntity);
Handle<SHSubpass> companionSubpass = renderGraph->GetNode(SHGraphicsConstants::RenderGraphEntityNames::GBUFFER_PASS.data())->GetSubpass("G-Buffer Write");
Handle<SHSubpass> companionSubpass = renderGraph->GetNode(SHGraphicsConstants::RenderGraphEntityNames::GBUFFER_PASS.data())->GetSubpass(SHGraphicsConstants::RenderGraphEntityNames::GBUFFER_WRITE_SUBPASS);
if (EVENT_DATA->generateRenderer)
{
@ -1196,6 +1194,16 @@ namespace SHADE
return fontLibrary;
}
Handle <SHSubpass> SHGraphicsSystem::GetUsableSubpass(std::string const& subpassName) const noexcept
{
if (usableSubpassesMapping.contains(subpassName))
{
return usableSubpassesMapping.at (subpassName);
}
else
return {};
}
Handle<SHVkPipeline> SHGraphicsSystem::createDebugDrawPipeline(Handle<SHVkRenderpass> renderPass, Handle<SHSubpass> subpass, bool filled, bool triMesh, bool instanced)
{
auto pipelineLayout = resourceManager.Create<SHVkPipelineLayout>

View File

@ -399,6 +399,7 @@ namespace SHADE
uint32_t GetCurrentFrameIndex(void) const noexcept { return renderContext.GetCurrentFrame(); }
SHFontLibrary const& GetFontLibrary (void) const noexcept;
const SHMeshLibrary& GetMeshLibrary() const noexcept { return meshLibrary; };
Handle <SHSubpass> GetUsableSubpass(std::string const& subpassName) const noexcept;
/*-----------------------------------------------------------------------------*/
/* Getters */
@ -509,6 +510,8 @@ namespace SHADE
uint32_t resizeHeight = 1;
bool restoredFromMinimize = false;
std::unordered_map<std::string, Handle<SHSubpass>> usableSubpassesMapping{};
/*---------------------------------------------------------------------------------*/
/* Helper Functions */
/*---------------------------------------------------------------------------------*/

View File

@ -565,7 +565,7 @@ namespace SHADE
// TODO: The graph scope buffers were meant to bind vertex buffers and index buffers for meshes. Find a
// better way to manage these
void SHRenderGraph::Execute(uint32_t frameIndex, Handle<SHVkDescriptorPool> descPool) noexcept
void SHRenderGraph::Execute(uint32_t frameIndex, Handle<SHVkDescriptorPool> descPool, const std::initializer_list<std::pair<Handle<SHVkBuffer>, uint32_t>> MESH_DATA) noexcept
{
auto cmdBuffer = commandBuffers[frameIndex];
cmdBuffer->BeginLabeledSegment(name);
@ -577,6 +577,7 @@ namespace SHADE
cmdBuffer->ForceSetPipelineLayout(batchingSystemData.dummyPipelineLayout, SH_PIPELINE_TYPE::COMPUTE);
auto const& descMappings = SHGraphicsPredefinedData::GetMappings(SHGraphicsPredefinedData::SystemType::BATCHING);
for (auto& node : nodes)
{
@ -585,6 +586,15 @@ namespace SHADE
// bind static global data
SHGlobalDescriptorSets::BindStaticGlobalData(cmdBuffer, SH_PIPELINE_TYPE::GRAPHICS, descMappings.at(SHPredefinedDescriptorTypes::STATIC_DATA));
// Bind all the buffers required for meshes
for (auto& [buffer, bindingPoint] : MESH_DATA)
{
if (buffer->GetUsageBits() & vk::BufferUsageFlagBits::eVertexBuffer)
cmdBuffer->BindVertexBuffer(bindingPoint, buffer, 0);
else if (buffer->GetUsageBits() & vk::BufferUsageFlagBits::eIndexBuffer)
cmdBuffer->BindIndexBuffer(buffer, 0);
}
node->Execute(cmdBuffer, descPool, frameIndex);
}
}

View File

@ -143,7 +143,7 @@ namespace SHADE
void Generate (void) noexcept;
void CheckForNodeComputes (void) noexcept;
void Execute (uint32_t frameIndex, Handle<SHVkDescriptorPool> descPool) noexcept;
void Execute (uint32_t frameIndex, Handle<SHVkDescriptorPool> descPool, const std::initializer_list<std::pair<Handle<SHVkBuffer>, uint32_t>> MESH_DATA) noexcept;
void Begin (uint32_t frameIndex) noexcept;
void End (uint32_t frameIndex) noexcept;
void FinaliseBatch (uint32_t frameIndex, Handle<SHVkDescriptorPool> descPool);

View File

@ -474,7 +474,7 @@ namespace SHADE
*/
/***************************************************************************/
Handle<SHRenderGraphNode> const& SHSubpass::GetParentNode(void) const noexcept
Handle<SHRenderGraphNode> SHSubpass::GetParentNode(void) const noexcept
{
return parentNode;
}

View File

@ -159,7 +159,7 @@ namespace SHADE
/*-----------------------------------------------------------------------*/
void SetCompanionSubpass (Handle<SHSubpass> companion, Handle<SHVkPipeline> pipeline) noexcept;
Handle<SHRenderGraphNode> const& GetParentNode(void) const noexcept;
Handle<SHRenderGraphNode> GetParentNode(void) const noexcept;
SHSubPassIndex GetIndex() const noexcept;
Handle<SHSuperBatch> GetSuperBatch(void) const noexcept;
std::vector<vk::AttachmentReference> const& GetColorAttachmentReferences (void) const noexcept;

View File

@ -280,14 +280,8 @@ namespace SHADE
return {};
}
// Grab subpass from worldRenderer
auto renderPass = gfxSystem->GetPrimaryRenderpass();
if (!renderPass)
{
SHLOG_ERROR("[SHResourceManager] Failed to load material as RenderPass could not be found.");
return {};
}
auto subPass = renderPass->GetSubpass(assetData.subpassName);
// Grab subpass
auto subPass = gfxSystem->GetUsableSubpass(assetData.subpassName);
if (!subPass)
{
SHLOG_ERROR("[SHResourceManager] Failed to load material as SubPass could not be found.");

View File

@ -182,7 +182,7 @@ namespace SHADE
mousePos.x = x;
mousePos.y = y;
auto ws = SHSystemManager::GetSystem<SHGraphicsSystem>()->GetWindow()->GetWindowSize();
windowSize = { ws.first,ws.second };
windowSize = { static_cast<float>(ws.first), static_cast<float>(ws.second) };
mousePos /= windowSize;
#endif
@ -300,7 +300,7 @@ namespace SHADE
mousePos.x = x;
mousePos.y = y;
auto ws = SHSystemManager::GetSystem<SHGraphicsSystem>()->GetWindow()->GetWindowSize();
windowSize = { ws.first,ws.second };
windowSize = { static_cast<float>(ws.first), static_cast<float>(ws.second) };
mousePos /= windowSize;
#endif