DynamicMaterialTestComponent.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /*
  2. * All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
  3. * its licensors.
  4. *
  5. * For complete copyright and license terms please see the LICENSE at the root of this
  6. * distribution (the "License"). All use of this software is governed by the License,
  7. * or, if provided, by the license below or the license accompanying this file. Do not
  8. * remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
  9. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. *
  11. */
  12. #pragma once
  13. #include <EntityLatticeTestComponent.h>
  14. #include <Utils/ImGuiSidebar.h>
  15. #include <Utils/ImGuiHistogramQueue.h>
  16. #include <Atom/RPI.Reflect/Material/MaterialPropertyDescriptor.h>
  17. #include <AzCore/Component/TickBus.h>
  18. #include <AzCore/std/functional.h>
  19. namespace AtomSampleViewer
  20. {
  21. //! This test loads a configurable lattice of entities, gives them all a unique Material instance, and
  22. //! changes a material property value every frame. UI to configure the size of the lattice is included.
  23. class DynamicMaterialTestComponent final
  24. : public EntityLatticeTestComponent
  25. , public AZ::TickBus::Handler
  26. {
  27. using Base = EntityLatticeTestComponent;
  28. public:
  29. AZ_COMPONENT(DynamicMaterialTestComponent, "{14E4AD00-BB56-4771-809F-1AF7BD3611D9}", EntityLatticeTestComponent);
  30. DynamicMaterialTestComponent();
  31. static void Reflect(AZ::ReflectContext* context);
  32. // AZ::Component overrides...
  33. void Activate() override;
  34. void Deactivate() override;
  35. private:
  36. AZ_DISABLE_COPY_MOVE(DynamicMaterialTestComponent);
  37. void InitMaterialConfigs();
  38. //! EntityLatticeTestComponent overrides...
  39. void PrepareCreateLatticeInstances(uint32_t instanceCount) override;
  40. void CreateLatticeInstance(const AZ::Transform& transform) override;
  41. void DestroyLatticeInstances() override;
  42. // AZ::TickBus::Handler overrides...
  43. void OnTick(float deltaTime, AZ::ScriptTimePoint scriptTime) override;
  44. void CompileWithTimer(AZ::Data::Instance<AZ::RPI::Material> material);
  45. void UpdateStandardPbrColors();
  46. void UpdateEmissiveMaterialIntensity();
  47. void CompileMaterials();
  48. ImGuiSidebar m_imguiSidebar;
  49. bool m_pause = false;
  50. struct MaterialConfig
  51. {
  52. AZStd::string m_name;
  53. AZ::Data::Asset<AZ::RPI::MaterialAsset> m_materialAsset;
  54. AZStd::function<void()> m_updateLatticeMaterials;
  55. };
  56. AZStd::vector<MaterialConfig> m_materialConfigs;
  57. int m_currentMaterialConfig;
  58. AZ::Data::Asset<AZ::RPI::ModelAsset> m_modelAsset;
  59. AZStd::vector<AZ::Render::MeshFeatureProcessorInterface::MeshHandle> m_meshHandles;
  60. AZStd::vector<AZ::Data::Instance<AZ::RPI::Material>> m_materials;
  61. static constexpr AZStd::size_t CompileTimerQueueSize = 30;
  62. ImGuiHistogramQueue m_compileTimer;
  63. bool m_waitingForMeshes = false;
  64. uint32_t m_loadedMeshCounter = 0;
  65. AZStd::vector<AZ::Render::MeshFeatureProcessorInterface::ModelChangedEvent::Handler> m_meshLoadEventHandlers;
  66. float m_currentTime = 0.0f;
  67. };
  68. } // namespace AtomSampleViewer