3
0

CubeMapRenderer.h 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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/Math/Transform.h>
  10. #include <Atom/RPI.Public/Base.h>
  11. #include <Atom/RPI.Public/Pass/Specific/EnvironmentCubeMapPass.h>
  12. #include <Atom/RPI.Public/Scene.h>
  13. namespace AZ
  14. {
  15. namespace Render
  16. {
  17. using RenderCubeMapCallback = AZStd::function<void(uint8_t* const* cubeMapTextureData, const RHI::Format cubeMapTextureFormat)>;
  18. // Mixin class that provides cubemap capture capability
  19. class CubeMapRenderer
  20. {
  21. public:
  22. // starts the cubemap render using the transform as the capture point
  23. void StartRender(RenderCubeMapCallback callback, const AZ::Transform& transform, float exposure);
  24. // called each frame, invokes the callback when rendering is complete
  25. void Update();
  26. // removes the render pipeline from the scene if rendering is complete
  27. // Note: must be called outside of the feature processor Simulate/Render phases
  28. void CheckAndRemovePipeline();
  29. bool IsRenderingCubeMap() const { return m_renderingCubeMap; }
  30. void SetScene(RPI::Scene* scene) { m_scene = scene; }
  31. void SetDefaultView(RPI::RenderPipeline* renderPipeline);
  32. protected:
  33. CubeMapRenderer() = default;
  34. ~CubeMapRenderer() = default;
  35. private:
  36. AZ_DISABLE_COPY_MOVE(CubeMapRenderer);
  37. RPI::Scene* m_scene = nullptr;
  38. float m_exposure = 0.0f;
  39. // render pipeline
  40. RPI::Ptr<RPI::EnvironmentCubeMapPass> m_environmentCubeMapPass = nullptr;
  41. RPI::RenderPipelineId m_environmentCubeMapPipelineId;
  42. RenderCubeMapCallback m_callback;
  43. RHI::ShaderInputNameIndex m_globalIblExposureConstantIndex = "m_iblExposure";
  44. RHI::ShaderInputNameIndex m_skyBoxExposureConstantIndex = "m_cubemapExposure";
  45. float m_previousGlobalIblExposure = 0.0f;
  46. float m_previousSkyBoxExposure = 0.0f;
  47. bool m_renderingCubeMap = false;
  48. };
  49. } // namespace Render
  50. } // namespace AZ