EditorDepthOfFieldComponent.cpp 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  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/DepthOfField/EditorDepthOfFieldComponent.h>
  10. namespace AZ
  11. {
  12. namespace Render
  13. {
  14. void EditorDepthOfFieldComponent::Reflect(AZ::ReflectContext* context)
  15. {
  16. BaseClass::Reflect(context);
  17. if (AZ::SerializeContext* serializeContext = azrtti_cast<AZ::SerializeContext*>(context))
  18. {
  19. serializeContext->Class<EditorDepthOfFieldComponent, BaseClass>()
  20. ->Version(2);
  21. if (AZ::EditContext* editContext = serializeContext->GetEditContext())
  22. {
  23. editContext->Class<EditorDepthOfFieldComponent>(
  24. "Depth Of Field", "Controls the Depth of Field.")
  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.y
  29. ->Attribute(Edit::Attributes::AppearsInAddComponentMenu, AZ_CRC_CE("Game"))
  30. ->Attribute(Edit::Attributes::AutoExpand, true)
  31. ->Attribute(Edit::Attributes::HelpPageURL, "https://www.o3de.org/docs/user-guide/components/reference/atom/depth-of-field/") // [GFX TODO][ATOM-2672][PostFX] need create page for PostProcessing.
  32. ;
  33. editContext->Class<DepthOfFieldComponentController>(
  34. "DepthOfFieldComponentController", "")
  35. ->ClassElement(AZ::Edit::ClassElements::EditorData, "")
  36. ->Attribute(AZ::Edit::Attributes::AutoExpand, true)
  37. ->DataElement(AZ::Edit::UIHandlers::Default, &DepthOfFieldComponentController::m_configuration, "Configuration", "")
  38. ->Attribute(AZ::Edit::Attributes::Visibility, AZ::Edit::PropertyVisibility::ShowChildrenOnly)
  39. ;
  40. editContext->Class<DepthOfFieldComponentConfig>("DepthOfFieldComponentConfig", "")
  41. ->ClassElement(Edit::ClassElements::EditorData, "")
  42. ->DataElement(Edit::UIHandlers::EntityId,
  43. &DepthOfFieldComponentConfig::m_cameraEntityId,
  44. "Camera Entity",
  45. "Camera entity. Required by Depth of Field.")
  46. ->Attribute(Edit::Attributes::ChangeNotify, Edit::PropertyRefreshLevels::AttributesAndValues)
  47. ->DataElement(Edit::UIHandlers::CheckBox,
  48. &DepthOfFieldComponentConfig::m_enabled,
  49. "Enable Depth of Field",
  50. "Enable Depth of Field.")
  51. ->Attribute(Edit::Attributes::ChangeNotify, Edit::PropertyRefreshLevels::ValuesOnly)
  52. ->Attribute(Edit::Attributes::ReadOnly, &DepthOfFieldComponentConfig::IsCameraEntityInvalid)
  53. ->DataElement(Edit::UIHandlers::Slider, &DepthOfFieldComponentConfig::m_qualityLevel,
  54. "Quality Level",
  55. "0 : Standard Bokeh blur.\n"
  56. "1 : High quality Bokeh blur (large number of sample)")
  57. ->Attribute(Edit::Attributes::Min, 0)
  58. ->Attribute(Edit::Attributes::Max, DepthOfField::QualityLevelMax - 1)
  59. ->Attribute(Edit::Attributes::Step, 1)
  60. ->Attribute(Edit::Attributes::ChangeNotify, Edit::PropertyRefreshLevels::ValuesOnly)
  61. ->Attribute(Edit::Attributes::ReadOnly, &DepthOfFieldComponentConfig::ArePropertiesReadOnly)
  62. ->DataElement(Edit::UIHandlers::Slider, &DepthOfFieldComponentConfig::m_apertureF,
  63. "Aperture F",
  64. "The higher the value, the larger the opening.")
  65. ->Attribute(Edit::Attributes::Min, 0.0f)
  66. ->Attribute(Edit::Attributes::Max, 1.0f)
  67. ->Attribute(Edit::Attributes::ChangeNotify, Edit::PropertyRefreshLevels::ValuesOnly)
  68. ->Attribute(Edit::Attributes::ReadOnly, &DepthOfFieldComponentConfig::ArePropertiesReadOnly)
  69. ->DataElement(Edit::UIHandlers::Default, &DepthOfFieldComponentConfig::m_fNumber,
  70. "F Number",
  71. "")
  72. ->Attribute(Edit::Attributes::ReadOnly, true)
  73. ->DataElement(Edit::UIHandlers::Default, &DepthOfFieldComponentConfig::m_focusDistance,
  74. "Focus Distance",
  75. "The distance from the camera to the focused subject.")
  76. ->Attribute(Edit::Attributes::Suffix, " m")
  77. ->Attribute(Edit::Attributes::Step, 1.0f)
  78. ->Attribute(Edit::Attributes::ChangeNotify, Edit::PropertyRefreshLevels::ValuesOnly)
  79. ->Attribute(Edit::Attributes::ReadOnly, &DepthOfFieldComponentConfig::IsFocusDistanceReadOnly)
  80. // Auto Focus
  81. ->ClassElement(AZ::Edit::ClassElements::Group, "Auto Focus")
  82. ->Attribute(AZ::Edit::Attributes::AutoExpand, true)
  83. ->DataElement(Edit::UIHandlers::CheckBox,
  84. &DepthOfFieldComponentConfig::m_enableAutoFocus,
  85. "Enable Auto Focus",
  86. "Enables auto focus.")
  87. ->Attribute(Edit::Attributes::ChangeNotify, Edit::PropertyRefreshLevels::AttributesAndValues)
  88. ->Attribute(Edit::Attributes::ReadOnly, &DepthOfFieldComponentConfig::ArePropertiesReadOnly)
  89. ->DataElement(Edit::UIHandlers::Default,
  90. &DepthOfFieldComponentConfig::m_focusedEntityId,
  91. "Focused Entity",
  92. "Entity to focus on.\n"
  93. "If unset, the screen position is used.")
  94. ->Attribute(Edit::Attributes::ChangeNotify, Edit::PropertyRefreshLevels::AttributesAndValues)
  95. ->Attribute(Edit::Attributes::ReadOnly, &DepthOfFieldComponentConfig::IsFocusedEntityReadonly)
  96. ->DataElement(Edit::UIHandlers::Default, &DepthOfFieldComponentConfig::m_autoFocusScreenPosition,
  97. "Focus Screen Position",
  98. "Values of the focus position on screen.")
  99. ->Attribute(Edit::Attributes::Min, 0.0f)
  100. ->Attribute(Edit::Attributes::Max, 1.0f)
  101. ->Attribute(Edit::Attributes::ChangeNotify, Edit::PropertyRefreshLevels::ValuesOnly)
  102. ->Attribute(Edit::Attributes::ReadOnly, &DepthOfFieldComponentConfig::IsAutoFocusReadOnly)
  103. ->DataElement(Edit::UIHandlers::Slider, &DepthOfFieldComponentConfig::m_autoFocusSensitivity,
  104. "Auto Focus Sensitivity",
  105. "Higher value is more responsive.\n"
  106. "Lower value require a greater difference in depth before refocusing.\n"
  107. "Always responds when the value is 1.0.")
  108. ->Attribute(Edit::Attributes::Min, 0.0f)
  109. ->Attribute(Edit::Attributes::Max, 1.0f)
  110. ->Attribute(Edit::Attributes::ChangeNotify, Edit::PropertyRefreshLevels::ValuesOnly)
  111. ->Attribute(Edit::Attributes::ReadOnly, &DepthOfFieldComponentConfig::IsAutoFocusReadOnly)
  112. ->DataElement(Edit::UIHandlers::Slider, &DepthOfFieldComponentConfig::m_autoFocusSpeed,
  113. "Auto Focus Speed",
  114. "Specify the distance that focus moves per second,\n"
  115. "normalizing the distance from view near to view far as 1.0.")
  116. ->Attribute(Edit::Attributes::Min, 0.0f)
  117. ->Attribute(Edit::Attributes::Max, DepthOfField::AutoFocusSpeedMax)
  118. ->Attribute(Edit::Attributes::ChangeNotify, Edit::PropertyRefreshLevels::ValuesOnly)
  119. ->Attribute(Edit::Attributes::ReadOnly, &DepthOfFieldComponentConfig::IsAutoFocusReadOnly)
  120. ->DataElement(Edit::UIHandlers::Slider, &DepthOfFieldComponentConfig::m_autoFocusDelay,
  121. "Auto Focus Delay",
  122. "Specifies a delay time for focus to shift from one to another target.")
  123. ->Attribute(Edit::Attributes::Min, 0.0f)
  124. ->Attribute(Edit::Attributes::Max, DepthOfField::AutoFocusDelayMax)
  125. ->Attribute(AZ::Edit::Attributes::Suffix, "[s]")
  126. ->Attribute(Edit::Attributes::ChangeNotify, Edit::PropertyRefreshLevels::ValuesOnly)
  127. ->Attribute(Edit::Attributes::ReadOnly, &DepthOfFieldComponentConfig::IsAutoFocusReadOnly)
  128. // Debugging
  129. ->ClassElement(AZ::Edit::ClassElements::Group, "Debugging")
  130. ->Attribute(AZ::Edit::Attributes::AutoExpand, false)
  131. ->DataElement(Edit::UIHandlers::CheckBox,
  132. &DepthOfFieldComponentConfig::m_enableDebugColoring,
  133. "Enable Debug Color",
  134. "Enable coloring to see Depth of Field level\n"
  135. "Red - Back large blur\n"
  136. "Orange - Back middle blur\n"
  137. "Yellow - Back small blur\n"
  138. "Green - Focus area\n"
  139. "Blue green - Front small blur\n"
  140. "Blue - Front middle blur\n"
  141. "Purple - Front large blur")
  142. ->Attribute(Edit::Attributes::ChangeNotify, Edit::PropertyRefreshLevels::ValuesOnly)
  143. // Overrides
  144. ->ClassElement(AZ::Edit::ClassElements::Group, "Overrides")
  145. ->Attribute(AZ::Edit::Attributes::AutoExpand, false)
  146. // Auto-gen editor context settings for overrides
  147. #define EDITOR_CLASS DepthOfFieldComponentConfig
  148. #include <Atom/Feature/ParamMacros/StartOverrideEditorContext.inl>
  149. #include <Atom/Feature/PostProcess/DepthOfField/DepthOfFieldParams.inl>
  150. #include <Atom/Feature/ParamMacros/EndParams.inl>
  151. #undef EDITOR_CLASS
  152. ;
  153. }
  154. }
  155. if (auto behaviorContext = azrtti_cast<BehaviorContext*>(context))
  156. {
  157. behaviorContext->Class<EditorDepthOfFieldComponent>()->RequestBus("DepthOfFieldRequestBus");
  158. behaviorContext->ConstantProperty("EditorDepthOfFieldComponentTypeId", BehaviorConstant(Uuid(DepthOfField::EditorDepthOfFieldComponentTypeId)))
  159. ->Attribute(AZ::Script::Attributes::Module, "render")
  160. ->Attribute(AZ::Script::Attributes::Scope, AZ::Script::Attributes::ScopeFlags::Automation);
  161. }
  162. }
  163. EditorDepthOfFieldComponent::EditorDepthOfFieldComponent(const DepthOfFieldComponentConfig& config)
  164. : BaseClass(config)
  165. {
  166. }
  167. u32 EditorDepthOfFieldComponent::OnConfigurationChanged()
  168. {
  169. m_controller.OnConfigChanged();
  170. return Edit::PropertyRefreshLevels::AttributesAndValues;
  171. }
  172. }
  173. }