From 26591e8c245dd8bbd74471d6ca8d9f028fb6a2cd Mon Sep 17 00:00:00 2001 From: Sri Sham Haran Date: Tue, 1 Nov 2022 19:03:08 +0800 Subject: [PATCH 1/7] material inspector --- .../MaterialInspector/SHMaterialInspector.cpp | 81 +++++++++++++++++++ .../MaterialInspector/SHMaterialInspector.h | 28 +++++++ 2 files changed, 109 insertions(+) create mode 100644 SHADE_Engine/src/Editor/EditorWindow/MaterialInspector/SHMaterialInspector.cpp create mode 100644 SHADE_Engine/src/Editor/EditorWindow/MaterialInspector/SHMaterialInspector.h diff --git a/SHADE_Engine/src/Editor/EditorWindow/MaterialInspector/SHMaterialInspector.cpp b/SHADE_Engine/src/Editor/EditorWindow/MaterialInspector/SHMaterialInspector.cpp new file mode 100644 index 00000000..c4904533 --- /dev/null +++ b/SHADE_Engine/src/Editor/EditorWindow/MaterialInspector/SHMaterialInspector.cpp @@ -0,0 +1,81 @@ +#include "SHpch.h" +#include "SHMaterialInspector.h" +#include "Editor/SHImGuiHelpers.hpp" +#include + +//#include "Assets/SHAssetManager.h" +//#include "Graphics/MiddleEnd/Materials/SHMaterialSpec.h" +//#include "Editor/SHEditorWidgets.hpp" +//#include "Resource/SHResourceManager.h" + +namespace SHADE +{ + SHMaterialInspector::SHMaterialInspector() + :SHEditorWindow("Material Inspector", ImGuiWindowFlags_MenuBar)//,isNewMaterial(false), currentViewedMaterial(0) + { + } + + void SHMaterialInspector::OpenMaterial(AssetID const& assetId) noexcept + { + //Get mat data + //isNewMaterial = false; + } + + void SHMaterialInspector::Init() + { + SHEditorWindow::Init(); + } + + void SHMaterialInspector::Update() + { + SHEditorWindow::Update(); + + //if(Begin()) + //{ + // DrawMenuBar(); + + // if(SHEditorWidgets::DragDropReadOnlyField("Vertex Shader", std::to_string(currentMatSpec.vertexShader), [&](){return currentMatSpec.vertexShader;}, [&](AssetID const& id){currentMatSpec.vertexShader = id;}, SHDragDrop::DRAG_RESOURCE)) + // { + // vertShaderHandle = SHResourceManager::LoadOrGet(currentMatSpec.vertexShader); + // } + // if(SHEditorWidgets::DragDropReadOnlyField("Fragment Shader", std::to_string(currentMatSpec.fragShader), [&](){return currentMatSpec.fragShader;}, [&](AssetID const& id){currentMatSpec.fragShader = id;}, SHDragDrop::DRAG_RESOURCE)) + // { + // fragShaderHandle = SHResourceManager::LoadOrGet(currentMatSpec.fragShader); + // } + + // auto vertInterface = vertShaderHandle->GetReflectedData().GetDescriptorBindingInfo().GetShaderBlockInterface(SHGraphicsConstants::DescriptorSetIndex::PER_INSTANCE, SHGraphicsConstants::DescriptorSetBindings::BATCHED_PER_INST_DATA); + + // int const varCount = static_cast(vertInterface->GetVariableCount()); + // + // for(int i = 0; i < varCount; ++i) + // { + // auto variable = vertInterface->GetVariable(i); + // } + + //} + //ImGui::End(); + } + + void SHMaterialInspector::Exit() + { + SHEditorWindow::Exit(); + } + + void SHMaterialInspector::CreateNewMaterial() + { + //isNewMaterial = true; + ////prompt for a name + //currentViewedMaterial = SHAssetManager::CreateNewAsset(AssetType::MATERIAL, "NewMaterial"); + //currentMatSpec = {}; + //vertShaderHandle = {}; + //fragShaderHandle = {}; + } + + void SHMaterialInspector::DrawMenuBar() + { + if(ImGui::BeginMenuBar()) + { + ImGui::EndMenuBar(); + } + } +} diff --git a/SHADE_Engine/src/Editor/EditorWindow/MaterialInspector/SHMaterialInspector.h b/SHADE_Engine/src/Editor/EditorWindow/MaterialInspector/SHMaterialInspector.h new file mode 100644 index 00000000..7256a0b6 --- /dev/null +++ b/SHADE_Engine/src/Editor/EditorWindow/MaterialInspector/SHMaterialInspector.h @@ -0,0 +1,28 @@ +#pragma once +#include "Assets/SHAssetMacros.h" +#include "Editor/EditorWindow/SHEditorWindow.h" + + +namespace SHADE +{ + class SHMaterialInspector final : public SHEditorWindow + { + public: + SHMaterialInspector(); + ~SHMaterialInspector() = default; + + void Init() override; + void Update() override; + void Exit() override; + + void CreateNewMaterial(); + void OpenMaterial(AssetID const& assetId) noexcept; + private: + void DrawMenuBar(); + + //bool isNewMaterial; + //AssetID currentViewedMaterial; + //SHMaterialSpec currentMatSpec; + //Handle vertShaderHandle, fragShaderHandle; + }; +} -- 2.40.1 From 129f92e4b66f18dbc8e17e92e014ed8bdf5aa1de Mon Sep 17 00:00:00 2001 From: Sri Sham Haran Date: Tue, 1 Nov 2022 21:49:42 +0800 Subject: [PATCH 2/7] mat inspector properties handling (WIP) --- .../MaterialInspector/SHMaterialInspector.cpp | 106 ++++++++++++------ .../MaterialInspector/SHMaterialInspector.h | 12 +- .../MiddleEnd/Materials/SHMaterialSpec.h | 1 + 3 files changed, 80 insertions(+), 39 deletions(-) diff --git a/SHADE_Engine/src/Editor/EditorWindow/MaterialInspector/SHMaterialInspector.cpp b/SHADE_Engine/src/Editor/EditorWindow/MaterialInspector/SHMaterialInspector.cpp index c4904533..775754d7 100644 --- a/SHADE_Engine/src/Editor/EditorWindow/MaterialInspector/SHMaterialInspector.cpp +++ b/SHADE_Engine/src/Editor/EditorWindow/MaterialInspector/SHMaterialInspector.cpp @@ -3,22 +3,22 @@ #include "Editor/SHImGuiHelpers.hpp" #include -//#include "Assets/SHAssetManager.h" -//#include "Graphics/MiddleEnd/Materials/SHMaterialSpec.h" -//#include "Editor/SHEditorWidgets.hpp" -//#include "Resource/SHResourceManager.h" +#include "Assets/SHAssetManager.h" +#include "Graphics/MiddleEnd/Materials/SHMaterialSpec.h" +#include "Editor/SHEditorWidgets.hpp" +#include "Resource/SHResourceManager.h" namespace SHADE { SHMaterialInspector::SHMaterialInspector() - :SHEditorWindow("Material Inspector", ImGuiWindowFlags_MenuBar)//,isNewMaterial(false), currentViewedMaterial(0) + :SHEditorWindow("Material Inspector", ImGuiWindowFlags_MenuBar), isNewMaterial(false), currentViewedMaterial(0) { } void SHMaterialInspector::OpenMaterial(AssetID const& assetId) noexcept { //Get mat data - //isNewMaterial = false; + isNewMaterial = false; } void SHMaterialInspector::Init() @@ -30,30 +30,20 @@ namespace SHADE { SHEditorWindow::Update(); - //if(Begin()) - //{ - // DrawMenuBar(); + if(Begin()) + { + DrawMenuBar(); - // if(SHEditorWidgets::DragDropReadOnlyField("Vertex Shader", std::to_string(currentMatSpec.vertexShader), [&](){return currentMatSpec.vertexShader;}, [&](AssetID const& id){currentMatSpec.vertexShader = id;}, SHDragDrop::DRAG_RESOURCE)) - // { - // vertShaderHandle = SHResourceManager::LoadOrGet(currentMatSpec.vertexShader); - // } - // if(SHEditorWidgets::DragDropReadOnlyField("Fragment Shader", std::to_string(currentMatSpec.fragShader), [&](){return currentMatSpec.fragShader;}, [&](AssetID const& id){currentMatSpec.fragShader = id;}, SHDragDrop::DRAG_RESOURCE)) - // { - // fragShaderHandle = SHResourceManager::LoadOrGet(currentMatSpec.fragShader); - // } - - // auto vertInterface = vertShaderHandle->GetReflectedData().GetDescriptorBindingInfo().GetShaderBlockInterface(SHGraphicsConstants::DescriptorSetIndex::PER_INSTANCE, SHGraphicsConstants::DescriptorSetBindings::BATCHED_PER_INST_DATA); - - // int const varCount = static_cast(vertInterface->GetVariableCount()); - // - // for(int i = 0; i < varCount; ++i) - // { - // auto variable = vertInterface->GetVariable(i); - // } - - //} - //ImGui::End(); + if(SHEditorWidgets::DragDropReadOnlyField("Vertex Shader", std::to_string(currentMatSpec.vertexShader), [&](){return currentMatSpec.vertexShader;}, [&](AssetID const& id){currentMatSpec.vertexShader = id;}, SHDragDrop::DRAG_RESOURCE)) + { + vertShaderHandle = SHResourceManager::LoadOrGet(currentMatSpec.vertexShader); + } + if(SHEditorWidgets::DragDropReadOnlyField("Fragment Shader", std::to_string(currentMatSpec.fragShader), [&](){return currentMatSpec.fragShader;}, [&](AssetID const& id){currentMatSpec.fragShader = id;}, SHDragDrop::DRAG_RESOURCE)) + { + fragShaderHandle = SHResourceManager::LoadOrGet(currentMatSpec.fragShader); + } + } + ImGui::End(); } void SHMaterialInspector::Exit() @@ -63,12 +53,12 @@ namespace SHADE void SHMaterialInspector::CreateNewMaterial() { - //isNewMaterial = true; - ////prompt for a name - //currentViewedMaterial = SHAssetManager::CreateNewAsset(AssetType::MATERIAL, "NewMaterial"); - //currentMatSpec = {}; - //vertShaderHandle = {}; - //fragShaderHandle = {}; + isNewMaterial = true; + //prompt for a name + currentViewedMaterial = SHAssetManager::CreateNewAsset(AssetType::MATERIAL, "NewMaterial"); + currentMatSpec = {}; + vertShaderHandle = {}; + fragShaderHandle = {}; } void SHMaterialInspector::DrawMenuBar() @@ -78,4 +68,50 @@ namespace SHADE ImGui::EndMenuBar(); } } + + void SHMaterialInspector::DrawShaderProperties(Handle shaderModule) + { + auto interface = shaderModule->GetReflectedData().GetDescriptorBindingInfo().GetShaderBlockInterface(SHGraphicsConstants::DescriptorSetIndex::PER_INSTANCE, SHGraphicsConstants::DescriptorSetBindings::BATCHED_PER_INST_DATA); + + int const varCount = static_cast(interface->GetVariableCount()); + + for(int i = 0; i < varCount; ++i) + { + auto variable = interface->GetVariable(i); + const std::string& VAR_NAME = interface->GetVariableName(i); + switch (variable->type) + { + case SHShaderBlockInterface::Variable::Type::FLOAT: + SHEditorWidgets::DragFloat(VAR_NAME, [&]() + { + if(currentMatSpec.properties[VAR_NAME].IsDefined()) + return currentMatSpec.properties[VAR_NAME].as(); + else + return 0.0f; + }, + [&](float const& value) + { + currentMatSpec.properties[VAR_NAME] = value; + } + ); + break; + case SHShaderBlockInterface::Variable::Type::INT: + + break; + case SHShaderBlockInterface::Variable::Type::VECTOR2: + + break; + case SHShaderBlockInterface::Variable::Type::VECTOR3: + + break; + case SHShaderBlockInterface::Variable::Type::VECTOR4: + + break; + case SHShaderBlockInterface::Variable::Type::OTHER: + default: + continue; + break; + } + } + } } diff --git a/SHADE_Engine/src/Editor/EditorWindow/MaterialInspector/SHMaterialInspector.h b/SHADE_Engine/src/Editor/EditorWindow/MaterialInspector/SHMaterialInspector.h index 7256a0b6..20e165a7 100644 --- a/SHADE_Engine/src/Editor/EditorWindow/MaterialInspector/SHMaterialInspector.h +++ b/SHADE_Engine/src/Editor/EditorWindow/MaterialInspector/SHMaterialInspector.h @@ -1,6 +1,9 @@ #pragma once #include "Assets/SHAssetMacros.h" #include "Editor/EditorWindow/SHEditorWindow.h" +#include "Graphics/MiddleEnd/Materials/SHMaterialSpec.h" +#include "Graphics/Shaders/SHVkShaderModule.h" +#include "Resource/SHHandle.h" namespace SHADE @@ -19,10 +22,11 @@ namespace SHADE void OpenMaterial(AssetID const& assetId) noexcept; private: void DrawMenuBar(); + void DrawShaderProperties(Handle shaderModule); - //bool isNewMaterial; - //AssetID currentViewedMaterial; - //SHMaterialSpec currentMatSpec; - //Handle vertShaderHandle, fragShaderHandle; + bool isNewMaterial; + AssetID currentViewedMaterial; + SHMaterialSpec currentMatSpec; + Handle vertShaderHandle, fragShaderHandle; }; } diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Materials/SHMaterialSpec.h b/SHADE_Engine/src/Graphics/MiddleEnd/Materials/SHMaterialSpec.h index 338c34b2..e41436ce 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Materials/SHMaterialSpec.h +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Materials/SHMaterialSpec.h @@ -16,6 +16,7 @@ of DigiPen Institute of Technology is prohibited. #include // Project Includes #include "Assets/SHAssetMacros.h" +#include namespace SHADE { -- 2.40.1 From d207042fec502fd43567a5f4d2a9fecf64cec185 Mon Sep 17 00:00:00 2001 From: Kah Wei Date: Wed, 2 Nov 2022 16:56:38 +0800 Subject: [PATCH 3/7] Reworked SHMaterialSpec and SHMaterial loading system --- .../MiddleEnd/Materials/SHMaterialSpec.cpp | 74 ++++++ .../MiddleEnd/Materials/SHMaterialSpec.h | 14 ++ SHADE_Engine/src/Resource/SHResourceManager.h | 9 +- .../src/Resource/SHResourceManager.hpp | 70 ++++-- .../Serialization/SHSerializationHelper.hpp | 231 +++++++----------- 5 files changed, 238 insertions(+), 160 deletions(-) create mode 100644 SHADE_Engine/src/Graphics/MiddleEnd/Materials/SHMaterialSpec.cpp diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Materials/SHMaterialSpec.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Materials/SHMaterialSpec.cpp new file mode 100644 index 00000000..0652b2bf --- /dev/null +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Materials/SHMaterialSpec.cpp @@ -0,0 +1,74 @@ +/************************************************************************************//*! +\file SHMaterialSpec.cpp +\author Tng Kah Wei, kahwei.tng, 390009620 +\par email: kahwei.tng\@digipen.edu +\date Nov 2, 2022 +\brief Contains the function definitions of SHMaterialSpec. + +Copyright (C) 2022 DigiPen Institute of Technology. +Reproduction or disclosure of this file or its contents without the prior written consent +of DigiPen Institute of Technology is prohibited. +*//*************************************************************************************/ +#include "SHpch.h" +#include "SHMaterialSpec.h" +#include "Graphics/Shaders/SHVkShaderModule.h" +#include "Resource/SHResourceManager.h" +#include "Graphics/MiddleEnd/Interface/SHMaterial.h" + +namespace SHADE +{ + /*-----------------------------------------------------------------------------------*/ + /* Constructors */ + /*-----------------------------------------------------------------------------------*/ + SHMaterialSpec::SHMaterialSpec(const SHMaterial& material) + { + // Get Shader Handles + const auto& SHADERS = material.GetPipeline()->GetPipelineLayout()->GetShaderModules(); + Handle vShaderMod, fShaderMod; + for (const auto& shader : SHADERS) + { + const auto FLAG_BITS = shader->GetShaderStageFlagBits(); + if (FLAG_BITS & vk::ShaderStageFlagBits::eVertex) + vShaderMod = shader; + else if (FLAG_BITS & vk::ShaderStageFlagBits::eFragment) + fShaderMod = shader; + } + vertexShader = SHResourceManager::GetAssetID(vShaderMod).value_or(0); + fragShader = SHResourceManager::GetAssetID(vShaderMod).value_or(0); + subpassName = material.GetPipeline()->GetPipelineState().GetSubpass()->GetName(); + + // Write Properties + Handle pipelineProperties = material.GetShaderBlockInterface(); + for (int i = 0; i < static_cast(pipelineProperties->GetVariableCount()); ++i) + { + const SHShaderBlockInterface::Variable* VARIABLE = pipelineProperties->GetVariable(i); + if (!VARIABLE) + break; + const std::string& VAR_NAME = pipelineProperties->GetVariableName(i); + YAML::Node propNode; + switch (VARIABLE->type) + { + case SHADE::SHShaderBlockInterface::Variable::Type::FLOAT: + propNode = material.GetProperty(VARIABLE->offset); + break; + case SHADE::SHShaderBlockInterface::Variable::Type::INT: + propNode = material.GetProperty(VARIABLE->offset); + break; + case SHADE::SHShaderBlockInterface::Variable::Type::VECTOR2: + propNode = material.GetProperty(VARIABLE->offset); + break; + case SHADE::SHShaderBlockInterface::Variable::Type::VECTOR3: + propNode = material.GetProperty(VARIABLE->offset); + break; + case SHADE::SHShaderBlockInterface::Variable::Type::VECTOR4: + propNode = material.GetProperty(VARIABLE->offset); + break; + case SHADE::SHShaderBlockInterface::Variable::Type::OTHER: + default: + continue; + break; + } + properties[VAR_NAME.data()] = propNode; + } + } +} \ No newline at end of file diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Materials/SHMaterialSpec.h b/SHADE_Engine/src/Graphics/MiddleEnd/Materials/SHMaterialSpec.h index e41436ce..03928cfa 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Materials/SHMaterialSpec.h +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Materials/SHMaterialSpec.h @@ -20,6 +20,14 @@ of DigiPen Institute of Technology is prohibited. namespace SHADE { + /*-----------------------------------------------------------------------------------*/ + /* Forward Declaration */ + /*-----------------------------------------------------------------------------------*/ + class SHMaterial; + + /*-----------------------------------------------------------------------------------*/ + /* Type Definitions */ + /*-----------------------------------------------------------------------------------*/ /*************************************************************************************/ /*! \brief @@ -33,5 +41,11 @@ namespace SHADE AssetID fragShader; std::string subpassName; YAML::Node properties; + + /*---------------------------------------------------------------------------------*/ + /* Constructors */ + /*---------------------------------------------------------------------------------*/ + SHMaterialSpec() = default; + SHMaterialSpec(const SHMaterial& material); }; } diff --git a/SHADE_Engine/src/Resource/SHResourceManager.h b/SHADE_Engine/src/Resource/SHResourceManager.h index 61689420..bf26c16c 100644 --- a/SHADE_Engine/src/Resource/SHResourceManager.h +++ b/SHADE_Engine/src/Resource/SHResourceManager.h @@ -13,6 +13,8 @@ of DigiPen Institute of Technology is prohibited. // STL Includes #include + +namespace SHADE { class SHMaterial; } // Project Includes #include "SH_API.h" #include "SHResourceLibrary.h" @@ -24,6 +26,7 @@ of DigiPen Institute of Technology is prohibited. #include "Graphics/MiddleEnd/Textures/SHTextureLibrary.h" #include "Graphics/MiddleEnd/Interface/SHMeshLibrary.h" #include "Graphics/MiddleEnd/Interface/SHMaterial.h" +#include "Graphics/MiddleEnd/Materials/SHMaterialSpec.h" #include "Assets/Asset Types/SHMaterialAsset.h" namespace SHADE @@ -50,9 +53,11 @@ namespace SHADE using AssetType = SHShaderAsset; }; template<> + struct SHResourceLoader { using AssetType = SHMaterialAsset; }; + template<> struct SHResourceLoader { - using AssetType = SHMaterialAsset; + using AssetType = SHMaterialSpec; }; @@ -79,6 +84,8 @@ namespace SHADE /// Handle to a loaded runtime asset. template static Handle LoadOrGet(AssetID assetId); + template<> + static inline Handle LoadOrGet(AssetID assetId); /// /// Unloads an existing loaded asset. Attempting to unload an invalid Handle will /// simply do nothing except emit a warning. diff --git a/SHADE_Engine/src/Resource/SHResourceManager.hpp b/SHADE_Engine/src/Resource/SHResourceManager.hpp index 15834cdf..aa0a0af9 100644 --- a/SHADE_Engine/src/Resource/SHResourceManager.hpp +++ b/SHADE_Engine/src/Resource/SHResourceManager.hpp @@ -24,6 +24,7 @@ of DigiPen Institute of Technology is prohibited. #include "Graphics/Shaders/SHVkShaderModule.h" #include "Graphics/Devices/SHVkLogicalDevice.h" #include "Graphics/MiddleEnd/Materials/SHMaterialSpec.h" +#include "Serialization/SHSerializationHelper.hpp" namespace SHADE { @@ -34,7 +35,12 @@ namespace SHADE Handle SHResourceManager::LoadOrGet(AssetID assetId) { // Check if it is an unsupported type - if (!std::is_same_v && !std::is_same_v) + if (!std::is_same_v && + !std::is_same_v && + !std::is_same_v && + !std::is_same_v && + !std::is_same_v + ) { static_assert(true, "Unsupported Resource Type specified for SHResourceManager."); } @@ -54,14 +60,41 @@ namespace SHADE } auto handle = load(assetId, *assetData); - Handle genericHandle = Handle(); + Handle genericHandle = Handle(handle); + typedHandleMap.get().emplace(assetId, genericHandle); + typedAssetIdMap.get().emplace(genericHandle, assetId); + return handle; + } + + template<> + Handle SHResourceManager::LoadOrGet(AssetID assetId) + { + /* Attempt to get existing loaded asset */ + auto [typedHandleMap, typedAssetIdMap] = getAssetHandleMap(); + if (typedHandleMap.get().contains(assetId)) + return Handle(typedHandleMap.get()[assetId]); + + /* Otherwise, we need to load it! */ + // Get system + SHGraphicsSystem* gfxSystem = SHSystemManager::GetSystem(); + if (gfxSystem == nullptr) + throw std::runtime_error("[SHResourceManager] Attempted to load graphics resource without a SHGraphicsSystem installed."); + + // Get SHMaterialSpec + Handle matSpec = LoadOrGet(assetId); + if (!matSpec) + return {}; + + // Create the material + auto handle = load(assetId, *matSpec); + Handle genericHandle = Handle(handle); typedHandleMap.get().emplace(assetId, genericHandle); typedAssetIdMap.get().emplace(genericHandle, assetId); return handle; } template - void SHResourceManager::Unload(Handle assetId) + void SHResourceManager::Unload(Handle asset) { // Check if it is an unsupported type if (!std::is_same_v && !std::is_same_v) @@ -71,14 +104,18 @@ namespace SHADE /* Attempt to get existing loaded asset */ auto [typedHandleMap, typedAssetIdMap] = getAssetHandleMap(); - if (typedHandleMap.get().contains(assetId)) + if (typedHandleMap.get().contains(asset)) { + // Remove from ResourceHub if SHMaterialSpec + if (std::is_same_v) + resourceHub.Free(asset); + // Dispose - Handle handle = typedHandleMap.get()[assetId]; - Handle typedHandle = static_cast>(handle); + Handle handle = typedHandleMap.get()[asset]; + auto typedHandle = static_cast>(handle); typedHandle.Free(); typedAssetIdMap.get().erase(handle); - typedHandleMap.get().erase(assetId); + typedHandleMap.get().erase(asset); } else { @@ -179,15 +216,20 @@ namespace SHADE shader->Reflect(); return shader; } + // Material Spec + else if constexpr (std::is_same_v) + { + // Get the data we need to construct + auto matSpec = resourceHub.Create(); + *matSpec = YAML::Node(assetData.data).as(); + return matSpec; + } // Materials else if constexpr (std::is_same_v) { - // Get the data we need to construct - SHMaterialSpec matSpec = YAML::Node(assetData.data).as(); - // Load shaders - auto vertexShader = SHResourceManager::LoadOrGet(matSpec.vertexShader); - auto fragShader = SHResourceManager::LoadOrGet(matSpec.fragShader); + auto vertexShader = SHResourceManager::LoadOrGet(assetData.vertexShader); + auto fragShader = SHResourceManager::LoadOrGet(assetData.fragShader); // Ensure that both shaders are present if (!(vertexShader && fragShader)) @@ -203,7 +245,7 @@ namespace SHADE SHLOG_ERROR("[SHResourceManager] Failed to load material as RenderPass could not be found."); return {}; } - auto subPass = renderPass->GetSubpass(matSpec.subpassName); + auto subPass = renderPass->GetSubpass(assetData.subpassName); if (!subPass) { SHLOG_ERROR("[SHResourceManager] Failed to load material as SubPass could not be found."); @@ -218,7 +260,7 @@ namespace SHADE for (int i = 0; i < static_cast(pipelineProperties->GetVariableCount()); ++i) { const std::string& PROP_NAME = pipelineProperties->GetVariableName(i); - const auto& PROP_NODE = matSpec.properties; + const auto& PROP_NODE = assetData.properties; if (PROP_NODE) { const std::string& VAR_NAME = pipelineProperties->GetVariableName(i); diff --git a/SHADE_Engine/src/Serialization/SHSerializationHelper.hpp b/SHADE_Engine/src/Serialization/SHSerializationHelper.hpp index 2179d1cf..f2c4572a 100644 --- a/SHADE_Engine/src/Serialization/SHSerializationHelper.hpp +++ b/SHADE_Engine/src/Serialization/SHSerializationHelper.hpp @@ -20,9 +20,9 @@ namespace YAML { - using namespace SHADE; + using namespace SHADE; - template<> + template<> struct convert { static constexpr const char* x = "x"; @@ -172,17 +172,17 @@ namespace YAML switch (colliderType) { case SHCollider::Type::BOX: - { - if(node[HalfExtents].IsDefined()) - rhs.SetBoundingBox(node[HalfExtents].as()); - } - break; + { + if (node[HalfExtents].IsDefined()) + rhs.SetBoundingBox(node[HalfExtents].as()); + } + break; case SHCollider::Type::SPHERE: - { - if(node[Radius].IsDefined()) - rhs.SetBoundingSphere(node[Radius].as()); - } - break; + { + if (node[Radius].IsDefined()) + rhs.SetBoundingSphere(node[Radius].as()); + } + break; case SHCollider::Type::CAPSULE: break; default:; } @@ -194,7 +194,7 @@ namespace YAML rhs.SetDensity(node[Density].as()); if (node[PositionOffset].IsDefined()) rhs.SetPositionOffset(node[PositionOffset].as()); - + return true; } }; @@ -231,7 +231,7 @@ namespace YAML const SHCollider::Type colliderType = enumAlign.name_to_value(colliderNode[convert::Type].as()).convert(&ok); if (!ok) return false; - + switch (colliderType) { case SHCollider::Type::BOX: rhs.AddBoundingBox(); break; @@ -246,143 +246,84 @@ namespace YAML } }; - template<> - struct convert + template<> + struct convert + { + static constexpr std::string_view VERT_SHADER_YAML_TAG = "VertexShader"; + static constexpr std::string_view FRAG_SHADER_YAML_TAG = "FragmentShader"; + static constexpr std::string_view SUBPASS_YAML_TAG = "SubPass"; + static constexpr std::string_view PROPS_YAML_TAG = "Properties"; + + static YAML::Node encode(SHMaterialSpec const& rhs) { - static constexpr std::string_view VERT_SHADER_YAML_TAG = "VertexShader"; - static constexpr std::string_view FRAG_SHADER_YAML_TAG = "FragmentShader"; - static constexpr std::string_view SUBPASS_YAML_TAG = "SubPass"; - static constexpr std::string_view PROPS_YAML_TAG = "Properties"; + YAML::Node node; + node[VERT_SHADER_YAML_TAG.data()] = rhs.vertexShader; + node[FRAG_SHADER_YAML_TAG.data()] = rhs.fragShader; + node[SUBPASS_YAML_TAG.data()] = rhs.subpassName; + node[PROPS_YAML_TAG.data()] = rhs.properties; + return node; + } - static YAML::Node encode(SHMaterial const& rhs) - { - // Write Properties - YAML::Node propertiesNode; - Handle pipelineProperties = rhs.GetShaderBlockInterface(); - for (int i = 0; i < static_cast(pipelineProperties->GetVariableCount()); ++i) - { - const SHShaderBlockInterface::Variable* VARIABLE = pipelineProperties->GetVariable(i); - if (!VARIABLE) - break; - const std::string& VAR_NAME = pipelineProperties->GetVariableName(i); - YAML::Node propNode; - switch (VARIABLE->type) - { - case SHADE::SHShaderBlockInterface::Variable::Type::FLOAT: - propNode = rhs.GetProperty(VARIABLE->offset); - break; - case SHADE::SHShaderBlockInterface::Variable::Type::INT: - propNode = rhs.GetProperty(VARIABLE->offset); - break; - case SHADE::SHShaderBlockInterface::Variable::Type::VECTOR2: - propNode = rhs.GetProperty(VARIABLE->offset); - break; - case SHADE::SHShaderBlockInterface::Variable::Type::VECTOR3: - propNode = rhs.GetProperty(VARIABLE->offset); - break; - case SHADE::SHShaderBlockInterface::Variable::Type::VECTOR4: - propNode = rhs.GetProperty(VARIABLE->offset); - break; - case SHADE::SHShaderBlockInterface::Variable::Type::OTHER: - default: - continue; - break; - } - propertiesNode[VAR_NAME.data()] = propNode; - } - - // Get Shader Handles - const auto& SHADERS = rhs.GetPipeline()->GetPipelineLayout()->GetShaderModules(); - Handle vertexShader, fragShader; - for (const auto& shader : SHADERS) - { - const auto FLAG_BITS = shader->GetShaderStageFlagBits(); - if (FLAG_BITS & vk::ShaderStageFlagBits::eVertex) - vertexShader = shader; - else if (FLAG_BITS & vk::ShaderStageFlagBits::eFragment) - fragShader = shader; - } - - // Write Material - YAML::Node node; - - node[VERT_SHADER_YAML_TAG.data()] = SHResourceManager::GetAssetID(vertexShader).value_or(0); - node[FRAG_SHADER_YAML_TAG.data()] = SHResourceManager::GetAssetID(fragShader).value_or(0); - node[SUBPASS_YAML_TAG.data()] = rhs.GetPipeline()->GetPipelineState().GetSubpass()->GetName(); - node[PROPS_YAML_TAG.data()] = propertiesNode; - - return node; - } - }; - - template<> - struct convert + static bool decode(YAML::Node const& node, SHMaterialSpec& rhs) { - static constexpr std::string_view VERT_SHADER_YAML_TAG = "VertexShader"; - static constexpr std::string_view FRAG_SHADER_YAML_TAG = "FragmentShader"; - static constexpr std::string_view SUBPASS_YAML_TAG = "SubPass"; - static constexpr std::string_view PROPS_YAML_TAG = "Properties"; + // Retrieve Shader Asset IDs + if (!node[VERT_SHADER_YAML_TAG.data()]) + return false; + rhs.vertexShader = node[VERT_SHADER_YAML_TAG.data()].as(); + if (!node[FRAG_SHADER_YAML_TAG.data()]) + return false; + rhs.fragShader = node[FRAG_SHADER_YAML_TAG.data()].as(); - static bool decode(YAML::Node const& node, SHMaterialSpec& rhs) + // Retrieve Subpass + if (!node[SUBPASS_YAML_TAG.data()]) + return false; + rhs.subpassName = node[SUBPASS_YAML_TAG.data()].as(); + + // Retrieve + if (!node[PROPS_YAML_TAG.data()]) + return false; + rhs.properties = node[PROPS_YAML_TAG.data()]; + + return true; + } + }; + + template<> + struct convert + { + static constexpr std::string_view MESH_YAML_TAG = "Mesh"; + static constexpr std::string_view MAT_YAML_TAG = "Material"; + + static YAML::Node encode(SHRenderable const& rhs) + { + YAML::Node node; + node[MESH_YAML_TAG.data()] = SHResourceManager::GetAssetID(rhs.GetMesh()).value_or(0); + node[MAT_YAML_TAG.data()] = SHResourceManager::GetAssetID(rhs.GetMaterial()->GetBaseMaterial()).value_or(0); + return node; + } + static bool decode(YAML::Node const& node, SHRenderable& rhs) + { + if (node[MESH_YAML_TAG.data()].IsDefined()) { - // Retrieve Shader Asset IDs - if (!node[VERT_SHADER_YAML_TAG.data()]) - return false; - rhs.vertexShader = node[VERT_SHADER_YAML_TAG.data()].as(); - if (!node[FRAG_SHADER_YAML_TAG.data()]) - return false; - rhs.fragShader = node[FRAG_SHADER_YAML_TAG.data()].as(); - - // Retrieve Subpass - if (!node[SUBPASS_YAML_TAG.data()]) - return false; - rhs.subpassName = node[SUBPASS_YAML_TAG.data()].as(); - - // Retrieve - if (!node[PROPS_YAML_TAG.data()]) - return false; - rhs.properties = node[PROPS_YAML_TAG.data()]; - - return true; + rhs.SetMesh(SHResourceManager::LoadOrGet(node[MESH_YAML_TAG.data()].as())); } - }; - - template<> - struct convert - { - static constexpr std::string_view MESH_YAML_TAG = "Mesh"; - static constexpr std::string_view MAT_YAML_TAG = "Material"; - - static YAML::Node encode(SHRenderable const& rhs) + if (node[MAT_YAML_TAG.data()].IsDefined()) + { + // Temporarily, use default material + auto gfxSystem = SHSystemManager::GetSystem(); + if (!gfxSystem) + return false; + Handle baseMat = SHResourceManager::LoadOrGet(node[MAT_YAML_TAG.data()].as()); + if (!baseMat) { - YAML::Node node; - node[MESH_YAML_TAG.data()] = SHResourceManager::GetAssetID(rhs.GetMesh()).value_or(0); - node[MAT_YAML_TAG.data()] = SHResourceManager::GetAssetID(rhs.GetMaterial()->GetBaseMaterial()).value_or(0); - return node; + baseMat = gfxSystem->GetDefaultMaterial(); + SHLog::Warning("[SHSerializationHelper] Unable to load specified material. Falling back to default material."); } - static bool decode(YAML::Node const& node, SHRenderable& rhs) - { - if (node[MESH_YAML_TAG.data()].IsDefined()) - { - rhs.SetMesh(SHResourceManager::LoadOrGet(node[MESH_YAML_TAG.data()].as())); - } - if (node[MAT_YAML_TAG.data()].IsDefined()) - { - // Temporarily, use default material - auto gfxSystem = SHSystemManager::GetSystem(); - if (!gfxSystem) - return false; - Handle baseMat = SHResourceManager::LoadOrGet(node[MAT_YAML_TAG.data()].as()); - if (!baseMat) - { - baseMat = gfxSystem->GetDefaultMaterial(); - SHLog::Warning("[SHSerializationHelper] Unable to load specified material. Falling back to default material."); - } - rhs.SetMaterial(gfxSystem->AddOrGetBaseMaterialInstance(baseMat)); - } - return true; - } - }; + rhs.SetMaterial(gfxSystem->AddOrGetBaseMaterialInstance(baseMat)); + } + return true; + } + }; } namespace SHADE @@ -550,7 +491,7 @@ namespace SHADE auto properties = propType.get_properties(); for (auto const& property : properties) { - if(propertyNode[property.get_name().data()].IsDefined()) + if (propertyNode[property.get_name().data()].IsDefined()) InitializeProperty(component, property, propertyNode[property.get_name().data()]); } } @@ -564,7 +505,7 @@ namespace SHADE return; auto rttrType = rttr::type::get(); auto componentNode = componentsNode[rttrType.get_name().data()]; - if(!componentNode.IsDefined()) + if (!componentNode.IsDefined()) return; auto properties = rttrType.get_properties(); for (auto const& prop : properties) -- 2.40.1 From 976c2201459b5815dfbf61d73d03c54ff8d3af6f Mon Sep 17 00:00:00 2001 From: Kah Wei Date: Wed, 2 Nov 2022 17:19:18 +0800 Subject: [PATCH 4/7] Deserialization of SHMaterialSpec will return an empty SHMaterialSpec on failure now instead --- .../Serialization/SHSerializationHelper.hpp | 20 ++++++++----------- 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/SHADE_Engine/src/Serialization/SHSerializationHelper.hpp b/SHADE_Engine/src/Serialization/SHSerializationHelper.hpp index f2c4572a..8f1b972c 100644 --- a/SHADE_Engine/src/Serialization/SHSerializationHelper.hpp +++ b/SHADE_Engine/src/Serialization/SHSerializationHelper.hpp @@ -267,22 +267,18 @@ namespace YAML static bool decode(YAML::Node const& node, SHMaterialSpec& rhs) { // Retrieve Shader Asset IDs - if (!node[VERT_SHADER_YAML_TAG.data()]) - return false; - rhs.vertexShader = node[VERT_SHADER_YAML_TAG.data()].as(); - if (!node[FRAG_SHADER_YAML_TAG.data()]) - return false; - rhs.fragShader = node[FRAG_SHADER_YAML_TAG.data()].as(); + if (node[VERT_SHADER_YAML_TAG.data()]) + rhs.vertexShader = node[VERT_SHADER_YAML_TAG.data()].as(); + if (node[FRAG_SHADER_YAML_TAG.data()]) + rhs.fragShader = node[FRAG_SHADER_YAML_TAG.data()].as(); // Retrieve Subpass - if (!node[SUBPASS_YAML_TAG.data()]) - return false; - rhs.subpassName = node[SUBPASS_YAML_TAG.data()].as(); + if (node[SUBPASS_YAML_TAG.data()]) + rhs.subpassName = node[SUBPASS_YAML_TAG.data()].as(); // Retrieve - if (!node[PROPS_YAML_TAG.data()]) - return false; - rhs.properties = node[PROPS_YAML_TAG.data()]; + if (node[PROPS_YAML_TAG.data()]) + rhs.properties = node[PROPS_YAML_TAG.data()]; return true; } -- 2.40.1 From 4721a133e133b37edc0d2bee64867ab514361a38 Mon Sep 17 00:00:00 2001 From: Kah Wei Date: Wed, 2 Nov 2022 17:43:28 +0800 Subject: [PATCH 5/7] Added a way to retrieve texture handles from texture indices --- .../MiddleEnd/Textures/SHTextureLibrary.h | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Textures/SHTextureLibrary.h b/SHADE_Engine/src/Graphics/MiddleEnd/Textures/SHTextureLibrary.h index 9357b0e0..5b7e4914 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Textures/SHTextureLibrary.h +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Textures/SHTextureLibrary.h @@ -129,6 +129,21 @@ namespace SHADE /* Getter Functions */ /*-----------------------------------------------------------------------------*/ Handle GetTextureDescriptorSetGroup() const noexcept { return texDescriptors; } + /***************************************************************************/ + /*! + * + \brief + Retrieves the texture handle at the specified texture index. + + \param textureId + Index of the texture to look for. + + \returns + Handle to the texture + + */ + /***************************************************************************/ + Handle GetTextureHandle(SHTexture::Index textureId) const { return texOrder[textureId]; }; private: /*-----------------------------------------------------------------------------*/ -- 2.40.1 From c68c5adc0d3753ebbad5e8b35dc0b80ed66dba3e Mon Sep 17 00:00:00 2001 From: Kah Wei Date: Wed, 2 Nov 2022 17:51:07 +0800 Subject: [PATCH 6/7] Added GetTextureHandle() to SHGraphicsSystem --- .../MiddleEnd/Interface/SHGraphicsSystem.cpp | 5 +++++ .../MiddleEnd/Interface/SHGraphicsSystem.h | 15 +++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp index 97380fa3..bccece68 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp @@ -655,6 +655,11 @@ namespace SHADE ); } + Handle SHGraphicsSystem::GetTextureHandle(SHTexture::Index textureId) const + { + return texLibrary.GetTextureHandle(textureId); + } + #pragma endregion ADD_REMOVE #pragma region ROUTINES diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.h b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.h index 3f899446..d5ac64dc 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.h +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.h @@ -262,6 +262,21 @@ namespace SHADE */ /***************************************************************************/ void BuildTextures(); + /***************************************************************************/ + /*! + * + \brief + Retrieves the texture handle at the specified texture index. + + \param textureId + Index of the texture to look for. + + \returns + Handle to the texture + + */ + /***************************************************************************/ + Handle GetTextureHandle(SHTexture::Index textureId) const; void PrepareResize(uint32_t newWidth, uint32_t newHeight) noexcept; void HandleResize(void) noexcept; -- 2.40.1 From e609b5634ad2672cf767c5edbdba713ced8d9ac0 Mon Sep 17 00:00:00 2001 From: Sri Sham Haran Date: Wed, 2 Nov 2022 21:31:27 +0800 Subject: [PATCH 7/7] Material Inspector Can set material --- Assets/Editor/Layouts/Default.ini | 26 +- Assets/Materials/TestMat.shmat | 8 + Assets/Materials/TestMat.shmat.shmeta | 3 + Assets/Shaders/TestCube_FS.glsl | 2 +- Assets/Shaders/TestCube_FS.shshaderb | Bin 2545 -> 2285 bytes SHADE_Engine/src/Assets/SHAssetManager.cpp | 6 + .../AssetBrowser/SHAssetBrowser.cpp | 80 +++++- .../AssetBrowser/SHAssetBrowser.h | 4 +- .../Inspector/SHEditorComponentView.hpp | 14 + .../MaterialInspector/SHMaterialInspector.cpp | 262 ++++++++++++++---- .../MaterialInspector/SHMaterialInspector.h | 9 +- .../Editor/EditorWindow/SHEditorWindow.cpp | 7 +- .../src/Editor/EditorWindow/SHEditorWindow.h | 1 + .../EditorWindow/SHEditorWindowIncludes.h | 13 +- SHADE_Engine/src/Editor/SHEditor.cpp | 2 + SHADE_Engine/src/Editor/SHEditorWidgets.hpp | 3 +- .../MiddleEnd/Materials/SHMaterialSpec.cpp | 2 +- .../MiddleEnd/Materials/SHMaterialSpec.h | 2 +- .../src/Graphics/RenderGraph/SHSubpass.cpp | 3 +- .../BlockInterface/SHShaderBlockInterface.cpp | 24 +- .../BlockInterface/SHShaderBlockInterface.h | 9 +- .../src/Resource/SHResourceManager.hpp | 26 +- .../Serialization/SHSerializationHelper.hpp | 8 +- 23 files changed, 380 insertions(+), 134 deletions(-) create mode 100644 Assets/Materials/TestMat.shmat create mode 100644 Assets/Materials/TestMat.shmat.shmeta diff --git a/Assets/Editor/Layouts/Default.ini b/Assets/Editor/Layouts/Default.ini index d7a7bf69..1099b5ac 100644 --- a/Assets/Editor/Layouts/Default.ini +++ b/Assets/Editor/Layouts/Default.ini @@ -1,16 +1,16 @@ [Window][MainStatusBar] -Pos=0,1060 +Pos=0,1007 Size=1920,20 Collapsed=0 [Window][SHEditorMenuBar] Pos=0,48 -Size=1920,1012 +Size=1920,959 Collapsed=0 [Window][Hierarchy Panel] -Pos=0,197 -Size=308,863 +Pos=0,189 +Size=308,818 Collapsed=0 DockId=0x00000004,0 @@ -21,13 +21,13 @@ Collapsed=0 [Window][Inspector] Pos=1528,48 -Size=392,1012 +Size=392,959 Collapsed=0 DockId=0x00000006,0 [Window][Profiler] Pos=0,48 -Size=308,147 +Size=308,139 Collapsed=0 DockId=0x00000003,0 @@ -76,7 +76,7 @@ DockId=0x0000000B,0 [Window][ Viewport] Pos=310,48 -Size=1216,715 +Size=1216,662 Collapsed=0 DockId=0x0000000B,0 @@ -93,13 +93,19 @@ Collapsed=0 DockId=0x0000000A,0 [Window][ Asset Browser] -Pos=310,765 +Pos=310,712 Size=1216,295 Collapsed=0 DockId=0x0000000C,0 +[Window][Material Inspector] +Pos=1528,48 +Size=392,959 +Collapsed=0 +DockId=0x00000006,1 + [Docking][Data] -DockSpace ID=0xC5C9B8AB Window=0xBE4044E9 Pos=8,79 Size=1920,1012 Split=X +DockSpace ID=0xC5C9B8AB Window=0xBE4044E9 Pos=0,71 Size=1920,959 Split=X DockNode ID=0x00000005 Parent=0xC5C9B8AB SizeRef=1526,1036 Split=X DockNode ID=0x00000001 Parent=0x00000005 SizeRef=308,1036 Split=Y Selected=0x1E6EB881 DockNode ID=0x00000003 Parent=0x00000001 SizeRef=225,147 Selected=0x1E6EB881 @@ -111,5 +117,5 @@ DockSpace ID=0xC5C9B8AB Window=0xBE4044E9 Pos=8,79 Size=1920,1012 Spli DockNode ID=0x0000000C Parent=0x00000009 SizeRef=1501,295 Selected=0xB128252A DockNode ID=0x0000000A Parent=0x00000007 SizeRef=1501,310 Selected=0xD446F7B6 DockNode ID=0x00000008 Parent=0x00000002 SizeRef=1501,338 Selected=0xD9F31532 - DockNode ID=0x00000006 Parent=0xC5C9B8AB SizeRef=392,1036 Selected=0xE7039252 + DockNode ID=0x00000006 Parent=0xC5C9B8AB SizeRef=392,1036 Selected=0xD3697FB6 diff --git a/Assets/Materials/TestMat.shmat b/Assets/Materials/TestMat.shmat new file mode 100644 index 00000000..089576f3 --- /dev/null +++ b/Assets/Materials/TestMat.shmat @@ -0,0 +1,8 @@ +- VertexShader: 39210065 + FragmentShader: 46377769 + SubPass: G-Buffer Write + Properties: + data.color: {x: 1, y: 0.200000003, z: 0.100000001, w: 1} + data.textureIndex: 64651793 + data.alpha: 0 + data.beta: {x: 1, y: 1, z: 1} \ No newline at end of file diff --git a/Assets/Materials/TestMat.shmat.shmeta b/Assets/Materials/TestMat.shmat.shmeta new file mode 100644 index 00000000..1612ef22 --- /dev/null +++ b/Assets/Materials/TestMat.shmat.shmeta @@ -0,0 +1,3 @@ +Name: TestMat +ID: 126974645 +Type: 7 diff --git a/Assets/Shaders/TestCube_FS.glsl b/Assets/Shaders/TestCube_FS.glsl index c60da6ce..093cc9c6 100644 --- a/Assets/Shaders/TestCube_FS.glsl +++ b/Assets/Shaders/TestCube_FS.glsl @@ -43,7 +43,7 @@ void main() { position = In.vertPos; normals = In.normal; - albedo = texture(textures[nonuniformEXT(MatProp.data[In2.materialIndex].textureIndex)], In.uv) + MatProp.data[In2.materialIndex].color / MatProp.data[In2.materialIndex].alpha; + albedo = texture(textures[nonuniformEXT(MatProp.data[In2.materialIndex].textureIndex)], In.uv); outEntityID = In2.eid; lightLayerIndices = In2.lightLayerIndex; diff --git a/Assets/Shaders/TestCube_FS.shshaderb b/Assets/Shaders/TestCube_FS.shshaderb index 95b4f62ae89c1bd3dc23f684757a7298c60833a3..fcb72b6e912e98ddd75e1e9eb888bad2282d0f97 100644 GIT binary patch delta 266 zcmew;{8ms*;0Xr<7%(#_vokO-GH@~QGT2QNo6Kqs6t>>Du9-;`#L6!%am_2qEUEN# zVPIuoXRzMv#vIKk2$GTmVn!f#XJ7#eZ(<2%GBpEonSodth^>LbAU;SbNK669w*b;0 zEy(iLo1@t68B6Sdio}6ZraP3JUrrs9F28n~zTZ6?J82$nsVFAPd#=;vt delta 528 zcmZ9I&q_j35Qpd9t6d7pq|#kPf`R+WG&S?zwKhSt(I;qAo7Sf>;rtcnceo=cL7ljKm6E3X9=A&V zjVH5O+zKXb+8+=)f->Zw!IKT{W02mau|_z7eNc{KK38MaKyhEMj{U#hDVlWE(-)d% zliz|0ZiAZZU#(?=U6HH?XHJvud0FgE1(yRT=gDd3*oUB4lT8%4rD;IzqYq^pnN={< gRLdE-fF5Xp^8JG$wtnP?RQ?4>SAOFBA68w3IcNPTo&W#< diff --git a/SHADE_Engine/src/Assets/SHAssetManager.cpp b/SHADE_Engine/src/Assets/SHAssetManager.cpp index 4897fc42..cf58d520 100644 --- a/SHADE_Engine/src/Assets/SHAssetManager.cpp +++ b/SHADE_Engine/src/Assets/SHAssetManager.cpp @@ -157,16 +157,22 @@ namespace SHADE { case AssetType::PREFAB: newPath += PREFAB_FOLDER; + newPath += name; + newPath += PREFAB_EXTENSION; data = new SHPrefabAsset(); break; case AssetType::SCENE: newPath += SCENE_FOLDER; + newPath += name; + newPath += SCENE_EXTENSION; data = new SHSceneAsset(); break; case AssetType::MATERIAL: newPath += MATERIAL_FOLDER; + newPath += name; + newPath += MATERIAL_EXTENSION; data = new SHMaterialAsset(); break; diff --git a/SHADE_Engine/src/Editor/EditorWindow/AssetBrowser/SHAssetBrowser.cpp b/SHADE_Engine/src/Editor/EditorWindow/AssetBrowser/SHAssetBrowser.cpp index 8c71eb8f..a18cd70f 100644 --- a/SHADE_Engine/src/Editor/EditorWindow/AssetBrowser/SHAssetBrowser.cpp +++ b/SHADE_Engine/src/Editor/EditorWindow/AssetBrowser/SHAssetBrowser.cpp @@ -5,15 +5,19 @@ #include "Editor/SHImGuiHelpers.hpp" #include #include +#include #include "Assets/SHAssetManager.h" +#include "ECS_Base/Managers/SHSystemManager.h" #include "Editor/IconsFontAwesome6.h" +#include "Editor/SHEditor.h" #include "Editor/DragDrop/SHDragDrop.hpp" +#include "Editor/EditorWindow/MaterialInspector/SHMaterialInspector.h" namespace SHADE { SHAssetBrowser::SHAssetBrowser() - :SHEditorWindow("\xee\x8b\x87 Asset Browser", ImGuiWindowFlags_MenuBar), rootFolder(SHAssetManager::GetRootFolder()), prevFolder(rootFolder), currentFolder(rootFolder) + :SHEditorWindow("\xee\x8b\x87 Asset Browser", ImGuiWindowFlags_MenuBar), rootFolder(SHAssetManager::GetRootFolder()), prevFolder(rootFolder), currentFolder(rootFolder), assetBeingCreated(std::nullopt) { } @@ -53,14 +57,33 @@ namespace SHADE flags |= ImGuiTreeNodeFlags_Selected; if (folder == rootFolder) flags |= ImGuiTreeNodeFlags_DefaultOpen; - + bool isOpen = ImGui::TreeNodeEx(folder, flags, "%s %s", ICON_MD_FOLDER, folder->name.data()); + ImGuiID folderID = ImGui::GetItemID(); const ImRect nodeRect = ImRect(ImGui::GetItemRectMin(), ImGui::GetItemRectMax()); - if(ImGui::IsItemClicked()) + + if (ImGui::BeginPopupContextItem()) + { + if (ImGui::BeginMenu("Create Asset")) + { + //TODO: Change to rttr type enum align + if (ImGui::Selectable("Material")) + { + assetBeingCreated = { folder, AssetType::MATERIAL, "New Material" }; + ImGui::TreeNodeSetOpen(folderID, true); + isOpen = true; + } + ImGui::EndMenu(); + } + ImGui::EndPopup(); + } + + if (ImGui::IsItemClicked()) { selectedFolders.clear(); selectedFolders.push_back(folder); } + if (isOpen) { const ImColor treeLineColor = ImGui::GetColorU32(ImGuiCol_CheckMark); @@ -86,6 +109,9 @@ namespace SHADE vertLineEnd.y = midPoint; } drawList->AddLine(vertLineStart, vertLineEnd, treeLineColor, 1); + if(assetBeingCreated.has_value() && std::get<0>(assetBeingCreated.value()) == folder) + DrawAssetBeingCreated(); + ImGui::TreePop(); } return nodeRect; @@ -130,7 +156,7 @@ namespace SHADE flags |= ImGuiTreeNodeFlags_Selected; std::string icon{}; - switch(file.assetMeta->type) + switch (file.assetMeta->type) { case AssetType::INVALID: break; case AssetType::SHADER: icon = ICON_FA_FILE_CODE; break; @@ -141,24 +167,64 @@ namespace SHADE case AssetType::PREFAB: icon = ICON_FA_BOX_OPEN; break; case AssetType::MATERIAL: break; case AssetType::MAX_COUNT: break; - default: ; + default:; } ImGui::TreeNodeEx(file.assetMeta, flags, "%s %s", icon.data(), file.assetMeta->name.data()); const ImRect nodeRect = ImRect(ImGui::GetItemRectMin(), ImGui::GetItemRectMax()); - if(SHDragDrop::BeginSource()) + if (SHDragDrop::BeginSource()) { auto id = file.assetMeta->id; ImGui::Text("Moving Asset: %s [%zu]", file.name.data(), file.assetMeta->id); SHDragDrop::SetPayload(SHDragDrop::DRAG_RESOURCE, &id); SHDragDrop::EndSource(); } - if(ImGui::IsItemClicked()) + if (ImGui::IsItemClicked()) { selectedAssets.clear(); selectedAssets.push_back(file.assetMeta->id); } + if (ImGui::IsItemHovered() && ImGui::IsMouseDoubleClicked(ImGuiMouseButton_Left)) + { + switch (file.assetMeta->type) + { + case AssetType::INVALID: break; + case AssetType::SHADER: icon = ICON_FA_FILE_CODE; break; + case AssetType::SHADER_BUILT_IN: icon = ICON_FA_FILE_CODE; break; + case AssetType::TEXTURE: icon = ICON_FA_IMAGES; break; + case AssetType::MESH: icon = ICON_FA_CUBES; break; + case AssetType::SCENE: icon = ICON_MD_IMAGE; break; + case AssetType::PREFAB: icon = ICON_FA_BOX_OPEN; break; + case AssetType::MATERIAL: + if (auto matInspector = SHEditorWindowManager::GetEditorWindow()) + { + matInspector->OpenMaterial(file.assetMeta->id); + } + break; + case AssetType::MAX_COUNT: break; + default:; + } + + } ImGui::TreePop(); return nodeRect; } + + void SHAssetBrowser::DrawAssetBeingCreated() noexcept + { + if (!assetBeingCreated.has_value()) + return; + auto& path = std::get<0>(assetBeingCreated.value()); + auto& type = std::get<1>(assetBeingCreated.value()); + auto& assetName = std::get<2>(assetBeingCreated.value()); + if (ImGui::InputText("##newAssetname", &assetName, ImGuiInputTextFlags_EnterReturnsTrue)) + { + AssetID assetId = SHAssetManager::CreateNewAsset(type, assetName); + if (auto matInspector = SHEditorWindowManager::GetEditorWindow()) + { + matInspector->OpenMaterial(assetId, true); + } + assetBeingCreated.reset(); + } + } } diff --git a/SHADE_Engine/src/Editor/EditorWindow/AssetBrowser/SHAssetBrowser.h b/SHADE_Engine/src/Editor/EditorWindow/AssetBrowser/SHAssetBrowser.h index d56fc029..eec40262 100644 --- a/SHADE_Engine/src/Editor/EditorWindow/AssetBrowser/SHAssetBrowser.h +++ b/SHADE_Engine/src/Editor/EditorWindow/AssetBrowser/SHAssetBrowser.h @@ -10,6 +10,7 @@ namespace SHADE class SHAssetBrowser final : public SHEditorWindow { public: + using AssetEntry = std::tuple; SHAssetBrowser(); void Init(); @@ -21,11 +22,12 @@ namespace SHADE ImRect RecursivelyDrawTree(FolderPointer folder); void DrawCurrentFolder(); ImRect DrawFile(SHFile const& file) noexcept; + void DrawAssetBeingCreated() noexcept; FolderPointer rootFolder, prevFolder, currentFolder; + std::optional assetBeingCreated; std::vector selectedFolders; std::vector selectedAssets; static constexpr float tileWidth = 50.0f; - }; } diff --git a/SHADE_Engine/src/Editor/EditorWindow/Inspector/SHEditorComponentView.hpp b/SHADE_Engine/src/Editor/EditorWindow/Inspector/SHEditorComponentView.hpp index e3f93713..5b16a47d 100644 --- a/SHADE_Engine/src/Editor/EditorWindow/Inspector/SHEditorComponentView.hpp +++ b/SHADE_Engine/src/Editor/EditorWindow/Inspector/SHEditorComponentView.hpp @@ -349,6 +349,7 @@ namespace SHADE { DrawContextMenu(component); Handle const& mesh = component->GetMesh(); + Handle const& mat = component->GetMaterial(); SHEditorWidgets::DragDropReadOnlyField("Mesh", std::to_string(SHResourceManager::GetAssetID(mesh).value_or(0)).data(), [component]() { @@ -359,6 +360,19 @@ namespace SHADE { component->SetMesh(SHResourceManager::LoadOrGet(id)); }, SHDragDrop::DRAG_RESOURCE); + + SHEditorWidgets::DragDropReadOnlyField("Material", mat ? std::to_string(SHResourceManager::GetAssetID(mat->GetBaseMaterial()).value_or(0)).data() : "", [component]() + { + Handle const& mat = component->GetMaterial(); + if(!mat) + return static_cast(0); + return SHResourceManager::GetAssetID(mat->GetBaseMaterial()).value_or(0); + }, + [component](AssetID const& id) + { + auto gfxSystem = SHSystemManager::GetSystem(); + component->SetMaterial(gfxSystem->AddOrGetBaseMaterialInstance(SHResourceManager::LoadOrGet(id))); + }, SHDragDrop::DRAG_RESOURCE); } else { diff --git a/SHADE_Engine/src/Editor/EditorWindow/MaterialInspector/SHMaterialInspector.cpp b/SHADE_Engine/src/Editor/EditorWindow/MaterialInspector/SHMaterialInspector.cpp index 775754d7..3eb8564f 100644 --- a/SHADE_Engine/src/Editor/EditorWindow/MaterialInspector/SHMaterialInspector.cpp +++ b/SHADE_Engine/src/Editor/EditorWindow/MaterialInspector/SHMaterialInspector.cpp @@ -1,9 +1,11 @@ #include "SHpch.h" +#include "Serialization/SHSerializationHelper.hpp" #include "SHMaterialInspector.h" #include "Editor/SHImGuiHelpers.hpp" #include #include "Assets/SHAssetManager.h" +#include "Editor/IconsMaterialDesign.h" #include "Graphics/MiddleEnd/Materials/SHMaterialSpec.h" #include "Editor/SHEditorWidgets.hpp" #include "Resource/SHResourceManager.h" @@ -11,14 +13,24 @@ namespace SHADE { SHMaterialInspector::SHMaterialInspector() - :SHEditorWindow("Material Inspector", ImGuiWindowFlags_MenuBar), isNewMaterial(false), currentViewedMaterial(0) + :SHEditorWindow("Material Inspector", ImGuiWindowFlags_MenuBar), isDirty(false), isNewMaterial(false), currentViewedMaterial(0) { } - void SHMaterialInspector::OpenMaterial(AssetID const& assetId) noexcept + void SHMaterialInspector::OpenMaterial(AssetID const& assetId, bool isNew) noexcept { //Get mat data - isNewMaterial = false; + if(isDirty) + return; + isDirty = isNew; + isOpen = true; + SetFocusToWindow(); + currentViewedMaterial = assetId; + + //currentMatSpec = //Get mat spec + + currentMatSpec = SHResourceManager::LoadOrGet(assetId); + currentMaterial = SHResourceManager::LoadOrGet(assetId); } void SHMaterialInspector::Init() @@ -30,18 +42,26 @@ namespace SHADE { SHEditorWindow::Update(); - if(Begin()) + if (Begin()) { - DrawMenuBar(); + if(currentViewedMaterial) + { + DrawMenuBar(); - if(SHEditorWidgets::DragDropReadOnlyField("Vertex Shader", std::to_string(currentMatSpec.vertexShader), [&](){return currentMatSpec.vertexShader;}, [&](AssetID const& id){currentMatSpec.vertexShader = id;}, SHDragDrop::DRAG_RESOURCE)) - { - vertShaderHandle = SHResourceManager::LoadOrGet(currentMatSpec.vertexShader); - } - if(SHEditorWidgets::DragDropReadOnlyField("Fragment Shader", std::to_string(currentMatSpec.fragShader), [&](){return currentMatSpec.fragShader;}, [&](AssetID const& id){currentMatSpec.fragShader = id;}, SHDragDrop::DRAG_RESOURCE)) - { - fragShaderHandle = SHResourceManager::LoadOrGet(currentMatSpec.fragShader); + //if (SHEditorWidgets::DragDropReadOnlyField("Vertex Shader", std::to_string(currentMatSpec->vertexShader), [&]() {return currentMatSpec->vertexShader; }, [&](AssetID const& id) {currentMatSpec->vertexShader = id; }, SHDragDrop::DRAG_RESOURCE)) + //{ + // isDirty = true; + // vertShaderHandle = SHResourceManager::LoadOrGet(currentMatSpec->vertexShader); + //} + //if (SHEditorWidgets::DragDropReadOnlyField("Fragment Shader", std::to_string(currentMatSpec->fragShader), [&]() {return currentMatSpec->fragShader; }, [&](AssetID const& id) {currentMatSpec->fragShader = id; }, SHDragDrop::DRAG_RESOURCE)) + //{ + // isDirty = true; + // fragShaderHandle = SHResourceManager::LoadOrGet(currentMatSpec->fragShader); + //} + + DrawShaderProperties(/*fragShaderHandle*/); } + } ImGui::End(); } @@ -51,67 +71,187 @@ namespace SHADE SHEditorWindow::Exit(); } - void SHMaterialInspector::CreateNewMaterial() - { - isNewMaterial = true; - //prompt for a name - currentViewedMaterial = SHAssetManager::CreateNewAsset(AssetType::MATERIAL, "NewMaterial"); - currentMatSpec = {}; - vertShaderHandle = {}; - fragShaderHandle = {}; - } - void SHMaterialInspector::DrawMenuBar() { - if(ImGui::BeginMenuBar()) + if (ImGui::BeginMenuBar()) { + ImGui::BeginDisabled(!isDirty); + if(ImGui::Button(std::format("{} Save", ICON_MD_SAVE).data())) + { + //save + if(auto matAsset = SHAssetManager::GetData(currentViewedMaterial)) + { + YAML::Emitter out; + out << YAML::BeginSeq; + out << YAML::convert::encode(*currentMatSpec); + out << YAML::EndSeq; + matAsset->data = out.c_str(); + + Handle pipelineProperties = currentMaterial->GetShaderBlockInterface(); + for (int i = 0; i < static_cast(pipelineProperties->GetVariableCount()); ++i) + { + const std::string& PROP_NAME = pipelineProperties->GetVariableName(i); + const YAML::Node& PROP_NODE = currentMatSpec->properties[PROP_NAME.data()]; + if (PROP_NODE.IsDefined()) + { + const std::string& VAR_NAME = pipelineProperties->GetVariableName(i); + const SHShaderBlockInterface::Variable* VARIABLE = pipelineProperties->GetVariable(i); + switch (VARIABLE->type) + { + case SHADE::SHShaderBlockInterface::Variable::Type::FLOAT: + currentMaterial->SetProperty(VARIABLE->offset, PROP_NODE.as()); + break; + case SHADE::SHShaderBlockInterface::Variable::Type::INT: + currentMaterial->SetProperty(VARIABLE->offset, PROP_NODE.as()); + break; + case SHADE::SHShaderBlockInterface::Variable::Type::VECTOR2: + currentMaterial->SetProperty(VARIABLE->offset, PROP_NODE.as()); + break; + case SHADE::SHShaderBlockInterface::Variable::Type::VECTOR3: + currentMaterial->SetProperty(VARIABLE->offset, PROP_NODE.as()); + break; + case SHADE::SHShaderBlockInterface::Variable::Type::VECTOR4: + currentMaterial->SetProperty(VARIABLE->offset, PROP_NODE.as()); + break; + case SHADE::SHShaderBlockInterface::Variable::Type::OTHER: + default: + continue; + break; + } + } + } + + if(SHAssetManager::SaveAsset(currentViewedMaterial)) + { + isDirty = false; + } + } + } + ImGui::EndDisabled(); ImGui::EndMenuBar(); } } - void SHMaterialInspector::DrawShaderProperties(Handle shaderModule) + void SHMaterialInspector::DrawShaderProperties(/*Handle shaderModule*/) { - auto interface = shaderModule->GetReflectedData().GetDescriptorBindingInfo().GetShaderBlockInterface(SHGraphicsConstants::DescriptorSetIndex::PER_INSTANCE, SHGraphicsConstants::DescriptorSetBindings::BATCHED_PER_INST_DATA); + /*if(!shaderModule) + return;*/ + auto gfxSystem = SHSystemManager::GetSystem(); + auto interface = gfxSystem->GetDefaultMaterialInstance()->GetBaseMaterial()->GetShaderBlockInterface(); + //auto interface = shaderModule->GetReflectedData().GetDescriptorBindingInfo().GetShaderBlockInterface(SHGraphicsConstants::DescriptorSetIndex::PER_INSTANCE, SHGraphicsConstants::DescriptorSetBindings::BATCHED_PER_INST_DATA); - int const varCount = static_cast(interface->GetVariableCount()); - - for(int i = 0; i < varCount; ++i) + int const varCount = static_cast(interface->GetVariableCount()); + + for (int i = 0; i < varCount; ++i) + { + auto variable = interface->GetVariable(i); + const std::string& VAR_NAME = interface->GetVariableName(i); + if(VAR_NAME.empty()) + continue; + switch (variable->type) { - auto variable = interface->GetVariable(i); - const std::string& VAR_NAME = interface->GetVariableName(i); - switch (variable->type) + case SHShaderBlockInterface::Variable::Type::FLOAT: + isDirty |= SHEditorWidgets::DragFloat(VAR_NAME, + [&]() + { + if (currentMatSpec->properties[VAR_NAME].IsDefined()) + return currentMatSpec->properties[VAR_NAME].as(); + else + return 0.0f; + }, + [&](float const& value) + { + currentMatSpec->properties[VAR_NAME] = value; + } + ); + break; + case SHShaderBlockInterface::Variable::Type::INT: + isDirty |= SHEditorWidgets::DragInt(VAR_NAME, + [&]() + { + if (currentMatSpec->properties[VAR_NAME].IsDefined()) + return currentMatSpec->properties[VAR_NAME].as(); + else + return 0; + }, + [&](int const& value) + { + currentMatSpec->properties[VAR_NAME] = value; + } + ); + if(SHDragDrop::BeginTarget()) { - case SHShaderBlockInterface::Variable::Type::FLOAT: - SHEditorWidgets::DragFloat(VAR_NAME, [&]() - { - if(currentMatSpec.properties[VAR_NAME].IsDefined()) - return currentMatSpec.properties[VAR_NAME].as(); - else - return 0.0f; - }, - [&](float const& value) - { - currentMatSpec.properties[VAR_NAME] = value; - } - ); - break; - case SHShaderBlockInterface::Variable::Type::INT: - - break; - case SHShaderBlockInterface::Variable::Type::VECTOR2: - - break; - case SHShaderBlockInterface::Variable::Type::VECTOR3: - - break; - case SHShaderBlockInterface::Variable::Type::VECTOR4: - - break; - case SHShaderBlockInterface::Variable::Type::OTHER: - default: - continue; - break; + if(AssetID* payload = SHDragDrop::AcceptPayload(SHDragDrop::DRAG_RESOURCE)) + { + currentMatSpec->properties[VAR_NAME] = *payload; + isDirty = true; + SHDragDrop::EndTarget(); + } } + break; + case SHShaderBlockInterface::Variable::Type::VECTOR2: + isDirty |= SHEditorWidgets::DragVec2(VAR_NAME, { "X", "Y" }, + [&]() + { + if (currentMatSpec->properties[VAR_NAME].IsDefined()) + return currentMatSpec->properties[VAR_NAME].as(); + else + return SHVec2::Zero; + }, + [&](SHVec2 const& value) + { + currentMatSpec->properties[VAR_NAME] = value; + } + ); + break; + case SHShaderBlockInterface::Variable::Type::VECTOR3: + isDirty |= SHEditorWidgets::DragVec3(VAR_NAME, { "X", "Y", "Z" }, + [&]() + { + if (currentMatSpec->properties[VAR_NAME].IsDefined()) + return currentMatSpec->properties[VAR_NAME].as(); + else + return SHVec3::Zero; + }, + [&](SHVec3 const& value) + { + currentMatSpec->properties[VAR_NAME] = value; + } + ); + break; + case SHShaderBlockInterface::Variable::Type::VECTOR4: + isDirty |= SHEditorWidgets::DragVec4(VAR_NAME, { "X", "Y", "Z", "W" }, + [&]() + { + if (currentMatSpec->properties[VAR_NAME].IsDefined()) + return currentMatSpec->properties[VAR_NAME].as(); + else + return SHVec4::Zero; + }, + [&](SHVec4 const& value) + { + currentMatSpec->properties[VAR_NAME] = value; + } + ); + break; + case SHShaderBlockInterface::Variable::Type::OTHER: + isDirty |= SHEditorWidgets::InputText(VAR_NAME, + [&]() + { + if (currentMatSpec->properties[VAR_NAME].IsDefined()) + return currentMatSpec->properties[VAR_NAME].as(); + else + return std::string(); + }, + [&](std::string const& value) + { + currentMatSpec->properties[VAR_NAME] = value; + } + ); + default: + continue; + break; } + } } } diff --git a/SHADE_Engine/src/Editor/EditorWindow/MaterialInspector/SHMaterialInspector.h b/SHADE_Engine/src/Editor/EditorWindow/MaterialInspector/SHMaterialInspector.h index 20e165a7..79885399 100644 --- a/SHADE_Engine/src/Editor/EditorWindow/MaterialInspector/SHMaterialInspector.h +++ b/SHADE_Engine/src/Editor/EditorWindow/MaterialInspector/SHMaterialInspector.h @@ -18,15 +18,16 @@ namespace SHADE void Update() override; void Exit() override; - void CreateNewMaterial(); - void OpenMaterial(AssetID const& assetId) noexcept; + void OpenMaterial(AssetID const& assetId, bool isNew = false) noexcept; private: void DrawMenuBar(); - void DrawShaderProperties(Handle shaderModule); + void DrawShaderProperties(/*Handle shaderModule*/); + bool isDirty; bool isNewMaterial; AssetID currentViewedMaterial; - SHMaterialSpec currentMatSpec; + Handle currentMatSpec; + Handle currentMaterial; Handle vertShaderHandle, fragShaderHandle; }; } diff --git a/SHADE_Engine/src/Editor/EditorWindow/SHEditorWindow.cpp b/SHADE_Engine/src/Editor/EditorWindow/SHEditorWindow.cpp index b5a691d8..5f00cc37 100644 --- a/SHADE_Engine/src/Editor/EditorWindow/SHEditorWindow.cpp +++ b/SHADE_Engine/src/Editor/EditorWindow/SHEditorWindow.cpp @@ -19,7 +19,7 @@ namespace SHADE //|| Public Member Functions || //#==============================================================# SHEditorWindow::SHEditorWindow(std::string_view const& name, ImGuiWindowFlags const& inFlags) - : windowName(name), windowFlags(inFlags), io(ImGui::GetIO()) + :isOpen(true), isWindowHovered(false), windowName(name), windowFlags(inFlags), io(ImGui::GetIO()) { } @@ -68,5 +68,10 @@ namespace SHADE void SHEditorWindow::OnPosChange() { } + + void SHEditorWindow::SetFocusToWindow() + { + ImGui::SetWindowFocus(windowName.data()); + } }//namespace SHADE diff --git a/SHADE_Engine/src/Editor/EditorWindow/SHEditorWindow.h b/SHADE_Engine/src/Editor/EditorWindow/SHEditorWindow.h index 239d8223..faacd8f2 100644 --- a/SHADE_Engine/src/Editor/EditorWindow/SHEditorWindow.h +++ b/SHADE_Engine/src/Editor/EditorWindow/SHEditorWindow.h @@ -34,6 +34,7 @@ namespace SHADE virtual bool Begin(); virtual void OnResize(); virtual void OnPosChange(); + virtual void SetFocusToWindow(); ImGuiWindowFlags windowFlags = 0; ImGuiIO& io; diff --git a/SHADE_Engine/src/Editor/EditorWindow/SHEditorWindowIncludes.h b/SHADE_Engine/src/Editor/EditorWindow/SHEditorWindowIncludes.h index 5208c6d9..2fcde2b2 100644 --- a/SHADE_Engine/src/Editor/EditorWindow/SHEditorWindowIncludes.h +++ b/SHADE_Engine/src/Editor/EditorWindow/SHEditorWindowIncludes.h @@ -1,7 +1,8 @@ #pragma once -#include "MenuBar/SHEditorMenuBar.h" //Menu Bar -#include "HierarchyPanel/SHHierarchyPanel.h" //Hierarchy Panel -#include "Inspector/SHEditorInspector.h" //Inspector -#include "Profiling/SHEditorProfiler.h" //Profiler -#include "ViewportWindow/SHEditorViewport.h" //Editor Viewport -#include "AssetBrowser/SHAssetBrowser.h" //Asset Browser \ No newline at end of file +#include "MenuBar/SHEditorMenuBar.h" //Menu Bar +#include "HierarchyPanel/SHHierarchyPanel.h" //Hierarchy Panel +#include "Inspector/SHEditorInspector.h" //Inspector +#include "Profiling/SHEditorProfiler.h" //Profiler +#include "ViewportWindow/SHEditorViewport.h" //Editor Viewport +#include "AssetBrowser/SHAssetBrowser.h" //Asset Browser +#include "MaterialInspector/SHMaterialInspector.h" //Material Inspector \ No newline at end of file diff --git a/SHADE_Engine/src/Editor/SHEditor.cpp b/SHADE_Engine/src/Editor/SHEditor.cpp index cf5056a5..8bf4c17b 100644 --- a/SHADE_Engine/src/Editor/SHEditor.cpp +++ b/SHADE_Engine/src/Editor/SHEditor.cpp @@ -93,6 +93,8 @@ namespace SHADE SHEditorWindowManager::CreateEditorWindow(); SHEditorWindowManager::CreateEditorWindow(); SHEditorWindowManager::CreateEditorWindow(); + SHEditorWindowManager::CreateEditorWindow(); + SHEditorWindowManager::CreateEditorWindow(); io = &ImGui::GetIO(); diff --git a/SHADE_Engine/src/Editor/SHEditorWidgets.hpp b/SHADE_Engine/src/Editor/SHEditorWidgets.hpp index 053348d7..0855d68d 100644 --- a/SHADE_Engine/src/Editor/SHEditorWidgets.hpp +++ b/SHADE_Engine/src/Editor/SHEditorWidgets.hpp @@ -422,12 +422,13 @@ namespace SHADE ImGui::BeginGroup(); ImGui::PushID(label.data()); TextLabel(label); - bool const changed = ImGui::InputText("##", &text, ImGuiInputTextFlags_ReadOnly, nullptr, nullptr); + bool changed = ImGui::InputText("##", &text, ImGuiInputTextFlags_ReadOnly, nullptr, nullptr); if(SHDragDrop::BeginTarget()) { if(T* payload = SHDragDrop::AcceptPayload(dragDropTag)) { SHCommandManager::PerformCommand(std::reinterpret_pointer_cast(std::make_shared>(get(), *payload, set)), false); + changed = true; SHDragDrop::EndTarget(); } } diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Materials/SHMaterialSpec.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Materials/SHMaterialSpec.cpp index 0652b2bf..0dabc4e8 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Materials/SHMaterialSpec.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Materials/SHMaterialSpec.cpp @@ -34,7 +34,7 @@ namespace SHADE fShaderMod = shader; } vertexShader = SHResourceManager::GetAssetID(vShaderMod).value_or(0); - fragShader = SHResourceManager::GetAssetID(vShaderMod).value_or(0); + fragShader = SHResourceManager::GetAssetID(fShaderMod).value_or(0); subpassName = material.GetPipeline()->GetPipelineState().GetSubpass()->GetName(); // Write Properties diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Materials/SHMaterialSpec.h b/SHADE_Engine/src/Graphics/MiddleEnd/Materials/SHMaterialSpec.h index 03928cfa..9c2177c3 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Materials/SHMaterialSpec.h +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Materials/SHMaterialSpec.h @@ -46,6 +46,6 @@ namespace SHADE /* Constructors */ /*---------------------------------------------------------------------------------*/ SHMaterialSpec() = default; - SHMaterialSpec(const SHMaterial& material); + explicit SHMaterialSpec(const SHMaterial& material); }; } diff --git a/SHADE_Engine/src/Graphics/RenderGraph/SHSubpass.cpp b/SHADE_Engine/src/Graphics/RenderGraph/SHSubpass.cpp index d8f4f8c2..6e78eb9f 100644 --- a/SHADE_Engine/src/Graphics/RenderGraph/SHSubpass.cpp +++ b/SHADE_Engine/src/Graphics/RenderGraph/SHSubpass.cpp @@ -70,7 +70,7 @@ namespace SHADE , inputImageDescriptors{ std::move(rhs.inputImageDescriptors) } , inputDescriptorLayout{ rhs.inputDescriptorLayout } , inputSamplers{ rhs.inputSamplers } - + , name { rhs.name } { } @@ -105,6 +105,7 @@ namespace SHADE inputImageDescriptors = std::move(rhs.inputImageDescriptors); inputDescriptorLayout = rhs.inputDescriptorLayout; inputSamplers = rhs.inputSamplers; + name = std::move(rhs.name); return *this; } diff --git a/SHADE_Engine/src/Graphics/Shaders/BlockInterface/SHShaderBlockInterface.cpp b/SHADE_Engine/src/Graphics/Shaders/BlockInterface/SHShaderBlockInterface.cpp index f214c094..67c83266 100644 --- a/SHADE_Engine/src/Graphics/Shaders/BlockInterface/SHShaderBlockInterface.cpp +++ b/SHADE_Engine/src/Graphics/Shaders/BlockInterface/SHShaderBlockInterface.cpp @@ -54,17 +54,7 @@ namespace SHADE { return variables.size(); } - - SHShaderBlockInterface::SHShaderBlockInterface(void) noexcept - : bytesRequired{ 0 } - {} - - SHShaderBlockInterface::SHShaderBlockInterface(SHShaderBlockInterface&& rhs) noexcept - : variables { std::move(rhs.variables) } - , variableIndexing { std::move(rhs.variableIndexing) } - , bytesRequired { rhs.bytesRequired } - {} - + void SHShaderBlockInterface::SetBytesRequired(uint32_t bytes) noexcept { bytesRequired = bytes; @@ -75,16 +65,4 @@ namespace SHADE { return bytesRequired; } - - SHADE::SHShaderBlockInterface& SHShaderBlockInterface::operator=(SHShaderBlockInterface&& rhs) noexcept - { - if (&rhs == this) - return *this; - - variables = std::move(rhs.variables); - variableIndexing = std::move(rhs.variableIndexing); - bytesRequired = rhs.bytesRequired; - - return *this; - } } \ No newline at end of file diff --git a/SHADE_Engine/src/Graphics/Shaders/BlockInterface/SHShaderBlockInterface.h b/SHADE_Engine/src/Graphics/Shaders/BlockInterface/SHShaderBlockInterface.h index ae75e2c8..8b7ccb97 100644 --- a/SHADE_Engine/src/Graphics/Shaders/BlockInterface/SHShaderBlockInterface.h +++ b/SHADE_Engine/src/Graphics/Shaders/BlockInterface/SHShaderBlockInterface.h @@ -33,7 +33,7 @@ namespace SHADE std::unordered_map variableIndexing; //! bytes required by the block (includes padding). This variable is required - uint32_t bytesRequired; + uint32_t bytesRequired = 0; public: void AddVariable (std::string name, Variable&& newVariable) noexcept; @@ -43,13 +43,6 @@ namespace SHADE const std::string& GetVariableName(uint32_t index) const noexcept; size_t GetVariableCount() const noexcept; - /*-----------------------------------------------------------------------*/ - /* CTORS AND DTORS */ - /*-----------------------------------------------------------------------*/ - SHShaderBlockInterface(void) noexcept; - SHShaderBlockInterface(SHShaderBlockInterface&& rhs) noexcept; - SHShaderBlockInterface& operator=(SHShaderBlockInterface&& rhs) noexcept; - /*-----------------------------------------------------------------------*/ /* SETTERS AND GETTERS */ /*-----------------------------------------------------------------------*/ diff --git a/SHADE_Engine/src/Resource/SHResourceManager.hpp b/SHADE_Engine/src/Resource/SHResourceManager.hpp index aa0a0af9..4f2acd45 100644 --- a/SHADE_Engine/src/Resource/SHResourceManager.hpp +++ b/SHADE_Engine/src/Resource/SHResourceManager.hpp @@ -221,7 +221,14 @@ namespace SHADE { // Get the data we need to construct auto matSpec = resourceHub.Create(); - *matSpec = YAML::Node(assetData.data).as(); + YAML::convert::decode(*YAML::Load(assetData.data).begin(), *matSpec); + // Failed to load + if (matSpec->subpassName == "") + { + // Use default material + *matSpec = SHMaterialSpec(*gfxSystem->GetDefaultMaterial()); + } + return matSpec; } // Materials @@ -260,8 +267,8 @@ namespace SHADE for (int i = 0; i < static_cast(pipelineProperties->GetVariableCount()); ++i) { const std::string& PROP_NAME = pipelineProperties->GetVariableName(i); - const auto& PROP_NODE = assetData.properties; - if (PROP_NODE) + const YAML::Node& PROP_NODE = assetData.properties[PROP_NAME.data()]; + if (PROP_NODE.IsDefined()) { const std::string& VAR_NAME = pipelineProperties->GetVariableName(i); const SHShaderBlockInterface::Variable* VARIABLE = pipelineProperties->GetVariable(i); @@ -271,7 +278,18 @@ namespace SHADE matHandle->SetProperty(VARIABLE->offset, PROP_NODE.as()); break; case SHADE::SHShaderBlockInterface::Variable::Type::INT: - matHandle->SetProperty(VARIABLE->offset, PROP_NODE.as()); + { + Handle texture = LoadOrGet(PROP_NODE.as()); + if (texture) + { + matHandle->SetProperty(VARIABLE->offset, texture->TextureArrayIndex); + } + else + { + SHLOG_WARNING("[] Attempted to load invalid texture! Setting to 0."); + matHandle->SetProperty(VARIABLE->offset, 0); + } + } break; case SHADE::SHShaderBlockInterface::Variable::Type::VECTOR2: matHandle->SetProperty(VARIABLE->offset, PROP_NODE.as()); diff --git a/SHADE_Engine/src/Serialization/SHSerializationHelper.hpp b/SHADE_Engine/src/Serialization/SHSerializationHelper.hpp index 8f1b972c..ed4f118a 100644 --- a/SHADE_Engine/src/Serialization/SHSerializationHelper.hpp +++ b/SHADE_Engine/src/Serialization/SHSerializationHelper.hpp @@ -267,17 +267,17 @@ namespace YAML static bool decode(YAML::Node const& node, SHMaterialSpec& rhs) { // Retrieve Shader Asset IDs - if (node[VERT_SHADER_YAML_TAG.data()]) + if (node[VERT_SHADER_YAML_TAG.data()].IsDefined()) rhs.vertexShader = node[VERT_SHADER_YAML_TAG.data()].as(); - if (node[FRAG_SHADER_YAML_TAG.data()]) + if (node[FRAG_SHADER_YAML_TAG.data()].IsDefined()) rhs.fragShader = node[FRAG_SHADER_YAML_TAG.data()].as(); // Retrieve Subpass - if (node[SUBPASS_YAML_TAG.data()]) + if (node[SUBPASS_YAML_TAG.data()].IsDefined()) rhs.subpassName = node[SUBPASS_YAML_TAG.data()].as(); // Retrieve - if (node[PROPS_YAML_TAG.data()]) + if (node[PROPS_YAML_TAG.data()].IsDefined()) rhs.properties = node[PROPS_YAML_TAG.data()]; return true; -- 2.40.1