MRTExampleComponent.h 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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 <Atom/RHI/BufferPool.h>
  10. #include <Atom/RHI/ScopeProducer.h>
  11. #include <Atom/RPI.Public/Image/AttachmentImage.h>
  12. #include <Atom/RHI/RHISystemInterface.h>
  13. #include <Atom/RPI.Public/Shader/ShaderResourceGroup.h>
  14. #include <Atom/RPI.Public/WindowContext.h>
  15. #include <Atom/RPI.Reflect/ResourcePoolAssetCreator.h>
  16. #include <AzCore/Component/Component.h>
  17. #include <RHI/BasicRHIComponent.h>
  18. namespace AtomSampleViewer
  19. {
  20. //! Multiple Render Targets testing, using 2 scopes
  21. //! First scope render to 3 render targets with different R, G, B values
  22. //! Second scope merge the result from 3 render targets and render to screen
  23. class MRTExampleComponent final
  24. : public BasicRHIComponent
  25. {
  26. public:
  27. AZ_COMPONENT(MRTExampleComponent, "{A18A98CB-1274-474F-81CC-E9238B3AD0AF}", AZ::Component);
  28. AZ_DISABLE_COPY(MRTExampleComponent);
  29. static void Reflect(AZ::ReflectContext* context);
  30. MRTExampleComponent();
  31. ~MRTExampleComponent() = default;
  32. protected:
  33. // AZ::Component
  34. void Activate() override;
  35. void Deactivate() override;
  36. // RHISystemNotificationBus::Handler
  37. void OnFramePrepare(AZ::RHI::FrameGraphBuilder& frameGraphBuilder) override;
  38. void CreateInputAssemblyBuffersAndViews();
  39. void InitRenderTargets();
  40. void CreateRenderTargetScope();
  41. void CreateScreenScope();
  42. // init pipeline state
  43. void ReadRenderTargetShader();
  44. void ReadScreenShader();
  45. AZ::RHI::Ptr<AZ::RHI::BufferPool> m_bufferPool;
  46. AZ::RHI::Ptr<AZ::RHI::Buffer> m_inputAssemblyBuffer;
  47. AZStd::array<AZ::RHI::TransientImageDescriptor, 3> m_renderTargetImageDescriptors;
  48. AZ::RHI::InputStreamLayout m_inputStreamLayout;
  49. AZStd::array<AZ::RHI::ConstPtr<AZ::RHI::PipelineState>,2> m_pipelineStates;
  50. AZStd::array<AZ::Data::Instance<AZ::RPI::ShaderResourceGroup>, 2> m_shaderResourceGroups;
  51. AZStd::array<AZ::RHI::ShaderInputConstantIndex, 3> m_shaderInputConstantIndices;
  52. AZStd::array<AZ::RHI::ShaderInputImageIndex, 3> m_shaderInputImageIndices;
  53. struct ScopeData
  54. {
  55. //UserDataParam - Empty for this samples
  56. };
  57. struct BufferData
  58. {
  59. AZStd::array<VertexPosition, 4> m_positions;
  60. AZStd::array<VertexUV, 4> m_uvs;
  61. AZStd::array<uint16_t, 6> m_indices;
  62. };
  63. AZ::RHI::GeometryView m_geometryView;
  64. AZStd::array<AZ::RHI::AttachmentId, 3> m_attachmentID;
  65. AZ::RHI::ClearValue m_clearValue;
  66. float m_time;
  67. };
  68. }