diff --git a/Engine/Source/Editor/UILayers/Inspector.cpp b/Engine/Source/Editor/UILayers/Inspector.cpp index 586245a7..11b4571a 100644 --- a/Engine/Source/Editor/UILayers/Inspector.cpp +++ b/Engine/Source/Editor/UILayers/Inspector.cpp @@ -147,12 +147,23 @@ void UpdateComponentWidget(engine::SceneWorld* pScene // Parameters ImGui::Separator(); - ImGuiUtils::ColorPickerProperty("AlbedoColor", pMaterialComponent->GetAlbedoColor()); - ImGuiUtils::ImGuiFloatProperty("MetallicFactor", pMaterialComponent->GetMetallicFactor(), cd::Unit::None, 0.0f, 1.0f); - ImGuiUtils::ImGuiFloatProperty("RoughnessFactor", pMaterialComponent->GetRoughnessFactor(), cd::Unit::None, 0.0f, 1.0f); - ImGuiUtils::ColorPickerProperty("EmissiveColor", pMaterialComponent->GetEmissiveColor()); - ImGuiUtils::ImGuiBoolProperty("TwoSided", pMaterialComponent->GetTwoSided()); - ImGuiUtils::ImGuiStringProperty("BlendMode", nameof::nameof_enum(pMaterialComponent->GetBlendMode()).data()); + + { + bool isOpen = ImGui::CollapsingHeader("Render States", ImGuiTreeNodeFlags_AllowItemOverlap | ImGuiTreeNodeFlags_DefaultOpen); + ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(2, 2)); + ImGui::Separator(); + + if (isOpen) + { + // TODO : generic cull mode. + ImGuiUtils::ImGuiBoolProperty("TwoSided", pMaterialComponent->GetTwoSided()); + ImGuiUtils::ImGuiStringProperty("BlendMode", nameof::nameof_enum(pMaterialComponent->GetBlendMode()).data()); + } + + ImGui::Separator(); + ImGui::PopStyleVar(); + } + if (cd::BlendMode::Mask == pMaterialComponent->GetBlendMode()) { ImGuiUtils::ImGuiFloatProperty("AlphaCutOff", pMaterialComponent->GetAlphaCutOff(), cd::Unit::None, 0.0f, 1.0f); @@ -161,17 +172,46 @@ void UpdateComponentWidget(engine::SceneWorld* pScene // Textures for (int textureTypeValue = 0; textureTypeValue < static_cast(cd::MaterialTextureType::Count); ++textureTypeValue) { - if (engine::MaterialComponent::TextureInfo* pTextureInfo = pMaterialComponent->GetTextureInfo(static_cast(textureTypeValue))) + auto textureType = static_cast(textureTypeValue); + if (engine::MaterialComponent::TextureInfo* pTextureInfo = pMaterialComponent->GetTextureInfo(textureType)) { - const char* title = nameof::nameof_enum(static_cast(textureTypeValue)).data(); - bool isOpen = ImGui::CollapsingHeader(title, ImGuiTreeNodeFlags_AllowItemOverlap | ImGuiTreeNodeFlags_DefaultOpen); + const char* pTextureType = nameof::nameof_enum(static_cast(textureTypeValue)).data(); + bool isOpen = ImGui::CollapsingHeader(pTextureType, ImGuiTreeNodeFlags_AllowItemOverlap | ImGuiTreeNodeFlags_DefaultOpen); ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(2, 2)); ImGui::Separator(); if (isOpen) { - ImGuiUtils::ImGuiVectorProperty("UVOffset", pTextureInfo->GetUVOffset()); - ImGuiUtils::ImGuiVectorProperty("UVScale", pTextureInfo->GetUVScale()); + if (cd::MaterialTextureType::BaseColor == textureType) + { + ImGuiUtils::ColorPickerProperty("AlbedoColor", pMaterialComponent->GetAlbedoColor()); + } + else if (cd::MaterialTextureType::Metallic == textureType) + { + ImGuiUtils::ImGuiFloatProperty("MetallicFactor", pMaterialComponent->GetMetallicFactor(), cd::Unit::None, 0.0f, 1.0f, false, 0.01f); + } + else if (cd::MaterialTextureType::Roughness == textureType) + { + ImGuiUtils::ImGuiFloatProperty("RoughnessFactor", pMaterialComponent->GetRoughnessFactor(), cd::Unit::None, 0.0f, 1.0f, false, 0.01f); + } + else if (cd::MaterialTextureType::Emissive == textureType) + { + float emissiveLength = pMaterialComponent->GetEmissiveColor().x(); + if (ImGuiUtils::ImGuiFloatProperty("EmissiveLength", emissiveLength, cd::Unit::None, 0.0f, 1.0f, false, 0.01f)) + { + pMaterialComponent->SetEmissiveColor(cd::Vec3f(emissiveLength)); + } + } + + if (pTextureInfo->textureHandle != bgfx::kInvalidHandle) + { + ImGui::Image(reinterpret_cast(pTextureInfo->textureHandle), ImVec2(64, 64)); + } + + ImGui::PushID(textureTypeValue); + ImGuiUtils::ImGuiVectorProperty("UV Offset", pTextureInfo->GetUVOffset(), cd::Unit::None, cd::Vec2f(0.0f), cd::Vec2f(1.0f), false, 0.01f); + ImGuiUtils::ImGuiVectorProperty("UV Scale", pTextureInfo->GetUVScale()); + ImGui::PopID(); } ImGui::Separator(); @@ -180,38 +220,39 @@ void UpdateComponentWidget(engine::SceneWorld* pScene } // Shaders - const char* title = "Shader"; - bool isOpen = ImGui::CollapsingHeader(title, ImGuiTreeNodeFlags_AllowItemOverlap | ImGuiTreeNodeFlags_DefaultOpen); - ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(2, 2)); - ImGui::Separator(); - - if (isOpen) { - ImGuiUtils::ImGuiStringProperty("Vertex Shader", pMaterialComponent->GetVertexShaderName()); - ImGuiUtils::ImGuiStringProperty("Fragment Shader", pMaterialComponent->GetFragmentShaderName()); + bool isOpen = ImGui::CollapsingHeader("Shader", ImGuiTreeNodeFlags_AllowItemOverlap | ImGuiTreeNodeFlags_DefaultOpen); + ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(2, 2)); ImGui::Separator(); - std::vector activeShaderFeatures; - for (const auto& feature : pMaterialComponent->GetShaderFeatures()) + if (isOpen) { - activeShaderFeatures.emplace_back(nameof::nameof_enum(feature).data()); - } + ImGuiUtils::ImGuiStringProperty("Vertex Shader", pMaterialComponent->GetVertexShaderName()); + ImGuiUtils::ImGuiStringProperty("Fragment Shader", pMaterialComponent->GetFragmentShaderName()); + ImGui::Separator(); - if (!activeShaderFeatures.empty()) - { - if (ImGui::BeginCombo("##combo", "Active shader features")) + std::vector activeShaderFeatures; + for (const auto& feature : pMaterialComponent->GetShaderFeatures()) { - for (size_t index = 0; index < activeShaderFeatures.size(); ++index) + activeShaderFeatures.emplace_back(nameof::nameof_enum(feature).data()); + } + + if (!activeShaderFeatures.empty()) + { + if (ImGui::BeginCombo("##combo", "Active shader features")) { - ImGui::Selectable(activeShaderFeatures[index], false); + for (size_t index = 0; index < activeShaderFeatures.size(); ++index) + { + ImGui::Selectable(activeShaderFeatures[index], false); + } + ImGui::EndCombo(); } - ImGui::EndCombo(); } } - } - ImGui::Separator(); - ImGui::PopStyleVar(); + ImGui::Separator(); + ImGui::PopStyleVar(); + } } ImGui::Separator(); @@ -269,7 +310,7 @@ void UpdateComponentWidget(engine::SceneWorld* pSceneWo ImGuiUtils::ImGuiBoolProperty("Open Blur", pCameraComponent->GetIsBlurEnable()); if (pCameraComponent->GetIsBlurEnable()) { - ImGuiUtils::ImGuiIntProperty("BlurIteration", pCameraComponent->GetBlurTimes(), cd::Unit::None, 0, 20, false, 1.0f); + ImGuiUtils::ImGuiIntProperty("Blur Iteration", pCameraComponent->GetBlurTimes(), cd::Unit::None, 0, 20, false, 1.0f); ImGuiUtils::ImGuiFloatProperty("Blur Size", pCameraComponent->GetBlurSize(), cd::Unit::None, 0.0f, 3.0f); ImGuiUtils::ImGuiIntProperty("Blur Scaling", pCameraComponent->GetBlurScaling(), cd::Unit::None, 1, 4, false, 1.0f); } @@ -571,37 +612,42 @@ void Inspector::Init() void Inspector::Update() { - auto flags = ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoScrollWithMouse; - ImGui::Begin(GetName(), &m_isEnable, flags); - engine::SceneWorld* pSceneWorld = GetSceneWorld(); - engine::Entity selectedEntity = pSceneWorld->GetSelectedEntity(); - if (engine::INVALID_ENTITY == selectedEntity) + if (engine::Entity selectedEntity = pSceneWorld->GetSelectedEntity(); selectedEntity != engine::INVALID_ENTITY) + { + // Entity will be invalid in two cases : 1.Select nothing 2.The selected entity has been deleted + // Here we only want to capture the case 1 not to clear Inspector properties. + // For case 2, it still uses a valid entity to update but nothing updated. + // It is OK if we don't reuse the entity id intermediately. + m_lastSelectedEntity = selectedEntity; + } + + if (m_lastSelectedEntity == engine::INVALID_ENTITY) { - ImGui::End(); return; } + constexpr auto flags = ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoScrollWithMouse; + ImGui::Begin(GetName(), &m_isEnable, flags); ImGui::BeginChild("Inspector"); - details::UpdateComponentWidget(pSceneWorld, selectedEntity); - details::UpdateComponentWidget(pSceneWorld, selectedEntity); - details::UpdateComponentWidget(pSceneWorld, selectedEntity); - details::UpdateComponentWidget(pSceneWorld, selectedEntity); - details::UpdateComponentWidget(pSceneWorld, selectedEntity); - details::UpdateComponentWidget(pSceneWorld, selectedEntity); - details::UpdateComponentWidget(pSceneWorld, selectedEntity); - details::UpdateComponentWidget(pSceneWorld, selectedEntity); - details::UpdateComponentWidget(pSceneWorld, selectedEntity); - details::UpdateComponentWidget(pSceneWorld, selectedEntity); - details::UpdateComponentWidget(pSceneWorld, selectedEntity); + details::UpdateComponentWidget(pSceneWorld, m_lastSelectedEntity); + details::UpdateComponentWidget(pSceneWorld, m_lastSelectedEntity); + details::UpdateComponentWidget(pSceneWorld, m_lastSelectedEntity); + details::UpdateComponentWidget(pSceneWorld, m_lastSelectedEntity); + details::UpdateComponentWidget(pSceneWorld, m_lastSelectedEntity); + details::UpdateComponentWidget(pSceneWorld, m_lastSelectedEntity); + details::UpdateComponentWidget(pSceneWorld, m_lastSelectedEntity); + details::UpdateComponentWidget(pSceneWorld, m_lastSelectedEntity); + details::UpdateComponentWidget(pSceneWorld, m_lastSelectedEntity); + details::UpdateComponentWidget(pSceneWorld, m_lastSelectedEntity); + details::UpdateComponentWidget(pSceneWorld, m_lastSelectedEntity); #ifdef ENABLE_DDGI - details::UpdateComponentWidget(pSceneWorld, selectedEntity); + details::UpdateComponentWidget(pSceneWorld, m_lastSelectedEntity); #endif ImGui::EndChild(); - ImGui::End(); } diff --git a/Engine/Source/Editor/UILayers/Inspector.h b/Engine/Source/Editor/UILayers/Inspector.h index 3a248792..f224dbb0 100644 --- a/Engine/Source/Editor/UILayers/Inspector.h +++ b/Engine/Source/Editor/UILayers/Inspector.h @@ -12,6 +12,9 @@ class Inspector : public engine::ImGuiBaseLayer virtual void Init() override; virtual void Update() override; + +private: + engine::Entity m_lastSelectedEntity = engine::INVALID_ENTITY; }; } \ No newline at end of file diff --git a/Engine/Source/Runtime/ImGui/ImGuiUtils.hpp b/Engine/Source/Runtime/ImGui/ImGuiUtils.hpp index 6004cce0..48734b9c 100644 --- a/Engine/Source/Runtime/ImGui/ImGuiUtils.hpp +++ b/Engine/Source/Runtime/ImGui/ImGuiUtils.hpp @@ -46,9 +46,7 @@ static bool ImGuiIntProperty(const char* pName, int& value, cd::Unit unit = cd:: ImGui::NextColumn(); ImGui::PushItemWidth(-1); - std::string labelName = "##"; - labelName += pName; - if (ImGui::DragInt(labelName.c_str(), &value, speed, minValue, maxValue, "%d")) + if (ImGui::DragInt(pName, &value, speed, minValue, maxValue, "%d")) { dirty = true; } @@ -69,15 +67,12 @@ static bool ImGuiFloatProperty(const char* pName, float& value, cd::Unit unit = ImGui::NextColumn(); ImGui::PushItemWidth(-1); - //std::string labelName = std::format("##{}", pName); - std::string labelName = "##"; - labelName += pName; //std::string metricName = std::format("%.2f{}", cd::GetUnitName(unit)); std::string metricName = "%.2f"; metricName += cd::GetUnitName(unit); float delta = maxValue - minValue; float dragSpeed = (speed <= 0.0) ? (cd::Math::IsEqualToZero(delta) ? 1.0f : delta * 0.05f) : speed; - if (ImGui::DragFloat(labelName.c_str(), &value, dragSpeed, minValue, maxValue, metricName.c_str())) + if (ImGui::DragFloat(pName, &value, dragSpeed, minValue, maxValue, metricName.c_str())) { dirty = true; } @@ -104,9 +99,6 @@ static bool ImGuiVectorProperty(const char* pName, T& value, cd::Unit unit = cd: ImGui::NextColumn(); ImGui::PushItemWidth(-1); - //std::string labelName = std::format("##{}", pName); - std::string labelName = "##"; - labelName += pName; //std::string metricName = std::format("%.2f{}", cd::GetUnitName(unit)); std::string metricName = "%.2f"; metricName += cd::GetUnitName(unit); @@ -114,21 +106,21 @@ static bool ImGuiVectorProperty(const char* pName, T& value, cd::Unit unit = cd: float dragSpeed = (speed <= 0.0) ? (cd::Math::IsEqualToZero(delta) ? 1.0f : delta * 0.05f) : speed; if constexpr (std::is_same()) { - if (ImGui::DragFloat2(labelName.c_str(), value.Begin(), dragSpeed, minValue.x(), maxValue.x(), metricName.c_str())) + if (ImGui::DragFloat2(pName, value.Begin(), dragSpeed, minValue.x(), maxValue.x(), metricName.c_str())) { dirty = true; } } else if constexpr (std::is_same()) { - if (ImGui::DragFloat3(labelName.c_str(), value.Begin(), dragSpeed, minValue.x(), maxValue.x(), metricName.c_str())) + if (ImGui::DragFloat3(pName, value.Begin(), dragSpeed, minValue.x(), maxValue.x(), metricName.c_str())) { dirty = true; } } else if constexpr (std::is_same()) { - if (ImGui::DragFloat4(labelName.c_str(), value.Begin(), dragSpeed, minValue.x(), maxValue.x(), metricName.c_str())) + if (ImGui::DragFloat4(pName, value.Begin(), dragSpeed, minValue.x(), maxValue.x(), metricName.c_str())) { dirty = true; } diff --git a/Engine/Source/ThirdParty/AssetPipeline b/Engine/Source/ThirdParty/AssetPipeline index 1e4b58f9..88373377 160000 --- a/Engine/Source/ThirdParty/AssetPipeline +++ b/Engine/Source/ThirdParty/AssetPipeline @@ -1 +1 @@ -Subproject commit 1e4b58f964f8adeff84038fb4f3be89eb26e6514 +Subproject commit 883733779ad37219e7b246710c33c26fc5d4d71c