HairGeometryRasterPass.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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/Memory/SystemAllocator.h>
  10. #include <Atom/RHI.Reflect/Size.h>
  11. #include <Atom/RPI.Public/Pass/RasterPass.h>
  12. #include <Atom/RPI.Public/Shader/Shader.h>
  13. #include <Atom/RPI.Public/Shader/ShaderResourceGroup.h>
  14. #include <Atom/RPI.Public/Shader/ShaderReloadNotificationBus.h>
  15. namespace AZ
  16. {
  17. namespace RHI
  18. {
  19. struct DrawItem;
  20. }
  21. namespace Render
  22. {
  23. namespace Hair
  24. {
  25. class HairRenderObject;
  26. class HairFeatureProcessor;
  27. //! A HairGeometryRasterPass is used for the render of the hair geometries. This is the base
  28. //! class that can be inherited - for example by the HiarPPLLRasterPass and have only the specific
  29. //! class data handling added on top.
  30. class HairGeometryRasterPass
  31. : public RPI::RasterPass
  32. , private RPI::ShaderReloadNotificationBus::Handler
  33. {
  34. AZ_RPI_PASS(HairGeometryRasterPass);
  35. public:
  36. AZ_RTTI(HairGeometryRasterPass, "{0F07360A-A286-4060-8C62-137AFFA50561}", RasterPass);
  37. AZ_CLASS_ALLOCATOR(HairGeometryRasterPass, SystemAllocator);
  38. //! Creates a HairGeometryRasterPass
  39. static RPI::Ptr<HairGeometryRasterPass> Create(const RPI::PassDescriptor& descriptor);
  40. bool AddDrawPackets(AZStd::list<Data::Instance<HairRenderObject>>& hairObjects);
  41. //! The following will be called when an object was added or shader has been compiled
  42. void SchedulePacketBuild(HairRenderObject* hairObject);
  43. Data::Instance<RPI::Shader> GetShader();
  44. void SetFeatureProcessor(HairFeatureProcessor* featureProcessor)
  45. {
  46. m_featureProcessor = featureProcessor;
  47. }
  48. virtual bool IsEnabled() const override;
  49. protected:
  50. explicit HairGeometryRasterPass(const RPI::PassDescriptor& descriptor);
  51. // ShaderReloadNotificationBus::Handler overrides...
  52. void OnShaderReinitialized(const RPI::Shader& shader) override;
  53. void OnShaderAssetReinitialized(const Data::Asset<RPI::ShaderAsset>& shaderAsset) override;
  54. void OnShaderVariantReinitialized(const AZ::RPI::ShaderVariant& shaderVariant) override;
  55. void SetShaderPath(const char* shaderPath) { m_shaderPath = shaderPath; }
  56. bool LoadShaderAndPipelineState();
  57. bool AcquireFeatureProcessor();
  58. void BuildShaderAndRenderData();
  59. bool BuildDrawPacket(HairRenderObject* hairObject);
  60. // Pass behavior overrides
  61. void InitializeInternal() override;
  62. void FrameBeginInternal(FramePrepareParams params) override;
  63. // Scope producer functions...
  64. void CompileResources(const RHI::FrameGraphCompileContext& context) override;
  65. //! Updates the shader variant being used by the pass
  66. bool UpdateShaderOptions(const RPI::ShaderVariantId& variantId);
  67. protected:
  68. HairFeatureProcessor* m_featureProcessor = nullptr;
  69. // The shader that will be used by the pass
  70. Data::Instance<RPI::Shader> m_shader = nullptr;
  71. // Override the following in the inherited class
  72. AZStd::string m_shaderPath = "dummyShaderPath";
  73. // To help create the pipeline state
  74. RPI::PassDescriptor m_passDescriptor;
  75. const RHI::PipelineState* m_pipelineState = nullptr;
  76. RPI::ViewPtr m_currentView = nullptr;
  77. AZStd::mutex m_mutex;
  78. //! List of new render objects introduced this frame so that their in order to identify
  79. //! that their PerObject (dynamic) Srg needs binding to the resources.
  80. //! Done once per every new object introduced / requires update.
  81. AZStd::unordered_set<HairRenderObject*> m_newRenderObjects;
  82. bool m_initialized = false;
  83. RPI::ShaderVariantId m_currentShaderVariantId;
  84. };
  85. } // namespace Hair
  86. } // namespace Render
  87. } // namespace AZ