SunShaftsFeatureProcessor.cpp 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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.Reflect/Asset/AssetUtils.h>
  10. #include <Atom/RPI.Public/RenderPipeline.h>
  11. #include <Atom/RPI.Public/Pass/PassFilter.h>
  12. #include <Atom/RPI.Public/Pass/PassSystemInterface.h>
  13. #include "SunShaftsFeatureProcessor.h"
  14. namespace ROSConDemo
  15. {
  16. SunShaftsFeatureProcessor::SunShaftsFeatureProcessor()
  17. {
  18. }
  19. SunShaftsFeatureProcessor::~SunShaftsFeatureProcessor()
  20. {
  21. }
  22. void SunShaftsFeatureProcessor::Reflect(AZ::ReflectContext* context)
  23. {
  24. if (auto* serializeContext = azrtti_cast<AZ::SerializeContext*>(context))
  25. {
  26. serializeContext
  27. ->Class<SunShaftsFeatureProcessor, AZ::RPI::FeatureProcessor>()
  28. ->Version(1);
  29. }
  30. }
  31. void SunShaftsFeatureProcessor::Activate()
  32. {
  33. EnableSceneNotification();
  34. }
  35. void SunShaftsFeatureProcessor::Deactivate()
  36. {
  37. DisableSceneNotification();
  38. }
  39. void AddPassRequestToRenderPipeline(
  40. AZ::RPI::RenderPipeline* renderPipeline,
  41. const char* passRequestAssetFilePath,
  42. const char* referencePass, bool beforeReferencePass)
  43. {
  44. auto passRequestAsset = AZ::RPI::AssetUtils::LoadAssetByProductPath<AZ::RPI::AnyAsset>(
  45. passRequestAssetFilePath, AZ::RPI::AssetUtils::TraceLevel::Warning);
  46. const AZ::RPI::PassRequest* passRequest = nullptr;
  47. if (!passRequestAsset)
  48. {
  49. AZ_Error("SunShafts", false, "Failed to load PassRequestAsset from %s", passRequestAssetFilePath);
  50. return;
  51. }
  52. if (passRequestAsset->IsReady())
  53. {
  54. passRequest = passRequestAsset->GetDataAs<AZ::RPI::PassRequest>();
  55. }
  56. if (!passRequest)
  57. {
  58. AZ_Error("SunShafts", false, "Can't load PassRequest from %s", passRequestAssetFilePath);
  59. return;
  60. }
  61. // Return if the pass to be created already exists
  62. AZ::RPI::PassFilter passFilter = AZ::RPI::PassFilter::CreateWithPassName(passRequest->m_passName, renderPipeline);
  63. AZ::RPI::Pass* existingPass = AZ::RPI::PassSystemInterface::Get()->FindFirstPass(passFilter);
  64. if (existingPass)
  65. {
  66. return;
  67. }
  68. // Create the pass
  69. AZ::RPI::Ptr<AZ::RPI::Pass> newPass = AZ::RPI::PassSystemInterface::Get()->CreatePassFromRequest(passRequest);
  70. if (!newPass)
  71. {
  72. AZ_Error("SunShafts", false, "Failed to create the pass from pass request [%s].", passRequest->m_passName.GetCStr());
  73. return;
  74. }
  75. // Add the pass to render pipeline
  76. bool success;
  77. if (beforeReferencePass)
  78. {
  79. success = renderPipeline->AddPassBefore(newPass, AZ::Name(referencePass));
  80. }
  81. else
  82. {
  83. success = renderPipeline->AddPassAfter(newPass, AZ::Name(referencePass));
  84. }
  85. // only create pass resources if it was success
  86. if (!success)
  87. {
  88. AZ_Error(
  89. "SunShafts", false, "Failed to add pass [%s] to render pipeline [%s].", newPass->GetName().GetCStr(),
  90. renderPipeline->GetId().GetCStr());
  91. }
  92. }
  93. void SunShaftsFeatureProcessor::ApplyRenderPipelineChange(AZ::RPI::RenderPipeline* renderPipeline)
  94. {
  95. AddPassRequestToRenderPipeline(renderPipeline, "Passes/SunShaftsFullScreenPassRequest.azasset", "SkyBoxPass", /*before*/ true);
  96. }
  97. void SunShaftsFeatureProcessor::Simulate(const FeatureProcessor::SimulatePacket& packet)
  98. {
  99. AZ_PROFILE_FUNCTION(AzRender);
  100. AZ_UNUSED(packet);
  101. }
  102. void SunShaftsFeatureProcessor::Render([[maybe_unused]] const FeatureProcessor::RenderPacket& packet)
  103. {
  104. AZ_PROFILE_FUNCTION(AzRender);
  105. }
  106. void SunShaftsFeatureProcessor::OnRenderPipelineAdded([[maybe_unused]] AZ::RPI::RenderPipelinePtr renderPipeline)
  107. {
  108. }
  109. void SunShaftsFeatureProcessor::OnRenderPipelineRemoved([[maybe_unused]] AZ::RPI::RenderPipeline* renderPipeline)
  110. {
  111. }
  112. void SunShaftsFeatureProcessor::OnRenderPipelinePassesChanged([[maybe_unused]] AZ::RPI::RenderPipeline* renderPipeline)
  113. {
  114. }
  115. } // namespace ROSConDemo
  116. //#pragma optimize("", on)