DiffuseProbeGridSystemComponent.cpp 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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. #include <AzCore/Serialization/SerializeContext.h>
  9. #include <Atom/RPI.Public/Pass/PassSystemInterface.h>
  10. #include <Atom/RPI.Public/FeatureProcessorFactory.h>
  11. #include <Components/DiffuseProbeGridSystemComponent.h>
  12. #include <Components/DiffuseProbeGridComponentController.h>
  13. #include <Render/DiffuseProbeGridFeatureProcessor.h>
  14. #include <Render/DiffuseGlobalIlluminationFeatureProcessor.h>
  15. #include <Render/DiffuseProbeGridBlendDistancePass.h>
  16. #include <Render/DiffuseProbeGridBlendIrradiancePass.h>
  17. #include <Render/DiffuseProbeGridBorderUpdatePass.h>
  18. #include <Render/DiffuseProbeGridClassificationPass.h>
  19. #include <Render/DiffuseProbeGridDownsamplePass.h>
  20. #include <Render/DiffuseProbeGridPreparePass.h>
  21. #include <Render/DiffuseProbeGridQueryPass.h>
  22. #include <Render/DiffuseProbeGridQueryFullscreenPass.h>
  23. #include <Render/DiffuseProbeGridQueryFullscreenPassData.h>
  24. #include <Render/DiffuseProbeGridRayTracingPass.h>
  25. #include <Render/DiffuseProbeGridRelocationPass.h>
  26. #include <Render/DiffuseProbeGridRenderPass.h>
  27. #include <Render/DiffuseProbeGridVisualizationAccelerationStructurePass.h>
  28. #include <Render/DiffuseProbeGridVisualizationCompositePass.h>
  29. #include <Render/DiffuseProbeGridVisualizationPreparePass.h>
  30. #include <Render/DiffuseProbeGridVisualizationRayTracingPass.h>
  31. namespace AZ
  32. {
  33. namespace Render
  34. {
  35. void DiffuseProbeGridSystemComponent::Reflect(ReflectContext* context)
  36. {
  37. if (SerializeContext* serialize = azrtti_cast<SerializeContext*>(context))
  38. {
  39. serialize->Class<DiffuseProbeGridSystemComponent, Component>()
  40. ->Version(0)
  41. ;
  42. }
  43. DiffuseProbeGridFeatureProcessor::Reflect(context);
  44. DiffuseGlobalIlluminationFeatureProcessor::Reflect(context);
  45. DiffuseProbeGridQueryFullscreenPassData::Reflect(context);
  46. }
  47. void DiffuseProbeGridSystemComponent::GetProvidedServices(ComponentDescriptor::DependencyArrayType& provided)
  48. {
  49. provided.push_back(AZ_CRC_CE("DiffuseProbeGrid"));
  50. provided.push_back(AZ_CRC_CE("DiffuseGlobalIllumination"));
  51. }
  52. void DiffuseProbeGridSystemComponent::GetIncompatibleServices(ComponentDescriptor::DependencyArrayType& incompatible)
  53. {
  54. incompatible.push_back(AZ_CRC_CE("DiffuseProbeGrid"));
  55. incompatible.push_back(AZ_CRC_CE("DiffuseGlobalIllumination"));
  56. }
  57. void DiffuseProbeGridSystemComponent::GetRequiredServices(ComponentDescriptor::DependencyArrayType& required)
  58. {
  59. required.push_back(AZ_CRC_CE("RPISystem"));
  60. }
  61. void DiffuseProbeGridSystemComponent::LoadPassTemplateMappings()
  62. {
  63. auto* passSystem = RPI::PassSystemInterface::Get();
  64. AZ_Assert(passSystem, "PassSystemInterface is null");
  65. const char* passTemplatesFile = "Passes/DiffuseProbeGridTemplates.azasset";
  66. passSystem->LoadPassTemplateMappings(passTemplatesFile);
  67. }
  68. void DiffuseProbeGridSystemComponent::Activate()
  69. {
  70. // register feature processors
  71. RPI::FeatureProcessorFactory::Get()->RegisterFeatureProcessor<DiffuseProbeGridFeatureProcessor>();
  72. RPI::FeatureProcessorFactory::Get()->RegisterFeatureProcessor<DiffuseGlobalIlluminationFeatureProcessor>();
  73. auto* passSystem = RPI::PassSystemInterface::Get();
  74. AZ_Assert(passSystem, "PassSystemInterface is null");
  75. // setup handler for pass templates mappings
  76. m_loadTemplatesHandler = RPI::PassSystemInterface::OnReadyLoadTemplatesEvent::Handler([this]() { this->LoadPassTemplateMappings(); });
  77. passSystem->ConnectEvent(m_loadTemplatesHandler);
  78. // load the DiffuseProbeGrid pass classes
  79. passSystem->AddPassCreator(Name("DiffuseProbeGridPreparePass"), &DiffuseProbeGridPreparePass::Create);
  80. passSystem->AddPassCreator(Name("DiffuseProbeGridRayTracingPass"), &DiffuseProbeGridRayTracingPass::Create);
  81. passSystem->AddPassCreator(Name("DiffuseProbeGridBlendIrradiancePass"), &DiffuseProbeGridBlendIrradiancePass::Create);
  82. passSystem->AddPassCreator(Name("DiffuseProbeGridBlendDistancePass"), &DiffuseProbeGridBlendDistancePass::Create);
  83. passSystem->AddPassCreator(Name("DiffuseProbeGridBorderUpdatePass"), &DiffuseProbeGridBorderUpdatePass::Create);
  84. passSystem->AddPassCreator(Name("DiffuseProbeGridRelocationPass"), &DiffuseProbeGridRelocationPass::Create);
  85. passSystem->AddPassCreator(Name("DiffuseProbeGridClassificationPass"), &DiffuseProbeGridClassificationPass::Create);
  86. passSystem->AddPassCreator(Name("DiffuseProbeGridDownsamplePass"), &DiffuseProbeGridDownsamplePass::Create);
  87. passSystem->AddPassCreator(Name("DiffuseProbeGridRenderPass"), &DiffuseProbeGridRenderPass::Create);
  88. passSystem->AddPassCreator(Name("DiffuseProbeGridVisualizationPreparePass"), &DiffuseProbeGridVisualizationPreparePass::Create);
  89. passSystem->AddPassCreator(Name("DiffuseProbeGridVisualizationAccelerationStructurePass"), &DiffuseProbeGridVisualizationAccelerationStructurePass::Create);
  90. passSystem->AddPassCreator(Name("DiffuseProbeGridVisualizationRayTracingPass"), &DiffuseProbeGridVisualizationRayTracingPass::Create);
  91. passSystem->AddPassCreator(Name("DiffuseProbeGridVisualizationCompositePass"), &DiffuseProbeGridVisualizationCompositePass::Create);
  92. passSystem->AddPassCreator(Name("DiffuseProbeGridQueryPass"), &DiffuseProbeGridQueryPass::Create);
  93. passSystem->AddPassCreator(Name("DiffuseProbeGridQueryFullscreenPass"), &DiffuseProbeGridQueryFullscreenPass::Create);
  94. }
  95. void DiffuseProbeGridSystemComponent::Deactivate()
  96. {
  97. RPI::FeatureProcessorFactory::Get()->UnregisterFeatureProcessor<DiffuseProbeGridFeatureProcessor>();
  98. RPI::FeatureProcessorFactory::Get()->UnregisterFeatureProcessor<DiffuseGlobalIlluminationFeatureProcessor>();
  99. m_loadTemplatesHandler.Disconnect();
  100. }
  101. }
  102. }