MRTExampleComponent.h 2.9 KB

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