EditorSsaoComponent.cpp 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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/RTTI/BehaviorContext.h>
  9. #include <PostProcess/Ssao/EditorSsaoComponent.h>
  10. namespace AZ
  11. {
  12. namespace Render
  13. {
  14. void EditorSsaoComponent::Reflect(AZ::ReflectContext* context)
  15. {
  16. BaseClass::Reflect(context);
  17. if (AZ::SerializeContext* serializeContext = azrtti_cast<AZ::SerializeContext*>(context))
  18. {
  19. serializeContext->Class<EditorSsaoComponent, BaseClass>()
  20. ->Version(2);
  21. if (AZ::EditContext* editContext = serializeContext->GetEditContext())
  22. {
  23. editContext->Class<EditorSsaoComponent>(
  24. "SSAO", "Controls SSAO.")
  25. ->ClassElement(Edit::ClassElements::EditorData, "")
  26. ->Attribute(Edit::Attributes::Category, "Graphics/PostFX")
  27. ->Attribute(AZ::Edit::Attributes::Icon, "Icons/Components/Component_Placeholder.svg") // [GFX TODO ATOM-2672][PostFX] need to create icons for PostProcessing.
  28. ->Attribute(AZ::Edit::Attributes::ViewportIcon, "Icons/Components/Viewport/Component_Placeholder.svg") // [GFX TODO ATOM-2672][PostFX] need to create icons for PostProcessing.
  29. ->Attribute(Edit::Attributes::AppearsInAddComponentMenu, AZ_CRC_CE("Game"))
  30. ->Attribute(Edit::Attributes::AutoExpand, true)
  31. ->Attribute(Edit::Attributes::HelpPageURL, "https://o3de.org/docs/user-guide/components/reference/atom/ssao/") // [GFX TODO][ATOM-2672][PostFX] need create page for PostProcessing.
  32. ;
  33. editContext->Class<SsaoComponentController>(
  34. "SsaoComponentController", "")
  35. ->ClassElement(AZ::Edit::ClassElements::EditorData, "")
  36. ->Attribute(AZ::Edit::Attributes::AutoExpand, true)
  37. ->DataElement(AZ::Edit::UIHandlers::Default, &SsaoComponentController::m_configuration, "Configuration", "")
  38. ->Attribute(AZ::Edit::Attributes::Visibility, AZ::Edit::PropertyVisibility::ShowChildrenOnly)
  39. ;
  40. editContext->Class<SsaoComponentConfig>("SsaoComponentConfig", "")
  41. ->ClassElement(Edit::ClassElements::EditorData, "")
  42. ->DataElement(Edit::UIHandlers::CheckBox,
  43. &SsaoComponentConfig::m_enabled,
  44. "Enable SSAO",
  45. "Enable SSAO.")
  46. ->DataElement(Edit::UIHandlers::Slider, &SsaoComponentConfig::m_strength,
  47. "SSAO Strength",
  48. "Multiplier for how much strong SSAO appears.")
  49. ->Attribute(Edit::Attributes::Min, 0.0f)
  50. ->Attribute(Edit::Attributes::Max, 2.0f)
  51. ->DataElement(Edit::UIHandlers::Slider, &SsaoComponentConfig::m_samplingRadius,
  52. "Sampling Radius",
  53. "The sampling radius of the SSAO effect in screen UV space")
  54. ->Attribute(Edit::Attributes::Min, 0.0f)
  55. ->Attribute(Edit::Attributes::Max, 0.25f)
  56. ->DataElement(Edit::UIHandlers::CheckBox,
  57. &SsaoComponentConfig::m_enableBlur,
  58. "Enable Blur",
  59. "Enables SSAO Blur")
  60. ->DataElement(Edit::UIHandlers::Slider, &SsaoComponentConfig::m_blurConstFalloff,
  61. "Blur Strength",
  62. "Affects how strong the blur is. Recommended value is 0.67")
  63. ->Attribute(Edit::Attributes::Min, 0.0f)
  64. ->Attribute(Edit::Attributes::Max, 0.95f)
  65. ->DataElement(Edit::UIHandlers::Slider, &SsaoComponentConfig::m_blurDepthFalloffStrength,
  66. "Blur Sharpness",
  67. "Affects how sharp the SSAO blur appears around edges. Recommended value is 50")
  68. ->Attribute(Edit::Attributes::Min, 0.0f)
  69. ->Attribute(Edit::Attributes::Max, 400.0f)
  70. ->DataElement(Edit::UIHandlers::Slider, &SsaoComponentConfig::m_blurDepthFalloffThreshold,
  71. "Blur Edge Threshold",
  72. "Affects the threshold needed for the blur algorithm to detect an edge. Recommended to be left at 0.")
  73. ->Attribute(Edit::Attributes::Min, 0.0f)
  74. ->Attribute(Edit::Attributes::Max, 1.0f)
  75. ->DataElement(Edit::UIHandlers::CheckBox,
  76. &SsaoComponentConfig::m_enableDownsample,
  77. "Enable Downsample",
  78. "Enables depth downsampling before SSAO. Slightly lower quality but 2x as fast as regular SSAO.")
  79. // Overrides
  80. ->ClassElement(AZ::Edit::ClassElements::Group, "Overrides")
  81. ->Attribute(AZ::Edit::Attributes::AutoExpand, false)
  82. // Auto-gen editor context settings for overrides
  83. #define EDITOR_CLASS SsaoComponentConfig
  84. #include <Atom/Feature/ParamMacros/StartOverrideEditorContext.inl>
  85. #include <Atom/Feature/PostProcess/Ssao/SsaoParams.inl>
  86. #include <Atom/Feature/ParamMacros/EndParams.inl>
  87. #undef EDITOR_CLASS
  88. ;
  89. }
  90. }
  91. if (auto behaviorContext = azrtti_cast<BehaviorContext*>(context))
  92. {
  93. behaviorContext->Class<EditorSsaoComponent>()->RequestBus("SsaoRequestBus");
  94. behaviorContext->ConstantProperty("EditorSsaoComponentTypeId", BehaviorConstant(Uuid(Ssao::EditorSsaoComponentTypeId)))
  95. ->Attribute(AZ::Script::Attributes::Module, "render")
  96. ->Attribute(AZ::Script::Attributes::Scope, AZ::Script::Attributes::ScopeFlags::Automation);
  97. }
  98. }
  99. EditorSsaoComponent::EditorSsaoComponent(const SsaoComponentConfig& config)
  100. : BaseClass(config)
  101. {
  102. }
  103. u32 EditorSsaoComponent::OnConfigurationChanged()
  104. {
  105. m_controller.OnConfigChanged();
  106. return Edit::PropertyRefreshLevels::AttributesAndValues;
  107. }
  108. }
  109. }