RayTracingAmbientOcclusionPass.h 3.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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 <Atom/RHI/ScopeProducer.h>
  14. #include <Atom/RPI.Public/Pass/RenderPass.h>
  15. #include <Atom/RPI.Public/Buffer/Buffer.h>
  16. #include <Atom/RHI/RayTracingBufferPools.h>
  17. #include <Atom/RHI/RayTracingPipelineState.h>
  18. #include <Atom/RHI/RayTracingShaderTable.h>
  19. #include <Atom/RPI.Public/RPIUtils.h>
  20. #include <Atom/RPI.Public/Shader/ShaderResourceGroup.h>
  21. #include <RayTracing/RayTracingFeatureProcessor.h>
  22. namespace AZ
  23. {
  24. namespace Render
  25. {
  26. //! A pass to generate rays g-buffer for ambient occlusion.
  27. class RayTracingAmbientOcclusionPass final
  28. : public RPI::RenderPass
  29. {
  30. public:
  31. AZ_RPI_PASS(RayTracingAmbientOcclusionPass);
  32. AZ_RTTI(RayTracingAmbientOcclusionPass, "{4E8F814F-F7C4-4788-B793-D7F118992819}", RPI::RenderPass);
  33. AZ_CLASS_ALLOCATOR(RayTracingAmbientOcclusionPass, SystemAllocator, 0);
  34. virtual ~RayTracingAmbientOcclusionPass() override;
  35. //! Creates a RayTracingAmbientOcclusionPass
  36. static RPI::Ptr<RayTracingAmbientOcclusionPass> Create(const RPI::PassDescriptor& descriptor);
  37. //! Get/Set some raytracing ao settings
  38. uint32_t GetRayNumberPerPixel();
  39. void SetRayNumberPerPixel(uint32_t rayNumber);
  40. float GetRayExtentMin();
  41. void SetRayExtentMin(float minT);
  42. float GetRayExtentMax();
  43. void SetRayExtentMax(float maxT);
  44. private:
  45. explicit RayTracingAmbientOcclusionPass(const RPI::PassDescriptor& descriptor);
  46. void CreateRayTracingPipelineState();
  47. // Scope producer functions
  48. void SetupFrameGraphDependencies(RHI::FrameGraphInterface frameGraph) override;
  49. void CompileResources(const RHI::FrameGraphCompileContext& context) override;
  50. void BuildCommandListInternal(const RHI::FrameGraphExecuteContext& context) override;
  51. // Pass overrides
  52. void FrameBeginInternal(FramePrepareParams params) override;
  53. // ray tracing shader and pipeline state
  54. Data::Instance<RPI::Shader> m_rayGenerationShader;
  55. Data::Instance<RPI::Shader> m_missShader;
  56. Data::Instance<RPI::Shader> m_hitShader;
  57. RHI::Ptr<RHI::RayTracingPipelineState> m_rayTracingPipelineState;
  58. // ray tracing shader table
  59. RHI::Ptr<RHI::RayTracingShaderTable> m_rayTracingShaderTable;
  60. // ray tracing global shader resource group asset and pipeline state
  61. Data::Asset<RPI::ShaderResourceGroupAsset> m_globalSrgAsset;
  62. RHI::ConstPtr<RHI::PipelineState> m_globalPipelineState;
  63. Render::RayTracingFeatureProcessor* m_rayTracingFeatureProcessor = nullptr;
  64. uint32_t m_frameCount = 0;
  65. // ray tracing ambient occlusion parameters
  66. float m_rayMaxT = 0.4f; // The ray's far distance
  67. float m_rayMinT = 0.01f; // The ray's near distance
  68. uint32_t m_rayNumber = 8; // Ray casted per pixel
  69. };
  70. } // namespace RPI
  71. } // namespace AZ