BloomExampleComponent.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. /*
  2. * All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
  3. * its licensors.
  4. *
  5. * For complete copyright and license terms please see the LICENSE at the root of this
  6. * distribution (the "License"). All use of this software is governed by the License,
  7. * or, if provided, by the license below or the license accompanying this file. Do not
  8. * remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
  9. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. *
  11. */
  12. #pragma once
  13. #include <CommonSampleComponentBase.h>
  14. #include <Atom/Feature/DisplayMapper/DisplayMapperConfigurationDescriptor.h>
  15. #include <Atom/Feature/Mesh/MeshFeatureProcessorInterface.h>
  16. #include <Atom/Feature/PostProcess/PostProcessFeatureProcessorInterface.h>
  17. #include <Atom/RPI.Public/ColorManagement/TransformColor.h>
  18. #include <Atom/RPI.Public/DynamicDraw/DynamicDrawInterface.h>
  19. #include <Atom/RPI.Public/Image/StreamingImage.h>
  20. #include <AzCore/Component/TickBus.h>
  21. #include <AzCore/Component/EntityBus.h>
  22. #include <AzFramework/Entity/EntityContextBus.h>
  23. #include <Utils/Utils.h>
  24. #include <Utils/ImGuiSidebar.h>
  25. #include <Utils/ImGuiAssetBrowser.h>
  26. #include <Utils/ImGuiSaveFilePath.h>
  27. namespace AtomSampleViewer
  28. {
  29. //! This component reuses the scene of tonemapping example to demonstrate the bloom feature
  30. class BloomExampleComponent final
  31. : public CommonSampleComponentBase
  32. , public AZ::TickBus::Handler
  33. {
  34. public:
  35. AZ_COMPONENT(BloomExampleComponent, "{F1957895-D74D-4A82-BF0C-055B57AB698A}", CommonSampleComponentBase);
  36. static void Reflect(AZ::ReflectContext* context);
  37. BloomExampleComponent();
  38. ~BloomExampleComponent() override = default;
  39. void Activate() override;
  40. void Deactivate() override;
  41. private:
  42. // AZ::TickBus::Handler overrides...
  43. void OnTick(float deltaTime, AZ::ScriptTimePoint time) override;
  44. // AZ::EntityBus::MultiHandler...
  45. void OnEntityDestruction(const AZ::EntityId& entityId) override;
  46. // GUI
  47. void DrawSidebar();
  48. // Image loading and capture
  49. AZ::RPI::ColorSpaceId GetColorSpaceIdForIndex(uint8_t colorSpaceIndex) const;
  50. struct ImageToDraw
  51. {
  52. AZ::Data::AssetId m_assetId;
  53. AZ::Data::Instance<AZ::RPI::StreamingImage> m_image;
  54. AZ::Data::Instance<AZ::RPI::ShaderResourceGroup> m_srg;
  55. bool m_wasStreamed = false;
  56. };
  57. // Submit draw package to draw image
  58. void DrawImage(const ImageToDraw* imageInfo);
  59. // Creates resources, resource views, pipeline state, etc. for rendering
  60. void PrepareRenderData();
  61. void QueueAssetPathForLoad(const AZStd::string& filePath);
  62. void QueueAssetIdForLoad(const AZ::Data::AssetId& imageAssetId);
  63. // Create bloom entity for rendering
  64. void CreateBloomEntity();
  65. // non-owning entity
  66. AzFramework::EntityContextId m_entityContextId;
  67. // owning entity
  68. AZ::Entity* m_bloomEntity = nullptr;
  69. // Init flag
  70. bool m_isInitParameters = false;
  71. // GUI
  72. ImGuiSidebar m_imguiSidebar;
  73. // Cache the DynamicDraw Interface
  74. AZ::RPI::DynamicDrawInterface* m_dynamicDraw = nullptr;
  75. // render related data
  76. AZ::RHI::ConstPtr<AZ::RHI::PipelineState> m_pipelineState;
  77. AZ::RHI::DrawListTag m_drawListTag;
  78. AZ::Data::Asset<AZ::RPI::ShaderResourceGroupAsset> m_srgAsset;
  79. // shader input indices
  80. AZ::RHI::ShaderInputImageIndex m_imageInputIndex;
  81. AZ::RHI::ShaderInputConstantIndex m_positionInputIndex;
  82. AZ::RHI::ShaderInputConstantIndex m_sizeInputIndex;
  83. AZ::RHI::ShaderInputConstantIndex m_colorSpaceIndex;
  84. // post processing feature processor
  85. AZ::Render::PostProcessFeatureProcessorInterface* m_postProcessFeatureProcessor = nullptr;
  86. AZ::Render::BloomSettingsInterface* m_bloomSettings = nullptr;
  87. // Image to display
  88. ImageToDraw m_drawImage;
  89. AZ::RPI::ColorSpaceId m_inputColorSpace = AZ::RPI::ColorSpaceId::ACEScg;
  90. static const char* s_colorSpaceLabels[];
  91. int m_inputColorSpaceIndex = 0;
  92. const AZStd::string InputImageFolder = "textures\\bloom\\";
  93. AZ::Render::DisplayMapperConfigurationDescriptor m_displayMapperConfiguration;
  94. AZStd::vector<AZStd::string> m_capturePassHierarchy;
  95. ImGuiAssetBrowser m_imageBrowser;
  96. };
  97. } // namespace AtomSampleViewer