/* * 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. * * SPDX-License-Identifier: Apache-2.0 OR MIT * */ #pragma once #include #include #include #include #include #include #include #include namespace AtomSampleViewer { //! This samples shows how to handle vertex buffer generation on a compute shader and how //! to properly declare shader inputs. //! There's 2 scopes in this sample, one runs a compute shader that is in charge of generating and animating the //! vertices of a 2D hexagon. The second scope is in charge of drawing the previously generated hexagon vertex buffer. class InputAssemblyExampleComponent final : public BasicRHIComponent , public AZ::TickBus::Handler { public: AZ_COMPONENT(InputAssemblyExampleComponent, "{1F061564-DB4A-4B68-B361-0B427B3CA5B5}", AZ::Component); AZ_DISABLE_COPY(InputAssemblyExampleComponent); static void Reflect(AZ::ReflectContext* context); InputAssemblyExampleComponent(); ~InputAssemblyExampleComponent() = default; protected: // We have only float4 vertex positions as data. using BufferData = AZStd::array, 6>; int m_numThreadsX = 1; int m_numThreadsY = 1; int m_numThreadsZ = 1; // AZ::Component void Activate() override; void Deactivate() override; void FrameBeginInternal(AZ::RHI::FrameGraphBuilder& frameGraphBuilder) override; // TickBus::Handler void OnTick(float deltaTime, AZ::ScriptTimePoint time) override; void CreateInputAssemblyLayout(); void CreateBuffers(); void LoadComputeShader(); void LoadRasterShader(); void CreateComputeScope(); void CreateRasterScope(); // ------------------------------------------------- // Input Assembly buffer and its Streams/Index Views // ------------------------------------------------- AZ::RHI::GeometryView m_geometryView[2]; AZ::RHI::InputStreamLayout m_inputStreamLayout; AZ::RHI::Ptr m_inputAssemblyBufferPool; AZ::RHI::Ptr m_inputAssemblyBuffer; // ---------------------- // Pipeline state and SRG // ---------------------- // Dispatch pipeline AZ::RHI::ConstPtr m_dispatchPipelineState; AZ::Data::Instance m_dispatchSRG[2]; AZ::RHI::ShaderInputConstantIndex m_dispatchTimeConstantIndex; AZ::RHI::ShaderInputBufferIndex m_dispatchIABufferIndex; // Draw pipeline AZ::RHI::ConstPtr m_drawPipelineState; AZ::RHI::ShaderInputConstantIndex m_drawMatrixIndex; AZ::RHI::ShaderInputConstantIndex m_drawColorIndex; AZ::Data::Instance m_drawSRG[2]; // This is used to animate the hexagon. float m_time = 0.0f; }; }