RootConstantsExampleComponent.h 3.0 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 <CommonSampleComponentBase.h>
  10. #include <Atom/Feature/CoreLights/DirectionalLightFeatureProcessorInterface.h>
  11. #include <Atom/RHI/IndexBufferView.h>
  12. #include <Atom/RHI/PipelineState.h>
  13. #include <Atom/RHI/DrawList.h>
  14. #include <Atom/RHI/ConstantsData.h>
  15. #include <Atom/RPI.Public/DynamicDraw/DynamicDrawInterface.h>
  16. #include <Atom/RPI.Public/Shader/ShaderResourceGroup.h>
  17. #include <Atom/RPI.Public/Model/Model.h>
  18. #include <Atom/RPI.Public/Model/ModelLod.h>
  19. #include <AzFramework/Asset/AssetCatalogBus.h>
  20. #include <AzCore/Component/TickBus.h>
  21. #include <AzFramework/Windowing/WindowBus.h>
  22. #include <ExampleComponentBus.h>
  23. struct ImGuiContext;
  24. namespace AtomSampleViewer
  25. {
  26. //! This samples demonstrates the use of root constants.
  27. //! It uses root constants to update the object's matrix and an index to a material array.
  28. //! A "material" in this example is just a simple structure with a color.
  29. //! There's no SRG updates after initialization.
  30. class RootConstantsExampleComponent final
  31. : public CommonSampleComponentBase
  32. , public AZ::TickBus::Handler
  33. , public ExampleComponentRequestBus::Handler
  34. {
  35. public:
  36. AZ_COMPONENT(RootConstantsExampleComponent, "{E0838156-DB0D-40BE-ADDD-9BF05889BBD6}", CommonSampleComponentBase);
  37. static void Reflect(AZ::ReflectContext* context);
  38. RootConstantsExampleComponent();
  39. ~RootConstantsExampleComponent() override = default;
  40. void Activate() override;
  41. void Deactivate() override;
  42. private:
  43. // AZ::TickBus::Handler
  44. void OnTick(float deltaTime, AZ::ScriptTimePoint timePoint) override;
  45. // ExampleComponentRequestBus::Handler
  46. void ResetCamera() override;
  47. void PrepareRenderData();
  48. void SetupScene();
  49. void DrawModel(uint32_t modelIndex);
  50. // Models
  51. AZStd::vector<AZ::Data::Instance<AZ::RPI::Model>> m_models;
  52. AZStd::vector<AZStd::vector<AZ::RHI::StreamBufferIndices>> m_streamIndices;
  53. // Cache interfaces
  54. AZ::RPI::DynamicDrawInterface* m_dynamicDraw = nullptr;
  55. AZ::Render::DirectionalLightFeatureProcessorInterface* m_directionalLightFeatureProcessor = nullptr;
  56. // Render related data
  57. AZ::RHI::ConstPtr<AZ::RHI::PipelineState> m_pipelineState;
  58. AZ::RHI::DrawListTag m_drawListTag;
  59. AZ::Data::Instance<AZ::RPI::ShaderResourceGroup> m_srg;
  60. // Root constant data
  61. AZ::RHI::ConstantsData m_rootConstantData;
  62. AZ::RHI::ShaderInputConstantIndex m_materialIdInputIndex;
  63. AZ::RHI::ShaderInputConstantIndex m_modelMatrixInputIndex;
  64. // Scene
  65. AZ::Render::DirectionalLightFeatureProcessorInterface::LightHandle m_directionalLightHandle;
  66. AZStd::vector<AZ::Matrix4x4> m_modelMatrices;
  67. };
  68. } // namespace AtomSampleViewer