3
0

RenderDebugFeatureProcessor.cpp 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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 <Debug/RenderDebugFeatureProcessor.h>
  9. #include <Debug/RenderDebugSettings.h>
  10. #include <Atom/RPI.Public/Scene.h>
  11. #include <Atom/RPI.Public/View.h>
  12. #include <Atom/RPI.Public/Shader/ShaderSystemInterface.h>
  13. namespace AZ::Render
  14. {
  15. RenderDebugFeatureProcessor::RenderDebugFeatureProcessor()
  16. {
  17. }
  18. void RenderDebugFeatureProcessor::Reflect(ReflectContext* context)
  19. {
  20. if (auto* serializeContext = azrtti_cast<SerializeContext*>(context))
  21. {
  22. serializeContext
  23. ->Class<RenderDebugFeatureProcessor, RPI::FeatureProcessor>()
  24. ->Version(0);
  25. }
  26. }
  27. //! RenderDebugFeatureProcessorInterface overrides...
  28. RenderDebugSettingsInterface* RenderDebugFeatureProcessor::GetSettingsInterface()
  29. {
  30. return m_settings.get();
  31. }
  32. void RenderDebugFeatureProcessor::OnRenderDebugComponentAdded()
  33. {
  34. ++m_debugComponentCount;
  35. }
  36. void RenderDebugFeatureProcessor::OnRenderDebugComponentRemoved()
  37. {
  38. --m_debugComponentCount;
  39. }
  40. void RenderDebugFeatureProcessor::Activate()
  41. {
  42. m_sceneSrg = GetParentScene()->GetShaderResourceGroup();
  43. m_settings = AZStd::make_unique<RenderDebugSettings>(this);
  44. }
  45. void RenderDebugFeatureProcessor::Deactivate()
  46. {
  47. m_sceneSrg = nullptr;
  48. m_settings = nullptr;
  49. }
  50. void RenderDebugFeatureProcessor::Simulate(const RPI::FeatureProcessor::SimulatePacket& packet)
  51. {
  52. AZ_PROFILE_SCOPE(RPI, "RenderDebugFeatureProcessor: Simulate");
  53. AZ_UNUSED(packet);
  54. if (m_settings)
  55. {
  56. m_settings->Simulate();
  57. }
  58. }
  59. void RenderDebugFeatureProcessor::Render(const RPI::FeatureProcessor::RenderPacket& packet)
  60. {
  61. AZ_PROFILE_SCOPE(RPI, "RenderDebugFeatureProcessor: Render");
  62. AZ_UNUSED(packet);
  63. // Disable debugging if no render debug level component is active
  64. bool debugEnabled = (m_debugComponentCount > 0) && m_settings->GetEnabled();
  65. RPI::ShaderSystemInterface::Get()->SetGlobalShaderOption(m_shaderDebugEnableOptionName, AZ::RPI::ShaderOptionValue{ debugEnabled });
  66. if (m_sceneSrg)
  67. {
  68. m_sceneSrg->SetConstant(m_debuggingEnabledIndex, debugEnabled);
  69. // Material overrides...
  70. m_sceneSrg->SetConstant(m_debugOverrideBaseColorIndex, m_settings->GetMaterialBaseColorOverride());
  71. m_sceneSrg->SetConstant(m_debugOverrideRoughnessIndex, m_settings->GetMaterialRoughnessOverride());
  72. m_sceneSrg->SetConstant(m_debugOverrideMetallicIndex, m_settings->GetMaterialMetallicOverride());
  73. // Debug Light...
  74. Vector3 debugLightIntensity = m_settings->GetDebugLightingColor() * m_settings->GetDebugLightingIntensity();
  75. m_sceneSrg->SetConstant(m_debugLightingIntensityIndex, debugLightIntensity);
  76. float yaw = m_settings->GetDebugLightingAzimuth();
  77. float pitch = m_settings->GetDebugLightingElevation();
  78. yaw = AZ::DegToRad(yaw);
  79. pitch = AZ::DegToRad(pitch);
  80. Transform lightRotation = Transform::CreateRotationZ(yaw) * Transform::CreateRotationX(pitch);
  81. Vector3 lightDirection = lightRotation.GetBasis(1);
  82. m_sceneSrg->SetConstant(m_debugLightingDirectionIndex, lightDirection);
  83. // Debug floats
  84. m_sceneSrg->SetConstant(m_customDebugFloatIndex01, m_settings->GetCustomDebugFloat01());
  85. m_sceneSrg->SetConstant(m_customDebugFloatIndex02, m_settings->GetCustomDebugFloat02());
  86. m_sceneSrg->SetConstant(m_customDebugFloatIndex03, m_settings->GetCustomDebugFloat03());
  87. m_sceneSrg->SetConstant(m_customDebugFloatIndex04, m_settings->GetCustomDebugFloat04());
  88. m_sceneSrg->SetConstant(m_customDebugFloatIndex05, m_settings->GetCustomDebugFloat05());
  89. m_sceneSrg->SetConstant(m_customDebugFloatIndex06, m_settings->GetCustomDebugFloat06());
  90. m_sceneSrg->SetConstant(m_customDebugFloatIndex07, m_settings->GetCustomDebugFloat07());
  91. m_sceneSrg->SetConstant(m_customDebugFloatIndex08, m_settings->GetCustomDebugFloat08());
  92. m_sceneSrg->SetConstant(m_customDebugFloatIndex09, m_settings->GetCustomDebugFloat09());
  93. }
  94. for (const RPI::ViewPtr& view : packet.m_views)
  95. {
  96. if (view->GetUsageFlags() & (RPI::View::UsageFlags::UsageCamera | RPI::View::UsageFlags::UsageReflectiveCubeMap))
  97. {
  98. Data::Instance<RPI::ShaderResourceGroup> viewSrg = view->GetShaderResourceGroup();
  99. if (viewSrg)
  100. {
  101. viewSrg->SetConstant(m_renderDebugOptionsIndex, m_settings->GetRenderDebugOptions());
  102. viewSrg->SetConstant(m_renderDebugViewModeIndex, m_settings->GetRenderDebugViewMode());
  103. }
  104. }
  105. }
  106. }
  107. }