TonemappingExampleComponent.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #pragma once
  9. #include <CommonSampleComponentBase.h>
  10. #include <Atom/Feature/DisplayMapper/DisplayMapperConfigurationDescriptor.h>
  11. #include <Atom/Feature/Mesh/MeshFeatureProcessorInterface.h>
  12. #include <Atom/Feature/PostProcess/PostProcessFeatureProcessorInterface.h>
  13. #include <Atom/RPI.Public/DynamicDraw/DynamicDrawInterface.h>
  14. #include <Atom/RPI.Public/ColorManagement/TransformColor.h>
  15. #include <Atom/RPI.Public/Image/StreamingImage.h>
  16. #include <AzCore/Component/TickBus.h>
  17. #include <AzFramework/Entity/EntityContextBus.h>
  18. #include <Utils/Utils.h>
  19. #include <Utils/ImGuiSidebar.h>
  20. #include <Utils/ImGuiAssetBrowser.h>
  21. #include <Utils/ImGuiSaveFilePath.h>
  22. namespace AtomSampleViewer
  23. {
  24. //! This component creates a simple scene to demonstrate the tonemapping feature by displaying a fullscreen image.
  25. //! The output from the DisplayMapper pass can also be captured to image.
  26. class TonemappingExampleComponent final
  27. : public CommonSampleComponentBase
  28. , public AZ::TickBus::Handler
  29. {
  30. public:
  31. AZ_COMPONENT(TonemappingExampleComponent, "{06777F38-E0DA-490E-9F1C-97274826A0EF}");
  32. static void Reflect(AZ::ReflectContext* context);
  33. TonemappingExampleComponent();
  34. ~TonemappingExampleComponent() override = default;
  35. void Activate() override;
  36. void Deactivate() override;
  37. private:
  38. // AZ::TickBus::Handler overrides...
  39. void OnTick(float deltaTime, AZ::ScriptTimePoint time) override;
  40. // GUI
  41. void DrawSidebar();
  42. const char* GetDisplayMapperOperationTypeLabel() const;
  43. // Image loading and capture
  44. void UpdateCapturePassHierarchy();
  45. void SaveCapture();
  46. AZ::RPI::ColorSpaceId GetColorSpaceIdForIndex(uint8_t colorSpaceIndex) const;
  47. void ImageChanged();
  48. struct ImageToDraw
  49. {
  50. AZ::Data::AssetId m_assetId;
  51. AZ::Data::Instance<AZ::RPI::StreamingImage> m_image;
  52. AZ::Data::Instance<AZ::RPI::ShaderResourceGroup> m_srg;
  53. bool m_wasStreamed = false;
  54. };
  55. // Submit draw package to draw image
  56. void DrawImage(const ImageToDraw* imageInfo);
  57. // Creates resources, resource views, pipeline state, etc. for rendering
  58. void PrepareRenderData();
  59. void QueueAssetPathForLoad(const AZStd::string& filePath);
  60. void QueueAssetIdForLoad(const AZ::Data::AssetId& imageAssetId);
  61. // non-owning entity
  62. AzFramework::EntityContextId m_entityContextId;
  63. // GUI
  64. ImGuiSidebar m_imguiSidebar;
  65. // Cache the DynamicDraw Interface
  66. AZ::RPI::DynamicDrawInterface* m_dynamicDraw = nullptr;
  67. // render related data
  68. AZ::RHI::GeometryView m_geometryView;
  69. AZ::RHI::ConstPtr<AZ::RHI::PipelineState> m_pipelineState;
  70. AZ::RHI::DrawListTag m_drawListTag;
  71. AZ::Data::Asset<AZ::RPI::ShaderAsset> m_shaderAsset;
  72. AZ::RHI::Ptr<AZ::RHI::ShaderResourceGroupLayout> m_srgLayout;
  73. // shader input indices
  74. AZ::RHI::ShaderInputImageIndex m_imageInputIndex;
  75. AZ::RHI::ShaderInputConstantIndex m_positionInputIndex;
  76. AZ::RHI::ShaderInputConstantIndex m_sizeInputIndex;
  77. AZ::RHI::ShaderInputConstantIndex m_colorSpaceIndex;
  78. // Image to display
  79. ImageToDraw m_drawImage;
  80. AZ::RPI::ColorSpaceId m_inputColorSpace = AZ::RPI::ColorSpaceId::ACEScg;
  81. static const char* s_colorSpaceLabels[];
  82. int m_inputColorSpaceIndex = 0;
  83. const AZStd::string InputImageFolder = "textures\\tonemapping\\";
  84. ImGuiSaveFilePath m_imguiFrameCaptureSaver;
  85. AZ::Render::DisplayMapperConfigurationDescriptor m_displayMapperConfiguration;
  86. AZStd::vector<AZStd::string> m_capturePassHierarchy;
  87. ImGuiAssetBrowser m_imageBrowser;
  88. };
  89. } // namespace AtomSampleViewer