From 3ae4bb22dfd1651edf509190c7db8bc98dbef4fd Mon Sep 17 00:00:00 2001 From: mnaumov Date: Thu, 29 Apr 2021 16:51:32 -0700 Subject: [PATCH 1/2] Adding tone mapping option to Material Editor --- Gems/Atom/Feature/Common/Code/CMakeLists.txt | 2 +- .../MaterialViewportNotificationBus.h | 4 + .../Viewport/MaterialViewportRequestBus.h | 7 ++ .../Viewport/MaterialViewportComponent.cpp | 11 +++ .../Viewport/MaterialViewportComponent.h | 5 ++ .../Viewport/MaterialViewportRenderer.cpp | 12 ++- .../Viewport/MaterialViewportRenderer.h | 7 ++ .../Window/ToolBar/MaterialEditorToolBar.cpp | 74 ++++++++++++++++--- .../Window/ToolBar/MaterialEditorToolBar.h | 7 ++ .../ViewportSettingsInspector.cpp | 16 ++++ .../ViewportSettingsInspector.h | 3 + 11 files changed, 134 insertions(+), 14 deletions(-) diff --git a/Gems/Atom/Feature/Common/Code/CMakeLists.txt b/Gems/Atom/Feature/Common/Code/CMakeLists.txt index 93da352c6e..6f087edefe 100644 --- a/Gems/Atom/Feature/Common/Code/CMakeLists.txt +++ b/Gems/Atom/Feature/Common/Code/CMakeLists.txt @@ -30,7 +30,6 @@ ly_add_target( PUBLIC Include Source - 3rdParty/ACES COMPILE_DEFINITIONS PRIVATE IMGUI_DISABLE_OBSOLETE_FUNCTIONS @@ -58,6 +57,7 @@ ly_add_target( ${pal_source_dir} PUBLIC Include + 3rdParty/ACES COMPILE_DEFINITIONS PRIVATE IMGUI_DISABLE_OBSOLETE_FUNCTIONS diff --git a/Gems/Atom/Tools/MaterialEditor/Code/Include/Atom/Viewport/MaterialViewportNotificationBus.h b/Gems/Atom/Tools/MaterialEditor/Code/Include/Atom/Viewport/MaterialViewportNotificationBus.h index 84406d8402..0727547b13 100644 --- a/Gems/Atom/Tools/MaterialEditor/Code/Include/Atom/Viewport/MaterialViewportNotificationBus.h +++ b/Gems/Atom/Tools/MaterialEditor/Code/Include/Atom/Viewport/MaterialViewportNotificationBus.h @@ -11,6 +11,7 @@ */ #pragma once +#include #include #include #include @@ -66,6 +67,9 @@ namespace MaterialEditor //! Notify when field of view changes virtual void OnFieldOfViewChanged([[maybe_unused]] float fieldOfView) {} + + //! Notify when tone mapping changes + virtual void OnDisplayMapperOperationTypeChanged([[maybe_unused]] AZ::Render::DisplayMapperOperationType operationType) {} }; using MaterialViewportNotificationBus = AZ::EBus; diff --git a/Gems/Atom/Tools/MaterialEditor/Code/Include/Atom/Viewport/MaterialViewportRequestBus.h b/Gems/Atom/Tools/MaterialEditor/Code/Include/Atom/Viewport/MaterialViewportRequestBus.h index ea6be4f21a..0c9b6e945d 100644 --- a/Gems/Atom/Tools/MaterialEditor/Code/Include/Atom/Viewport/MaterialViewportRequestBus.h +++ b/Gems/Atom/Tools/MaterialEditor/Code/Include/Atom/Viewport/MaterialViewportRequestBus.h @@ -11,6 +11,7 @@ */ #pragma once +#include #include #include #include @@ -147,6 +148,12 @@ namespace MaterialEditor //! Get field of view virtual float GetFieldOfView() const = 0; + + //! Set tone mapping type + virtual void SetDisplayMapperOperationType(AZ::Render::DisplayMapperOperationType operationType) = 0; + + //! Get tone mapping type + virtual AZ::Render::DisplayMapperOperationType GetDisplayMapperOperationType() const = 0; }; using MaterialViewportRequestBus = AZ::EBus; diff --git a/Gems/Atom/Tools/MaterialEditor/Code/Source/Viewport/MaterialViewportComponent.cpp b/Gems/Atom/Tools/MaterialEditor/Code/Source/Viewport/MaterialViewportComponent.cpp index d6f2092d27..abaf50804f 100644 --- a/Gems/Atom/Tools/MaterialEditor/Code/Source/Viewport/MaterialViewportComponent.cpp +++ b/Gems/Atom/Tools/MaterialEditor/Code/Source/Viewport/MaterialViewportComponent.cpp @@ -508,6 +508,17 @@ namespace MaterialEditor return m_fieldOfView; } + void MaterialViewportComponent::SetDisplayMapperOperationType(AZ::Render::DisplayMapperOperationType operationType) + { + m_displayMapperOperationType = operationType; + MaterialViewportNotificationBus::Broadcast(&MaterialViewportNotificationBus::Events::OnDisplayMapperOperationTypeChanged, operationType); + } + + AZ::Render::DisplayMapperOperationType MaterialViewportComponent::GetDisplayMapperOperationType() const + { + return m_displayMapperOperationType; + } + void MaterialViewportComponent::OnCatalogLoaded([[maybe_unused]] const char* catalogFile) { AZ::TickBus::QueueFunction([this]() { diff --git a/Gems/Atom/Tools/MaterialEditor/Code/Source/Viewport/MaterialViewportComponent.h b/Gems/Atom/Tools/MaterialEditor/Code/Source/Viewport/MaterialViewportComponent.h index 036974e123..8332cb862c 100644 --- a/Gems/Atom/Tools/MaterialEditor/Code/Source/Viewport/MaterialViewportComponent.h +++ b/Gems/Atom/Tools/MaterialEditor/Code/Source/Viewport/MaterialViewportComponent.h @@ -12,6 +12,8 @@ #pragma once +#include + #include #include @@ -85,6 +87,8 @@ namespace MaterialEditor bool GetAlternateSkyboxEnabled() const override; void SetFieldOfView(float fieldOfView) override; float GetFieldOfView() const override; + void SetDisplayMapperOperationType(AZ::Render::DisplayMapperOperationType operationType) override; + AZ::Render::DisplayMapperOperationType GetDisplayMapperOperationType() const override; //////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////// @@ -111,5 +115,6 @@ namespace MaterialEditor bool m_gridEnabled = true; bool m_alternateSkyboxEnabled = false; float m_fieldOfView = 90.0f; + AZ::Render::DisplayMapperOperationType m_displayMapperOperationType = AZ::Render::DisplayMapperOperationType::Aces; }; } diff --git a/Gems/Atom/Tools/MaterialEditor/Code/Source/Viewport/MaterialViewportRenderer.cpp b/Gems/Atom/Tools/MaterialEditor/Code/Source/Viewport/MaterialViewportRenderer.cpp index e1bfaa3872..70e1f681f2 100644 --- a/Gems/Atom/Tools/MaterialEditor/Code/Source/Viewport/MaterialViewportRenderer.cpp +++ b/Gems/Atom/Tools/MaterialEditor/Code/Source/Viewport/MaterialViewportRenderer.cpp @@ -33,6 +33,7 @@ #include #include #include +#include #include #include @@ -145,9 +146,11 @@ namespace MaterialEditor m_postProcessEntity->Activate(); // Init directional light processor - m_directionalLightFeatureProcessor = m_scene->GetFeatureProcessor(); + // Init display mapper processor + m_displayMapperFeatureProcessor = m_scene->GetFeatureProcessor(); + // Init Skybox m_skyboxFeatureProcessor = m_scene->GetFeatureProcessor(); @@ -414,6 +417,13 @@ namespace MaterialEditor MaterialEditorViewportInputControllerRequestBus::Broadcast(&MaterialEditorViewportInputControllerRequestBus::Handler::SetFieldOfView, fieldOfView); } + void MaterialViewportRenderer::OnDisplayMapperOperationTypeChanged(AZ::Render::DisplayMapperOperationType operationType) + { + AZ::Render::DisplayMapperConfigurationDescriptor desc; + desc.m_operationType = operationType; + m_displayMapperFeatureProcessor->RegisterDisplayMapperConfiguration(desc); + } + void MaterialViewportRenderer::OnAssetReady(AZ::Data::Asset asset) { if (m_modelAssetId == asset.GetId()) diff --git a/Gems/Atom/Tools/MaterialEditor/Code/Source/Viewport/MaterialViewportRenderer.h b/Gems/Atom/Tools/MaterialEditor/Code/Source/Viewport/MaterialViewportRenderer.h index e014d9eada..744a887396 100644 --- a/Gems/Atom/Tools/MaterialEditor/Code/Source/Viewport/MaterialViewportRenderer.h +++ b/Gems/Atom/Tools/MaterialEditor/Code/Source/Viewport/MaterialViewportRenderer.h @@ -27,6 +27,11 @@ namespace AZ { + namespace Render + { + class DisplayMapperFeatureProcessorInterface; + } + class Entity; class Component; @@ -71,6 +76,7 @@ namespace MaterialEditor void OnGridEnabledChanged(bool enable) override; void OnAlternateSkyboxEnabledChanged(bool enable) override; void OnFieldOfViewChanged(float fieldOfView) override; + void OnDisplayMapperOperationTypeChanged(AZ::Render::DisplayMapperOperationType operationType) override; // AZ::Data::AssetBus::Handler interface overrides... void OnAssetReady(AZ::Data::Asset asset) override; @@ -92,6 +98,7 @@ namespace MaterialEditor AZ::RPI::RenderPipelinePtr m_renderPipeline; AZ::RPI::ScenePtr m_scene; AZ::Render::DirectionalLightFeatureProcessorInterface* m_directionalLightFeatureProcessor = nullptr; + AZ::Render::DisplayMapperFeatureProcessorInterface* m_displayMapperFeatureProcessor = nullptr; AZ::Entity* m_cameraEntity = nullptr; AZ::Component* m_cameraComponent = nullptr; diff --git a/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/ToolBar/MaterialEditorToolBar.cpp b/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/ToolBar/MaterialEditorToolBar.cpp index dad4a34b1e..7044f0bb5f 100644 --- a/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/ToolBar/MaterialEditorToolBar.cpp +++ b/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/ToolBar/MaterialEditorToolBar.cpp @@ -38,7 +38,7 @@ namespace MaterialEditor m_toggleGrid->setCheckable(true); connect(m_toggleGrid, &QAction::triggered, [this]() { MaterialViewportRequestBus::Broadcast(&MaterialViewportRequestBus::Events::SetGridEnabled, m_toggleGrid->isChecked()); - }); + }); bool enableGrid = false; MaterialViewportRequestBus::BroadcastResult(enableGrid, &MaterialViewportRequestBus::Events::GetGridEnabled); m_toggleGrid->setChecked(enableGrid); @@ -49,7 +49,7 @@ namespace MaterialEditor connect(m_toggleShadowCatcher, &QAction::triggered, [this]() { MaterialViewportRequestBus::Broadcast( &MaterialViewportRequestBus::Events::SetShadowCatcherEnabled, m_toggleShadowCatcher->isChecked()); - }); + }); bool enableShadowCatcher = false; MaterialViewportRequestBus::BroadcastResult(enableShadowCatcher, &MaterialViewportRequestBus::Events::GetShadowCatcherEnabled); m_toggleShadowCatcher->setChecked(enableShadowCatcher); @@ -58,22 +58,44 @@ namespace MaterialEditor //[GFX TODO][ATOM-3992] QToolButton* toneMappingButton = new QToolButton(this); QMenu* toneMappingMenu = new QMenu(toneMappingButton); - toneMappingMenu->addAction("None", [this]() { - MaterialEditorSettingsRequestBus::Broadcast(&MaterialEditorSettingsRequests::SetStringProperty, "toneMapping", "None"); - }); - toneMappingMenu->addAction("Gamma2.2", [this]() { - MaterialEditorSettingsRequestBus::Broadcast(&MaterialEditorSettingsRequests::SetStringProperty, "toneMapping", "Gamma2.2"); - }); - toneMappingMenu->addAction("ACES", [this]() { - MaterialEditorSettingsRequestBus::Broadcast(&MaterialEditorSettingsRequests::SetStringProperty, "toneMapping", "ACES"); - }); + m_aces = toneMappingMenu->addAction("Aces", [this]() { + MaterialViewportRequestBus::Broadcast( + &MaterialViewportRequestBus::Events::SetDisplayMapperOperationType, + AZ::Render::DisplayMapperOperationType::Aces); + }); + m_aces->setCheckable(true); + m_aces->setChecked(true); + m_acesLut = toneMappingMenu->addAction("AcesLut", [this]() { + MaterialViewportRequestBus::Broadcast( + &MaterialViewportRequestBus::Events::SetDisplayMapperOperationType, + AZ::Render::DisplayMapperOperationType::AcesLut); + }); + m_acesLut->setCheckable(true); + m_passthrough = toneMappingMenu->addAction("Passthrough", [this]() { + MaterialViewportRequestBus::Broadcast( + &MaterialViewportRequestBus::Events::SetDisplayMapperOperationType, + AZ::Render::DisplayMapperOperationType::Passthrough); + }); + m_passthrough->setCheckable(true); + m_gammaSRGB = toneMappingMenu->addAction("GammaSRGB", [this]() { + MaterialViewportRequestBus::Broadcast( + &MaterialViewportRequestBus::Events::SetDisplayMapperOperationType, + AZ::Render::DisplayMapperOperationType::GammaSRGB); + }); + m_gammaSRGB->setCheckable(true); + m_reinhard = toneMappingMenu->addAction("Reinhard", [this]() { + MaterialViewportRequestBus::Broadcast( + &MaterialViewportRequestBus::Events::SetDisplayMapperOperationType, + AZ::Render::DisplayMapperOperationType::Reinhard); + }); + m_reinhard->setCheckable(true); toneMappingButton->setMenu(toneMappingMenu); toneMappingButton->setText("Tone Mapping"); toneMappingButton->setIcon(QIcon(":/Icons/toneMapping.svg")); toneMappingButton->setPopupMode(QToolButton::InstantPopup); // hiding button until DisplayMapper supports changing settings at run time - toneMappingButton->setVisible(false); + toneMappingButton->setVisible(true); addWidget(toneMappingButton); // Add model combo box @@ -99,6 +121,34 @@ namespace MaterialEditor m_toggleGrid->setChecked(enable); } + void MaterialEditorToolBar::OnDisplayMapperOperationTypeChanged(AZ::Render::DisplayMapperOperationType operationType) + { + m_aces->setChecked(false); + m_acesLut->setChecked(false); + m_passthrough->setChecked(false); + m_gammaSRGB->setChecked(false); + m_reinhard->setChecked(false); + + switch (operationType) + { + case AZ::Render::DisplayMapperOperationType::Aces: + m_aces->setChecked(true); + break; + case AZ::Render::DisplayMapperOperationType::AcesLut: + m_acesLut->setChecked(true); + break; + case AZ::Render::DisplayMapperOperationType::Passthrough: + m_passthrough->setChecked(true); + break; + case AZ::Render::DisplayMapperOperationType::GammaSRGB: + m_gammaSRGB->setChecked(true); + break; + case AZ::Render::DisplayMapperOperationType::Reinhard: + m_reinhard->setChecked(true); + break; + } + } + void MaterialEditorToolBar::OnShadowCatcherEnabledChanged(bool enable) { m_toggleShadowCatcher->setChecked(enable); diff --git a/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/ToolBar/MaterialEditorToolBar.h b/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/ToolBar/MaterialEditorToolBar.h index 147608bc23..a711c8d4f8 100644 --- a/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/ToolBar/MaterialEditorToolBar.h +++ b/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/ToolBar/MaterialEditorToolBar.h @@ -33,8 +33,15 @@ namespace MaterialEditor // MaterialViewportNotificationBus::Handler overrides... void OnShadowCatcherEnabledChanged([[maybe_unused]] bool enable) override; void OnGridEnabledChanged([[maybe_unused]] bool enable) override; + void OnDisplayMapperOperationTypeChanged(AZ::Render::DisplayMapperOperationType operationType) override; QAction* m_toggleGrid = {}; QAction* m_toggleShadowCatcher = {}; + + QAction* m_aces = {}; + QAction* m_acesLut = {}; + QAction* m_passthrough = {}; + QAction* m_gammaSRGB = {}; + QAction* m_reinhard = {}; }; } // namespace MaterialEditor diff --git a/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/ViewportSettingsInspector/ViewportSettingsInspector.cpp b/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/ViewportSettingsInspector/ViewportSettingsInspector.cpp index 8efed36197..fd50ace918 100644 --- a/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/ViewportSettingsInspector/ViewportSettingsInspector.cpp +++ b/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/ViewportSettingsInspector/ViewportSettingsInspector.cpp @@ -36,6 +36,7 @@ namespace MaterialEditor ->Field("enableShadowCatcher", &GeneralViewportSettings::m_enableShadowCatcher) ->Field("enableAlternateSkybox", &GeneralViewportSettings::m_enableAlternateSkybox) ->Field("fieldOfView", &GeneralViewportSettings::m_fieldOfView) + ->Field("displayMapperOperationType", &GeneralViewportSettings::m_displayMapperOperationType) ; if (auto editContext = serializeContext->GetEditContext()) @@ -50,6 +51,12 @@ namespace MaterialEditor ->DataElement(AZ::Edit::UIHandlers::Slider, &GeneralViewportSettings::m_fieldOfView, "Field Of View", "") ->Attribute(AZ::Edit::Attributes::Min, 60.0f) ->Attribute(AZ::Edit::Attributes::Max, 120.0f) + ->DataElement(AZ::Edit::UIHandlers::ComboBox, &GeneralViewportSettings::m_displayMapperOperationType, "Display Mapper Type", "") + ->EnumAttribute(AZ::Render::DisplayMapperOperationType::Aces, "Aces") + ->EnumAttribute(AZ::Render::DisplayMapperOperationType::AcesLut, "AcesLut") + ->EnumAttribute(AZ::Render::DisplayMapperOperationType::Passthrough, "Passthrough") + ->EnumAttribute(AZ::Render::DisplayMapperOperationType::GammaSRGB, "GammaSRGB") + ->EnumAttribute(AZ::Render::DisplayMapperOperationType::Reinhard, "Reinhard") ; } } @@ -66,6 +73,7 @@ namespace MaterialEditor ->Property("enableShadowCatcher", BehaviorValueProperty(&GeneralViewportSettings::m_enableShadowCatcher)) ->Property("enableAlternateSkybox", BehaviorValueProperty(&GeneralViewportSettings::m_enableAlternateSkybox)) ->Property("fieldOfView", BehaviorValueProperty(&GeneralViewportSettings::m_fieldOfView)) + ->Property("displayMapperOperationType", BehaviorValueProperty(&GeneralViewportSettings::m_displayMapperOperationType)) ; } } @@ -298,6 +306,7 @@ namespace MaterialEditor MaterialViewportRequestBus::BroadcastResult( m_generalSettings.m_enableAlternateSkybox, &MaterialViewportRequestBus::Events::GetAlternateSkyboxEnabled); MaterialViewportRequestBus::BroadcastResult(m_generalSettings.m_fieldOfView, &MaterialViewportRequestBus::Handler::GetFieldOfView); + MaterialViewportRequestBus::BroadcastResult(m_generalSettings.m_displayMapperOperationType, &MaterialViewportRequestBus::Handler::GetDisplayMapperOperationType); AtomToolsFramework::InspectorRequestBus::Handler::BusDisconnect(); AtomToolsFramework::InspectorWidget::Reset(); @@ -343,6 +352,12 @@ namespace MaterialEditor RefreshGroup("general"); } + void ViewportSettingsInspector::OnDisplayMapperOperationTypeChanged(AZ::Render::DisplayMapperOperationType operationType) + { + m_generalSettings.m_displayMapperOperationType = operationType; + RefreshGroup("general"); + } + void ViewportSettingsInspector::BeforePropertyModified(AzToolsFramework::InstanceDataNode* pNode) { AZ_UNUSED(pNode); @@ -370,6 +385,7 @@ namespace MaterialEditor MaterialViewportRequestBus::Broadcast( &MaterialViewportRequestBus::Events::SetAlternateSkyboxEnabled, m_generalSettings.m_enableAlternateSkybox); MaterialViewportRequestBus::Broadcast(&MaterialViewportRequestBus::Handler::SetFieldOfView, m_generalSettings.m_fieldOfView); + MaterialViewportRequestBus::Broadcast(&MaterialViewportRequestBus::Handler::SetDisplayMapperOperationType, m_generalSettings.m_displayMapperOperationType); } AZStd::string ViewportSettingsInspector::GetDefaultUniqueSaveFilePath(const AZStd::string& baseName) const diff --git a/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/ViewportSettingsInspector/ViewportSettingsInspector.h b/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/ViewportSettingsInspector/ViewportSettingsInspector.h index 08e22a380c..c61acb2e4c 100644 --- a/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/ViewportSettingsInspector/ViewportSettingsInspector.h +++ b/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/ViewportSettingsInspector/ViewportSettingsInspector.h @@ -13,6 +13,7 @@ #pragma once #if !defined(Q_MOC_RUN) +#include #include #include #include @@ -32,6 +33,7 @@ namespace MaterialEditor bool m_enableShadowCatcher = true; bool m_enableAlternateSkybox = false; float m_fieldOfView = 90.0f; + AZ::Render::DisplayMapperOperationType m_displayMapperOperationType = AZ::Render::DisplayMapperOperationType::Aces; }; //! Provides controls for viewing and editing a material document settings. @@ -74,6 +76,7 @@ namespace MaterialEditor void OnGridEnabledChanged(bool enable) override; void OnAlternateSkyboxEnabledChanged(bool enable) override; void OnFieldOfViewChanged(float fieldOfView) override; + void OnDisplayMapperOperationTypeChanged(AZ::Render::DisplayMapperOperationType operationType) override; // AzToolsFramework::IPropertyEditorNotify overrides... void BeforePropertyModified(AzToolsFramework::InstanceDataNode* pNode) override; From 6a0df12de206818a3fed8f76bce3c9ac7eaf2409 Mon Sep 17 00:00:00 2001 From: mnaumov Date: Fri, 30 Apr 2021 12:24:38 -0700 Subject: [PATCH 2/2] PR feedback --- .../Window/ToolBar/MaterialEditorToolBar.cpp | 78 ++++++------------- .../Window/ToolBar/MaterialEditorToolBar.h | 7 +- 2 files changed, 24 insertions(+), 61 deletions(-) diff --git a/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/ToolBar/MaterialEditorToolBar.cpp b/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/ToolBar/MaterialEditorToolBar.cpp index 7044f0bb5f..2af73bf436 100644 --- a/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/ToolBar/MaterialEditorToolBar.cpp +++ b/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/ToolBar/MaterialEditorToolBar.cpp @@ -55,46 +55,32 @@ namespace MaterialEditor m_toggleShadowCatcher->setChecked(enableShadowCatcher); // Add mapping selection button - //[GFX TODO][ATOM-3992] + QToolButton* toneMappingButton = new QToolButton(this); QMenu* toneMappingMenu = new QMenu(toneMappingButton); - m_aces = toneMappingMenu->addAction("Aces", [this]() { - MaterialViewportRequestBus::Broadcast( - &MaterialViewportRequestBus::Events::SetDisplayMapperOperationType, - AZ::Render::DisplayMapperOperationType::Aces); - }); - m_aces->setCheckable(true); - m_aces->setChecked(true); - m_acesLut = toneMappingMenu->addAction("AcesLut", [this]() { - MaterialViewportRequestBus::Broadcast( - &MaterialViewportRequestBus::Events::SetDisplayMapperOperationType, - AZ::Render::DisplayMapperOperationType::AcesLut); - }); - m_acesLut->setCheckable(true); - m_passthrough = toneMappingMenu->addAction("Passthrough", [this]() { - MaterialViewportRequestBus::Broadcast( - &MaterialViewportRequestBus::Events::SetDisplayMapperOperationType, - AZ::Render::DisplayMapperOperationType::Passthrough); - }); - m_passthrough->setCheckable(true); - m_gammaSRGB = toneMappingMenu->addAction("GammaSRGB", [this]() { - MaterialViewportRequestBus::Broadcast( - &MaterialViewportRequestBus::Events::SetDisplayMapperOperationType, - AZ::Render::DisplayMapperOperationType::GammaSRGB); - }); - m_gammaSRGB->setCheckable(true); - m_reinhard = toneMappingMenu->addAction("Reinhard", [this]() { - MaterialViewportRequestBus::Broadcast( - &MaterialViewportRequestBus::Events::SetDisplayMapperOperationType, - AZ::Render::DisplayMapperOperationType::Reinhard); - }); - m_reinhard->setCheckable(true); + + m_operationNames = + { + { AZ::Render::DisplayMapperOperationType::Reinhard, "Reinhard" }, + { AZ::Render::DisplayMapperOperationType::GammaSRGB, "GammaSRGB" }, + { AZ::Render::DisplayMapperOperationType::Passthrough, "Passthrough" }, + { AZ::Render::DisplayMapperOperationType::AcesLut, "AcesLut" }, + { AZ::Render::DisplayMapperOperationType::Aces, "Aces" } + }; + for (auto operationNamePair : m_operationNames) + { + m_operationActions[operationNamePair.first] = toneMappingMenu->addAction(operationNamePair.second, [operationNamePair]() { + MaterialViewportRequestBus::Broadcast( + &MaterialViewportRequestBus::Events::SetDisplayMapperOperationType, + operationNamePair.first); + }); + m_operationActions[operationNamePair.first]->setCheckable(true); + } + m_operationActions[AZ::Render::DisplayMapperOperationType::Aces]->setChecked(true); toneMappingButton->setMenu(toneMappingMenu); toneMappingButton->setText("Tone Mapping"); toneMappingButton->setIcon(QIcon(":/Icons/toneMapping.svg")); toneMappingButton->setPopupMode(QToolButton::InstantPopup); - - // hiding button until DisplayMapper supports changing settings at run time toneMappingButton->setVisible(true); addWidget(toneMappingButton); @@ -123,29 +109,9 @@ namespace MaterialEditor void MaterialEditorToolBar::OnDisplayMapperOperationTypeChanged(AZ::Render::DisplayMapperOperationType operationType) { - m_aces->setChecked(false); - m_acesLut->setChecked(false); - m_passthrough->setChecked(false); - m_gammaSRGB->setChecked(false); - m_reinhard->setChecked(false); - - switch (operationType) + for (auto operationActionPair : m_operationActions) { - case AZ::Render::DisplayMapperOperationType::Aces: - m_aces->setChecked(true); - break; - case AZ::Render::DisplayMapperOperationType::AcesLut: - m_acesLut->setChecked(true); - break; - case AZ::Render::DisplayMapperOperationType::Passthrough: - m_passthrough->setChecked(true); - break; - case AZ::Render::DisplayMapperOperationType::GammaSRGB: - m_gammaSRGB->setChecked(true); - break; - case AZ::Render::DisplayMapperOperationType::Reinhard: - m_reinhard->setChecked(true); - break; + operationActionPair.second->setChecked(operationActionPair.first == operationType); } } diff --git a/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/ToolBar/MaterialEditorToolBar.h b/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/ToolBar/MaterialEditorToolBar.h index a711c8d4f8..25077c1868 100644 --- a/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/ToolBar/MaterialEditorToolBar.h +++ b/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/ToolBar/MaterialEditorToolBar.h @@ -38,10 +38,7 @@ namespace MaterialEditor QAction* m_toggleGrid = {}; QAction* m_toggleShadowCatcher = {}; - QAction* m_aces = {}; - QAction* m_acesLut = {}; - QAction* m_passthrough = {}; - QAction* m_gammaSRGB = {}; - QAction* m_reinhard = {}; + AZStd::unordered_map m_operationNames; + AZStd::unordered_map m_operationActions; }; } // namespace MaterialEditor