BloomExampleComponent.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. /*
  2. * 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.
  3. *
  4. * SPDX-License-Identifier: Apache-2.0 OR MIT
  5. *
  6. */
  7. #pragma once
  8. #include <CommonSampleComponentBase.h>
  9. #include <Atom/Feature/DisplayMapper/DisplayMapperConfigurationDescriptor.h>
  10. #include <Atom/Feature/Mesh/MeshFeatureProcessorInterface.h>
  11. #include <Atom/Feature/PostProcess/PostProcessFeatureProcessorInterface.h>
  12. #include <Atom/RPI.Public/ColorManagement/TransformColor.h>
  13. #include <Atom/RPI.Public/DynamicDraw/DynamicDrawInterface.h>
  14. #include <Atom/RPI.Public/Image/StreamingImage.h>
  15. #include <AzCore/Component/TickBus.h>
  16. #include <AzCore/Component/EntityBus.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 reuses the scene of tonemapping example to demonstrate the bloom feature
  25. class BloomExampleComponent final
  26. : public CommonSampleComponentBase
  27. , public AZ::TickBus::Handler
  28. {
  29. public:
  30. AZ_COMPONENT(BloomExampleComponent, "{F1957895-D74D-4A82-BF0C-055B57AB698A}", CommonSampleComponentBase);
  31. static void Reflect(AZ::ReflectContext* context);
  32. BloomExampleComponent();
  33. ~BloomExampleComponent() override = default;
  34. void Activate() override;
  35. void Deactivate() override;
  36. private:
  37. // AZ::TickBus::Handler overrides...
  38. void OnTick(float deltaTime, AZ::ScriptTimePoint time) override;
  39. // AZ::EntityBus::MultiHandler...
  40. void OnEntityDestruction(const AZ::EntityId& entityId) override;
  41. // GUI
  42. void DrawSidebar();
  43. // Image loading and capture
  44. AZ::RPI::ColorSpaceId GetColorSpaceIdForIndex(uint8_t colorSpaceIndex) const;
  45. struct ImageToDraw
  46. {
  47. AZ::Data::AssetId m_assetId;
  48. AZ::Data::Instance<AZ::RPI::StreamingImage> m_image;
  49. AZ::Data::Instance<AZ::RPI::ShaderResourceGroup> m_srg;
  50. bool m_wasStreamed = false;
  51. };
  52. // Submit draw package to draw image
  53. void DrawImage(const ImageToDraw* imageInfo);
  54. // Creates resources, resource views, pipeline state, etc. for rendering
  55. void PrepareRenderData();
  56. void QueueAssetPathForLoad(const AZStd::string& filePath);
  57. void QueueAssetIdForLoad(const AZ::Data::AssetId& imageAssetId);
  58. // Create bloom entity for rendering
  59. void CreateBloomEntity();
  60. // non-owning entity
  61. AzFramework::EntityContextId m_entityContextId;
  62. // owning entity
  63. AZ::Entity* m_bloomEntity = nullptr;
  64. // Init flag
  65. bool m_isInitParameters = false;
  66. // GUI
  67. ImGuiSidebar m_imguiSidebar;
  68. // Cache the DynamicDraw Interface
  69. AZ::RPI::DynamicDrawInterface* m_dynamicDraw = nullptr;
  70. // render related data
  71. AZ::RHI::ConstPtr<AZ::RHI::PipelineState> m_pipelineState;
  72. AZ::RHI::DrawListTag m_drawListTag;
  73. AZ::Data::Asset<AZ::RPI::ShaderAsset> m_shaderAsset;
  74. AZ::RHI::Ptr<AZ::RHI::ShaderResourceGroupLayout> m_srgLayout;
  75. // shader input indices
  76. AZ::RHI::ShaderInputNameIndex m_imageInputIndex = "m_texture";
  77. AZ::RHI::ShaderInputNameIndex m_positionInputIndex = "m_position";
  78. AZ::RHI::ShaderInputNameIndex m_sizeInputIndex = "m_size";
  79. AZ::RHI::ShaderInputNameIndex m_colorSpaceIndex = "m_colorSpace";
  80. // post processing feature processor
  81. AZ::Render::PostProcessFeatureProcessorInterface* m_postProcessFeatureProcessor = nullptr;
  82. AZ::Render::BloomSettingsInterface* m_bloomSettings = nullptr;
  83. // Image to display
  84. ImageToDraw m_drawImage;
  85. AZ::RPI::ColorSpaceId m_inputColorSpace = AZ::RPI::ColorSpaceId::ACEScg;
  86. static const char* s_colorSpaceLabels[];
  87. int m_inputColorSpaceIndex = 0;
  88. const AZStd::string InputImageFolder = "textures\\bloom\\";
  89. AZ::Render::DisplayMapperConfigurationDescriptor m_displayMapperConfiguration;
  90. AZStd::vector<AZStd::string> m_capturePassHierarchy;
  91. ImGuiAssetBrowser m_imageBrowser;
  92. };
  93. } // namespace AtomSampleViewer