Bläddra i källkod

Merge pull request #504 from aws-lumberyard-dev/Atom/santorac/ShaderDetailsTool_Moving

Moved ImGuiMaterialDetails Tool to O3DE
santorac 3 år sedan
förälder
incheckning
6e8cff51c5

+ 1 - 2
Gem/Code/Source/BakedShaderVariantExampleComponent.cpp

@@ -176,14 +176,13 @@ namespace AtomSampleViewer
 
             if (m_material && ImGui::Button("Material Details..."))
             {
-                m_imguiMaterialDetails.SetMaterial(m_material);
                 m_imguiMaterialDetails.OpenDialog();
             }
 
             m_imguiSidebar.End();
         }
 
-        m_imguiMaterialDetails.Tick();
+        m_imguiMaterialDetails.Tick(&m_meshFeatureProcessor->GetDrawPackets(m_meshHandle));
 
         if (materialNeedsUpdate)
         {

+ 2 - 2
Gem/Code/Source/BakedShaderVariantExampleComponent.h

@@ -15,8 +15,8 @@
 #include <CommonSampleComponentBase.h>
 #include <Utils/ImGuiSidebar.h>
 #include <Utils/ImGuiAssetBrowser.h>
-#include <Utils/ImGuiMaterialDetails.h>
 #include <Utils/ImGuiHistogramQueue.h>
+#include <Atom/Utils/ImGuiMaterialDetails.h>
 
 namespace AtomSampleViewer
 {
@@ -52,7 +52,7 @@ namespace AtomSampleViewer
         static constexpr uint32_t FrameTimeLogSize = 50;
         static constexpr uint32_t PassTimeLogSize = 50;
         ImGuiSidebar m_imguiSidebar;
-        ImGuiMaterialDetails m_imguiMaterialDetails;
+        AZ::Render::ImGuiMaterialDetails m_imguiMaterialDetails;
         ImGuiAssetBrowser m_materialBrowser;
         ImGuiHistogramQueue m_imGuiFrameTimer;
         ImGuiHistogramQueue m_imGuiForwardPassTimer;

+ 0 - 1
Gem/Code/Source/DiffuseGIExampleComponent.h

@@ -14,7 +14,6 @@
 #include <AzCore/Component/TickBus.h>
 #include <Utils/Utils.h>
 #include <Utils/ImGuiSidebar.h>
-#include <Utils/ImGuiMaterialDetails.h>
 #include <Utils/ImGuiAssetBrowser.h>
 #include <Atom/RPI.Public/WindowContext.h>
 #include <Atom/Feature/Mesh/MeshFeatureProcessorInterface.h>

+ 1 - 2
Gem/Code/Source/EyeMaterialExampleComponent.cpp

@@ -174,13 +174,12 @@ namespace AtomSampleViewer
 
             if (ScriptableImGui::Button("Material Details..."))
             {
-                m_imguiMaterialDetails.SetMaterial(m_materialInstance);
                 m_imguiMaterialDetails.OpenDialog();
             }
 
             m_imguiSidebar.End();
         }
-        m_imguiMaterialDetails.Tick();
+        m_imguiMaterialDetails.Tick(&GetMeshFeatureProcessor()->GetDrawPackets(m_meshHandle), "Eye Mesh");
     }
     
     void EyeMaterialExampleComponent::DrawSidebarMaterialProperties()

+ 4 - 3
Gem/Code/Source/EyeMaterialExampleComponent.h

@@ -11,9 +11,10 @@
 #include <AzCore/Component/TickBus.h>
 #include <CommonSampleComponentBase.h>
 #include <Utils/Utils.h>
-
 #include <Utils/ImGuiSidebar.h>
-#include <Utils/ImGuiMaterialDetails.h>
+#include <Atom/Utils/ImGuiMaterialDetails.h>
+
+#include <Atom/Utils/ImGuiMaterialDetails.h>
 
 namespace AtomSampleViewer
 {
@@ -101,7 +102,7 @@ namespace AtomSampleViewer
         float m_rotationEuler[3];
 
         ImGuiSidebar m_imguiSidebar;
-        ImGuiMaterialDetails m_imguiMaterialDetails;
+        AZ::Render::ImGuiMaterialDetails m_imguiMaterialDetails;
         
     };
 } // namespace AtomSampleViewer

+ 1 - 1
Gem/Code/Source/MaterialHotReloadTestComponent.cpp

@@ -334,7 +334,7 @@ namespace AtomSampleViewer
 
         if (m_material)
         {
-            const Render::MeshDrawPacketLods& drawPackets = GetMeshFeatureProcessor()->GetDrawPackets(m_meshHandle);
+            const AZ::RPI::MeshDrawPacketLods& drawPackets = GetMeshFeatureProcessor()->GetDrawPackets(m_meshHandle);
             if (!drawPackets.empty())
             {
                 AZ_Assert(drawPackets.size() == 1, "Expected exactly 1 LOD");

+ 1 - 2
Gem/Code/Source/MeshExampleComponent.cpp

@@ -303,14 +303,13 @@ namespace AtomSampleViewer
 
             if (m_materialOverrideInstance && ImGui::Button("Material Details..."))
             {
-                m_imguiMaterialDetails.SetMaterial(m_materialOverrideInstance);
                 m_imguiMaterialDetails.OpenDialog();
             }
 
             m_imguiSidebar.End();
         }
 
-        m_imguiMaterialDetails.Tick();
+        m_imguiMaterialDetails.Tick(&GetMeshFeatureProcessor()->GetDrawPackets(m_meshHandle));
 
         if (modelNeedsUpdate)
         {

+ 2 - 2
Gem/Code/Source/MeshExampleComponent.h

@@ -16,12 +16,12 @@
 
 #include <Utils/Utils.h>
 #include <Utils/ImGuiSidebar.h>
-#include <Utils/ImGuiMaterialDetails.h>
 #include <Utils/ImGuiAssetBrowser.h>
 
 #include <Atom/Bootstrap/DefaultWindowBus.h>
 #include <Atom/Feature/ImGui/ImGuiUtils.h>
 #include <Atom/Feature/SkyBox/SkyBoxFeatureProcessorInterface.h>
+#include <Atom/Utils/ImGuiMaterialDetails.h>
 
 namespace AtomSampleViewer
 {
@@ -117,7 +117,7 @@ namespace AtomSampleViewer
         AZ::Data::Instance<AZ::RPI::Material> m_groundPlaneMaterial;
 
         ImGuiSidebar m_imguiSidebar;
-        ImGuiMaterialDetails m_imguiMaterialDetails;
+        AZ::Render::ImGuiMaterialDetails m_imguiMaterialDetails;
         ImGuiAssetBrowser m_materialBrowser;
         ImGuiAssetBrowser m_modelBrowser;
     };

+ 1 - 0
Gem/Code/Source/SampleComponentManager.h

@@ -23,6 +23,7 @@
 
 #include <Atom/Utils/ImGuiCullingDebug.h>
 #include <Atom/Utils/ImGuiGpuProfiler.h>
+#include <Atom/Utils/ImGuiMaterialDetails.h>
 #include <Atom/Utils/ImGuiPassTree.h>
 #include <Atom/Utils/ImGuiFrameVisualizer.h>
 #include <Atom/Utils/ImGuiTransientAttachmentProfiler.h>

+ 1 - 2
Gem/Code/Source/ShadowExampleComponent.cpp

@@ -479,13 +479,12 @@ namespace AtomSampleViewer
 
             if (ScriptableImGui::Button("Material Details..."))
             {
-                m_imguiMaterialDetails.SetMaterial(m_materialInstance);
                 m_imguiMaterialDetails.OpenDialog();
             }
 
             m_imguiSidebar.End();
         }
-        m_imguiMaterialDetails.Tick();
+        m_imguiMaterialDetails.Tick(&GetMeshFeatureProcessor()->GetDrawPackets(m_bunnyMeshHandle), "Bunny Mesh");
     }
 
     void ShadowExampleComponent::DrawSidebarDirectionalLight()

+ 2 - 5
Gem/Code/Source/ShadowExampleComponent.h

@@ -13,14 +13,11 @@
 #include <Atom/Feature/CoreLights/DirectionalLightFeatureProcessorInterface.h>
 #include <Atom/Feature/CoreLights/ShadowConstants.h>
 #include <Atom/Feature/CoreLights/DiskLightFeatureProcessorInterface.h>
-
 #include <Atom/Feature/CoreLights/PointLightFeatureProcessorInterface.h>
-
-
 #include <AzCore/Component/TickBus.h>
+#include <Atom/Utils/ImGuiMaterialDetails.h>
 
 #include <Utils/ImGuiSidebar.h>
-#include <Utils/ImGuiMaterialDetails.h>
 #include <Utils/Utils.h>
 
 namespace AtomSampleViewer
@@ -175,7 +172,7 @@ namespace AtomSampleViewer
         int m_filteringSampleCountsPositional[PositionalLightCount] = { 32, 32, 32 };
 
         ImGuiSidebar m_imguiSidebar;
-        ImGuiMaterialDetails m_imguiMaterialDetails;
+        AZ::Render::ImGuiMaterialDetails m_imguiMaterialDetails;
 
         // original camera configuration
         float m_originalFarClipDistance = 0.f;

+ 0 - 86
Gem/Code/Source/Utils/ImGuiMaterialDetails.cpp

@@ -1,86 +0,0 @@
-/*
- * Copyright (c) Contributors to the Open 3D Engine Project.
- * For complete copyright and license terms please see the LICENSE at the root of this distribution.
- *
- * SPDX-License-Identifier: Apache-2.0 OR MIT
- *
- */
-
-#include <Utils/ImGuiMaterialDetails.h>
-#include <Utils/ImGuiShaderUtils.h>
-#include <imgui/imgui.h>
-#include <Atom/RPI.Public/Material/Material.h>
-
-
-#include <AzCore/Casting/numeric_cast.h>
-
-namespace AtomSampleViewer
-{
-    void ImGuiMaterialDetails::SetMaterial(AZ::Data::Instance<AZ::RPI::Material> material)
-    {
-        m_material = material;
-    }
-
-    void ImGuiMaterialDetails::OpenDialog()
-    {
-        m_dialogIsOpen = true;
-    }
-
-    void ImGuiMaterialDetails::Tick()
-    {
-        if (m_dialogIsOpen)
-        {
-            if (ImGui::Begin("Material Details", &m_dialogIsOpen, ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoSavedSettings))
-            {
-                if (m_material)
-                {
-                    const ImGuiTreeNodeFlags flagDefaultOpen = ImGuiTreeNodeFlags_OpenOnArrow | ImGuiTreeNodeFlags_OpenOnDoubleClick | ImGuiTreeNodeFlags_DefaultOpen;
-                    if (ImGui::TreeNodeEx("Shaders", flagDefaultOpen))
-                    {
-                        for (size_t i = 0; i < m_material->GetShaderCollection().size(); i++)
-                        {
-                            const AZ::RPI::ShaderCollection::Item& shaderItem = m_material->GetShaderCollection()[i];
-
-                            if (ImGui::TreeNodeEx(AZStd::string::format("Shader[%d] - Enabled=%d - %s", aznumeric_cast<int>(i), shaderItem.IsEnabled(), shaderItem.GetShaderAsset()->GetName().GetCStr()).c_str(), flagDefaultOpen))
-                            {
-                                if (shaderItem.IsEnabled())
-                                {
-                                    AZ::RPI::ShaderVariantId requestedVariantId = shaderItem.GetShaderVariantId();
-                                    AZ::Data::Asset<AZ::RPI::ShaderVariantAsset> selectedVariantAsset =
-                                        shaderItem.GetShaderAsset()->GetVariantAsset(requestedVariantId);
-
-                                    if (!selectedVariantAsset)
-                                    {
-                                        selectedVariantAsset = shaderItem.GetShaderAsset()->GetRootVariantAsset();
-                                    }
-
-                                    if (selectedVariantAsset)
-                                    {
-                                        AZ::RPI::ShaderVariantId selectedVariantId = selectedVariantAsset->GetShaderVariantId();
-
-                                        ImGui::Indent();
-
-                                        ImGuiShaderUtils::DrawShaderVariantTable(
-                                            shaderItem.GetShaderAsset()->GetShaderOptionGroupLayout(), requestedVariantId,
-                                            selectedVariantId);
-
-                                        ImGui::Unindent();
-                                    }
-                                }
-
-                                ImGui::TreePop();
-                            }
-                        }
-
-                        ImGui::TreePop();
-                    }
-                }
-                else
-                {
-                    ImGui::Text("No material selected");
-                }
-            }
-            ImGui::End();
-        }
-    }
-} // namespace AtomSampleViewer

+ 0 - 39
Gem/Code/Source/Utils/ImGuiMaterialDetails.h

@@ -1,39 +0,0 @@
-/*
- * Copyright (c) Contributors to the Open 3D Engine Project.
- * For complete copyright and license terms please see the LICENSE at the root of this distribution.
- *
- * SPDX-License-Identifier: Apache-2.0 OR MIT
- *
- */
-
-#pragma once
-
-struct ImGuiContext;
-
-#include<AtomCore/Instance/Instance.h>
-
-namespace AZ
-{
-    namespace RPI
-    {
-        class Material;
-    }
-}
-
-namespace AtomSampleViewer
-{
-    //! Provides a dialog that shows technical details about individual materials, for example the list of
-    //! shaders, the shader options requested, and which shader variant was selected.
-    class ImGuiMaterialDetails
-    {
-    public:
-        void SetMaterial(AZ::Data::Instance<AZ::RPI::Material> material);
-        void OpenDialog();
-        void Tick();
-
-    private:
-
-        AZ::Data::Instance<AZ::RPI::Material> m_material;
-        bool m_dialogIsOpen = false;
-    };
-} // namespace AtomSampleViewer

+ 0 - 72
Gem/Code/Source/Utils/ImGuiShaderUtils.cpp

@@ -1,72 +0,0 @@
-/*
- * Copyright (c) Contributors to the Open 3D Engine Project.
- * For complete copyright and license terms please see the LICENSE at the root of this distribution.
- *
- * SPDX-License-Identifier: Apache-2.0 OR MIT
- *
- */
-
-#include <Utils/ImGuiShaderUtils.h>
-#include <imgui/imgui.h>
-
-namespace AtomSampleViewer
-{
-    namespace ImGuiShaderUtils
-    {
-        void DrawShaderVariantTable(const AZ::RPI::ShaderOptionGroupLayout* layout, AZ::RPI::ShaderVariantId requestedVariantId, AZ::RPI::ShaderVariantId selectedVariantId)
-        {
-            AZ::RPI::ShaderOptionGroup requestedShaderVariantOptions{layout, requestedVariantId};
-            AZ::RPI::ShaderOptionGroup selectedShaderVariantOptions{layout, selectedVariantId};
-            auto& shaderOptionDescriptors = layout->GetShaderOptions();
-
-            // Note I tried using ImGui columns but they don't work so well, and I already had this manual formatting approach shelved elsewhere
-            // so decided to just stick with this is it seems to be more reliable this way.
-
-            int longestOptionNameLength = 0;
-            for (auto& shaderOption : shaderOptionDescriptors)
-            {
-                longestOptionNameLength = AZStd::GetMax(longestOptionNameLength, aznumeric_cast<int>(shaderOption.GetName().GetStringView().size()));
-            }
-
-            AZStd::string header = AZStd::string::format("%-*s |  Bits | Requested | Selected", longestOptionNameLength, "Option Name");
-            AZStd::string divider(header.size(), '-');
-
-            ImGui::Text("%s", header.c_str());
-            ImGui::Text("%s", divider.c_str());
-
-            for (size_t i = 0; i < shaderOptionDescriptors.size(); ++i)
-            {
-                // TODO Consider giving ShaderOptionDescriptor its index value so we can use for-each.
-                const AZ::RPI::ShaderOptionDescriptor& shaderOptionDesc = shaderOptionDescriptors[i];
-                AZ::RPI::ShaderOptionIndex optionIndex{i};
-
-                const char* optionName = shaderOptionDesc.GetName().GetCStr();
-                AZ::RPI::ShaderOptionValue requestedValue = requestedShaderVariantOptions.GetValue(optionIndex);
-                AZ::RPI::ShaderOptionValue selectedValue = selectedShaderVariantOptions.GetValue(optionIndex);
-
-                AZStd::string optionNameLabel = AZStd::string::format("%-*s", longestOptionNameLength, optionName);
-                AzFramework::StringFunc::Replace(optionNameLabel, ' ', '.');
-
-                if (shaderOptionDesc.GetBitCount() == 1)
-                {
-                    ImGui::Text("%s | %4d  | %9d | %8d",
-                        optionNameLabel.c_str(),
-                        shaderOptionDesc.GetBitOffset(),
-                        requestedValue.GetIndex(),
-                        selectedValue.GetIndex());
-                }
-                else
-                {
-                    ImGui::Text("%s | %2d-%-2d | %9d | %8d",
-                        optionNameLabel.c_str(),
-                        shaderOptionDesc.GetBitOffset(),
-                        shaderOptionDesc.GetBitOffset() + shaderOptionDesc.GetBitCount() - 1,
-                        requestedValue.GetIndex(),
-                        selectedValue.GetIndex());
-                }
-            }
-
-        }
-
-    } // namespace Utils
-} // namespace AtomSampleViewer

+ 0 - 19
Gem/Code/Source/Utils/ImGuiShaderUtils.h

@@ -1,19 +0,0 @@
-/*
- * Copyright (c) Contributors to the Open 3D Engine Project.
- * For complete copyright and license terms please see the LICENSE at the root of this distribution.
- *
- * SPDX-License-Identifier: Apache-2.0 OR MIT
- *
- */
-#pragma once
-
-#include <Atom/RPI.Public/Material/Material.h>
-
-namespace AtomSampleViewer
-{
-    namespace ImGuiShaderUtils
-    {
-        //! Draws an ImGui table that compares the shader options for a shader variant that was requested and the shader variant that was found.
-        void DrawShaderVariantTable(const AZ::RPI::ShaderOptionGroupLayout* layout, AZ::RPI::ShaderVariantId requestedVariantId, AZ::RPI::ShaderVariantId selectedVariantId);
-    } // namespace Utils
-} // namespace AtomSampleViewer

+ 0 - 4
Gem/Code/atomsampleviewergem_private_files.cmake

@@ -186,14 +186,10 @@ set(FILES
     Source/Utils/ImGuiAssetBrowser.h
     Source/Utils/ImGuiHistogramQueue.cpp
     Source/Utils/ImGuiHistogramQueue.h
-    Source/Utils/ImGuiMaterialDetails.cpp
-    Source/Utils/ImGuiMaterialDetails.h
     Source/Utils/ImGuiMessageBox.cpp
     Source/Utils/ImGuiMessageBox.h
     Source/Utils/ImGuiSaveFilePath.cpp
     Source/Utils/ImGuiSaveFilePath.h
-    Source/Utils/ImGuiShaderUtils.cpp
-    Source/Utils/ImGuiShaderUtils.h
     Source/Utils/ImGuiSidebar.cpp
     Source/Utils/ImGuiSidebar.h
     Source/Utils/Utils.cpp