BloomExampleComponent.h 4.3 KB

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