DiffuseProbeGridTextureReadback.h 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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 <Atom/RHI/ScopeProducer.h>
  10. #include <Atom/RPI.Public/Pass/AttachmentReadback.h>
  11. #include <Atom/RPI.Public/Pass/Pass.h>
  12. #include <DiffuseProbeGrid/DiffuseProbeGridFeatureProcessorInterface.h>
  13. namespace AZ
  14. {
  15. namespace Render
  16. {
  17. class DiffuseProbeGrid;
  18. enum class DiffuseProbeGridReadbackState
  19. {
  20. Idle,
  21. Initializing,
  22. Irradiance,
  23. Distance,
  24. ProbeData,
  25. Complete
  26. };
  27. //! This class contains functionality necessary to read back the DiffuseProbeGrid textures, which
  28. //! allows them to be saved as assets to run the DiffuseProbeGrid in non-realtime mode.
  29. class DiffuseProbeGridTextureReadback final
  30. {
  31. public:
  32. DiffuseProbeGridTextureReadback(DiffuseProbeGrid* diffuseProbeGrid);
  33. ~DiffuseProbeGridTextureReadback() = default;
  34. void BeginTextureReadback(DiffuseProbeGridBakeTexturesCallback callback);
  35. void Update(const AZ::Name& passName);
  36. void FrameBegin(AZ::RPI::Pass::FramePrepareParams& params);
  37. bool IsIdle() const { return m_readbackState == DiffuseProbeGridReadbackState::Idle; }
  38. private:
  39. DiffuseProbeGrid* m_diffuseProbeGrid = nullptr;
  40. DiffuseProbeGridReadbackState m_readbackState = DiffuseProbeGridReadbackState::Idle;
  41. AZStd::shared_ptr<AZ::RPI::AttachmentReadback> m_attachmentReadback;
  42. DiffuseProbeGridBakeTexturesCallback m_callback;
  43. AZ::RPI::AttachmentReadback::ReadbackResult m_irradianceReadbackResult;
  44. AZ::RPI::AttachmentReadback::ReadbackResult m_distanceReadbackResult;
  45. AZ::RPI::AttachmentReadback::ReadbackResult m_probeDataReadbackResult;
  46. // number of frames to delay before starting the texture readbacks, this allows the textures to settle
  47. static constexpr int32_t DefaultNumInitializationFrames = 50;
  48. int32_t m_remainingInitializationFrames = DefaultNumInitializationFrames;
  49. };
  50. } // namespace Render
  51. } // namespace AZ