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 95b4f62a..fcb72b6e 100644 Binary files a/Assets/Shaders/TestCube_FS.shshaderb and b/Assets/Shaders/TestCube_FS.shshaderb differ 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;