/* * 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 { //! MultipleViewsComponent //! The purpose of this sample is to test multiple views by doing shadow mapping, //! to have more complex shaders, test resource bindings and comprehensive support of depth/stencil buffer. //! For this sample, there will be 2 views: the main view (or camera view) and the light view. //! As for the geometries, there is a plane with a cube sitting on it. class MultipleViewsComponent final : public BasicRHIComponent , public AZ::EntitySystemBus::Handler { public: AZ_COMPONENT(MultipleViewsComponent, "{A8CC6572-7FD4-4708-88B3-E24034C8F6FC}", AZ::Component); AZ_DISABLE_COPY(MultipleViewsComponent); static void Reflect(AZ::ReflectContext* context); MultipleViewsComponent(); ~MultipleViewsComponent() override = default; // AZ::Component void Activate() override; void Deactivate() override; protected: static const uint32_t geometryVertexCount = 28; static const uint32_t geometryIndexCount = 42; struct BufferData { AZStd::array m_positions; AZStd::array m_colors; AZStd::array m_normals; AZStd::array m_indices; }; struct ScopeData { //UserDataParam - Empty for this samples }; // RHISystemNotificationBus::Handler void OnFramePrepare(AZ::RHI::FrameGraphBuilder& frameGraphBuilder) override; // Create Buffers for Input Assembly BufferData CreateBufferData(); void CreateInputAssemblyBuffersAndViews(); void SetupScene(); void InitRenderTarget(); void CreateDepthScope(); void CreateMainScope(); void ReadDepthShader(); void ReadMainShader(); // shadow map required variable AZ::Matrix4x4 m_worldMatrix; AZ::Matrix4x4 m_viewProjectionMatrix; AZ::Vector3 m_worldPosition; AZ::Matrix4x4 m_lightViewProjectionMatrix; AZ::Matrix4x4 m_lightProjectionMatrix; AZ::Vector4 m_lightPosition; AZ::Vector4 m_ambientColor; AZ::Vector4 m_diffuseColor; static constexpr float m_zNear = 1.0f; static constexpr float m_zFar = 100.0f; static const AZ::Vector3 m_up; static const AZ::Vector3 m_lookAt; static const int s_shadowMapSize = 1024; AZ::RHI::Ptr m_bufferPool; AZ::RHI::Ptr m_inputAssemblyBuffer; AZ::RHI::InputStreamLayout m_inputStreamLayout; AZStd::array, 2> m_pipelineStates; AZStd::array, 2> m_shaderResourceGroups; AZStd::array m_shaderInputConstantIndices; AZ::RHI::ShaderInputImageIndex m_shaderInputImageIndex; AZStd::array m_streamBufferViews; AZ::RHI::IndexBufferView m_indexBufferView; AZ::RHI::AttachmentId m_depthMapID; AZ::RHI::AttachmentId m_depthStencilID; AZ::RHI::ClearValue m_depthClearValue; AZ::RHI::DrawItem m_drawItem; AZ::RHI::TransientImageDescriptor m_transientImageDescriptor; }; } // namespace AtomSampleViewer