DualSourceBlendingComponent.h 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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 <AzCore/Component/TickBus.h>
  10. #include <Atom/RHI/PipelineState.h>
  11. #include <RHI/BasicRHIComponent.h>
  12. namespace AtomSampleViewer
  13. {
  14. //! Dual source blending testing
  15. //! Using dual source blending to implement alpha blending
  16. //! Showing a color triangle fade in and fade out on success
  17. class DualSourceBlendingComponent final
  18. : public BasicRHIComponent
  19. , public AZ::TickBus::Handler
  20. {
  21. public:
  22. AZ_COMPONENT(DualSourceBlendingComponent, "{792A6BF1-6FD8-4834-81DE-2B39F1E2A9BB}", AZ::Component);
  23. static void Reflect(AZ::ReflectContext* context);
  24. DualSourceBlendingComponent();
  25. ~DualSourceBlendingComponent() override = default;
  26. protected:
  27. AZ_DISABLE_COPY(DualSourceBlendingComponent);
  28. static const char* s_dualSourceBlendingName;
  29. static const uint32_t geometryVertexCount = 3;
  30. static const uint32_t geometryIndexCount = 3;
  31. // AZ::Component
  32. void Activate() override;
  33. void Deactivate() override;
  34. // RHISystemNotificationBus::Handler
  35. void OnFramePrepare(AZ::RHI::FrameGraphBuilder& frameGraphBuilder) override;
  36. // TickBus::Handler
  37. void OnTick(float deltaTime, AZ::ScriptTimePoint time) override;
  38. void CreateInputAssemblyBuffersAndViews();
  39. void LoadRasterShader();
  40. void CreateRasterScope();
  41. // -------------------------------------------------
  42. // Input Assembly buffer and its Streams/Index Views
  43. // -------------------------------------------------
  44. struct BufferData
  45. {
  46. AZStd::array<VertexPosition, geometryVertexCount> m_positions;
  47. AZStd::array<VertexColor, geometryVertexCount> m_colors;
  48. AZStd::array<uint16_t, geometryIndexCount> m_indices;
  49. };
  50. AZ::RHI::Ptr<AZ::RHI::BufferPool> m_inputAssemblyBufferPool;
  51. AZ::RHI::Ptr<AZ::RHI::Buffer> m_inputAssemblyBuffer;
  52. AZ::RHI::GeometryView m_geometryView;
  53. AZ::RHI::InputStreamLayout m_inputStreamLayout;
  54. // ----------------------------------
  55. // Pipeline and Shader Resource Group
  56. // ----------------------------------
  57. AZ::RHI::ConstPtr<AZ::RHI::PipelineState> m_pipelineState;
  58. AZ::Data::Instance < AZ::RPI::ShaderResourceGroup> m_shaderResourceGroup;
  59. AZ::RHI::ShaderInputConstantIndex m_blendFactorIndex;
  60. // ------
  61. // Others
  62. // ------
  63. float m_time = 0.0f;
  64. };
  65. }