EditorDeferredFogComponent.cpp 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  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 <ScreenSpace/EditorDeferredFogComponent.h>
  10. namespace AZ
  11. {
  12. namespace Render
  13. {
  14. void EditorDeferredFogComponent::Reflect(AZ::ReflectContext* context)
  15. {
  16. BaseClass::Reflect(context);
  17. if (AZ::SerializeContext* serializeContext = azrtti_cast<AZ::SerializeContext*>(context))
  18. {
  19. serializeContext->Class<EditorDeferredFogComponent, BaseClass>()
  20. ->Version(2);
  21. if (AZ::EditContext* editContext = serializeContext->GetEditContext())
  22. {
  23. editContext->Class<EditorDeferredFogComponent>(
  24. "Deferred Fog", "Controls the Deferred Fog")
  25. ->ClassElement(Edit::ClassElements::EditorData, "")
  26. ->Attribute(Edit::Attributes::Category, "Graphics/Environment")
  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://www.o3de.org/docs/user-guide/components/reference/atom/deferred-fog/") // [TODO][ATOM-13427] Create Wiki for Deferred Fog
  32. ;
  33. editContext->Class<DeferredFogComponentController>(
  34. "DeferredFogComponentController", "")
  35. ->ClassElement(AZ::Edit::ClassElements::EditorData, "")
  36. ->Attribute(AZ::Edit::Attributes::AutoExpand, true)
  37. ->DataElement(AZ::Edit::UIHandlers::Default, &DeferredFogComponentController::m_configuration, "Configuration", "")
  38. ->Attribute(AZ::Edit::Attributes::Visibility, AZ::Edit::PropertyVisibility::ShowChildrenOnly)
  39. ;
  40. editContext->Class<DeferredFogComponentConfig>(
  41. "DeferredFogComponentConfig", "")
  42. ->ClassElement(AZ::Edit::ClassElements::EditorData, "")
  43. ->DataElement(Edit::UIHandlers::CheckBox,
  44. &DeferredFogComponentConfig::m_enabled,
  45. "Enable Deferred Fog",
  46. "Enable Deferred Fog.")
  47. ->Attribute(Edit::Attributes::ChangeNotify, Edit::PropertyRefreshLevels::ValuesOnly)
  48. ->DataElement(Edit::UIHandlers::CheckBox, &DeferredFogComponentConfig::m_enableFogLayerShaderOption,
  49. "Enable Fog Layer",
  50. "Enable Fog Layer")
  51. ->Attribute(Edit::Attributes::ChangeNotify, Edit::PropertyRefreshLevels::ValuesOnly)
  52. ->DataElement(Edit::UIHandlers::CheckBox, &DeferredFogComponentConfig::m_useNoiseTextureShaderOption,
  53. "Enable Turbulence Properties",
  54. "Enable Turbulence Properties")
  55. ->Attribute(Edit::Attributes::ChangeNotify, Edit::PropertyRefreshLevels::ValuesOnly)
  56. ->DataElement(AZ::Edit::UIHandlers::Color, &DeferredFogComponentConfig::m_fogColor,
  57. "Fog Color", "The fog color.")
  58. ->Attribute(AZ::Edit::Attributes::ChangeNotify, Edit::PropertyRefreshLevels::ValuesOnly)
  59. ->DataElement(Edit::UIHandlers::ComboBox, &DeferredFogComponentConfig::m_fogMode,
  60. "Fog Mode",
  61. "Which formula to use for calculating the fog.")
  62. ->Attribute(AZ::Edit::Attributes::EnumValues, AZ::Edit::GetEnumConstantsFromTraits<Render::FogMode>())
  63. ->ClassElement(Edit::ClassElements::Group, "Distance")
  64. ->Attribute(Edit::Attributes::AutoExpand, true)
  65. ->DataElement(AZ::Edit::UIHandlers::Slider, &DeferredFogComponentConfig::m_fogStartDistance,
  66. "Fog Start Distance", "The distance from the viewer when the fog starts")
  67. ->Attribute(AZ::Edit::Attributes::Min, 0.0f)
  68. ->Attribute(AZ::Edit::Attributes::Max, 5000.0f)
  69. ->Attribute(AZ::Edit::Attributes::SoftMin, 0.0f)
  70. ->Attribute(AZ::Edit::Attributes::SoftMax, 10.0f)
  71. ->Attribute(AZ::Edit::Attributes::ChangeNotify, Edit::PropertyRefreshLevels::ValuesOnly)
  72. ->DataElement(AZ::Edit::UIHandlers::Slider, &DeferredFogComponentConfig::m_fogEndDistance,
  73. "Fog End Distance", "At what distance from the viewer does the fog take over and mask the background scene out.")
  74. ->Attribute(AZ::Edit::Attributes::Min, &DeferredFogComponentConfig::m_fogStartDistance)
  75. ->Attribute(AZ::Edit::Attributes::Max, 5000.0f)
  76. ->Attribute(AZ::Edit::Attributes::SoftMin, 0.0f)
  77. ->Attribute(AZ::Edit::Attributes::SoftMax, 100.0f)
  78. ->Attribute(AZ::Edit::Attributes::ChangeNotify, Edit::PropertyRefreshLevels::ValuesOnly)
  79. ->Attribute(Edit::Attributes::Visibility, &DeferredFogComponentConfig::SupportsFogEnd)
  80. ->ClassElement(Edit::ClassElements::Group, "Density Control")
  81. ->Attribute(Edit::Attributes::AutoExpand, true)
  82. ->DataElement(AZ::Edit::UIHandlers::Slider, &DeferredFogComponentConfig::m_fogDensity,
  83. "Fog Density",
  84. "Density of the fog that can range from 0.0 to 1.0")
  85. ->Attribute(AZ::Edit::Attributes::Min, 0.0f)
  86. ->Attribute(AZ::Edit::Attributes::Max, 1.0f)
  87. ->Attribute(AZ::Edit::Attributes::SoftMin, 0.0f)
  88. ->Attribute(AZ::Edit::Attributes::SoftMax, 1.0f)
  89. ->Attribute(AZ::Edit::Attributes::ChangeNotify, Edit::PropertyRefreshLevels::ValuesOnly)
  90. ->Attribute(Edit::Attributes::Visibility, &DeferredFogComponentConfig::SupportsFogDensity)
  91. ->DataElement(AZ::Edit::UIHandlers::Slider, &DeferredFogComponentConfig::m_fogDensityClamp,
  92. "Fog Density Clamp",
  93. "The maximum density that the fog can reach. This enables the sky, horizon, and other bright, distant objects to be visible through dense fog.")
  94. ->Attribute(AZ::Edit::Attributes::Min, 0.0f)
  95. ->Attribute(AZ::Edit::Attributes::Max, 1.0f)
  96. ->Attribute(AZ::Edit::Attributes::SoftMin, 0.0f)
  97. ->Attribute(AZ::Edit::Attributes::SoftMax, 1.0f)
  98. ->Attribute(AZ::Edit::Attributes::ChangeNotify, Edit::PropertyRefreshLevels::ValuesOnly)
  99. // Fog layer properties
  100. ->ClassElement(Edit::ClassElements::Group, "Fog Layer")
  101. ->Attribute(Edit::Attributes::AutoExpand, true)
  102. ->Attribute(Edit::Attributes::Visibility, &DeferredFogComponentConfig::GetEnableFogLayerShaderOption)
  103. ->DataElement(AZ::Edit::UIHandlers::Slider, &DeferredFogComponentConfig::m_fogMinHeight,
  104. "Fog Bottom Height", "The height at which the fog layer starts")
  105. ->Attribute(AZ::Edit::Attributes::Min, -5000.0f)
  106. ->Attribute(AZ::Edit::Attributes::Max, 5000.0f)
  107. ->Attribute(AZ::Edit::Attributes::SoftMin, -100.0f)
  108. ->Attribute(AZ::Edit::Attributes::SoftMax, 1000.0f)
  109. ->Attribute(AZ::Edit::Attributes::ChangeNotify, Edit::PropertyRefreshLevels::ValuesOnly)
  110. ->DataElement(AZ::Edit::UIHandlers::Slider, &DeferredFogComponentConfig::m_fogMaxHeight,
  111. "Fog Max Height", "The height of the fog layer top")
  112. ->Attribute(AZ::Edit::Attributes::Min, -5000.0f)
  113. ->Attribute(AZ::Edit::Attributes::Max, 5000.0f)
  114. ->Attribute(AZ::Edit::Attributes::SoftMin, -100.0f)
  115. ->Attribute(AZ::Edit::Attributes::SoftMax, 1000.0f)
  116. ->Attribute(AZ::Edit::Attributes::ChangeNotify, Edit::PropertyRefreshLevels::ValuesOnly)
  117. // Fog turbulence properties
  118. ->ClassElement(Edit::ClassElements::Group, "Turbulence")
  119. ->Attribute(Edit::Attributes::AutoExpand, true)
  120. ->Attribute(Edit::Attributes::Visibility, &DeferredFogComponentConfig::GetUseNoiseTextureShaderOption)
  121. ->DataElement(AZ::Edit::UIHandlers::LineEdit, &DeferredFogComponentConfig::m_noiseTexture,
  122. "Noise Texture", "The noise texture used for creating the fog turbulence")
  123. ->Attribute(AZ::Edit::Attributes::ChangeNotify, Edit::PropertyRefreshLevels::ValuesOnly)
  124. // First noise octave
  125. ->DataElement(AZ::Edit::UIHandlers::Vector2, &DeferredFogComponentConfig::m_noiseScaleUV,
  126. "Noise Texture First Octave Scale", "The scale of the first noise octave - higher indicates higher frequency / repetition")
  127. ->Attribute(AZ::Edit::Attributes::ChangeNotify, Edit::PropertyRefreshLevels::ValuesOnly)
  128. ->DataElement(AZ::Edit::UIHandlers::Vector2, &DeferredFogComponentConfig::m_noiseVelocityUV,
  129. "Noise Texture First Octave Velocity", "The velocity of the first noise octave UV coordinates")
  130. ->Attribute(AZ::Edit::Attributes::ChangeNotify, Edit::PropertyRefreshLevels::ValuesOnly)
  131. // Second noise octave
  132. ->DataElement(AZ::Edit::UIHandlers::Vector2, &DeferredFogComponentConfig::m_noiseScaleUV2,
  133. "Noise Texture Second Octave Scale", "The scale of the second noise octave - higher indicates higher frequency / repetition")
  134. ->Attribute(AZ::Edit::Attributes::ChangeNotify, Edit::PropertyRefreshLevels::ValuesOnly)
  135. ->DataElement(AZ::Edit::UIHandlers::Vector2, &DeferredFogComponentConfig::m_noiseVelocityUV2,
  136. "Noise Texture Second Octave Velocity", "The velocity of the second noise octave UV coordinates")
  137. ->Attribute(AZ::Edit::Attributes::ChangeNotify, Edit::PropertyRefreshLevels::ValuesOnly)
  138. ->DataElement(AZ::Edit::UIHandlers::Slider, &DeferredFogComponentConfig::m_octavesBlendFactor,
  139. "Octaves Blend Factor", "The blend factor between the noise octaves")
  140. ->Attribute(AZ::Edit::Attributes::Min, 0.0f)
  141. ->Attribute(AZ::Edit::Attributes::Max, 1.0f)
  142. ->Attribute(AZ::Edit::Attributes::SoftMin, 0.0f)
  143. ->Attribute(AZ::Edit::Attributes::SoftMax, 1.0f)
  144. ->Attribute(AZ::Edit::Attributes::ChangeNotify, Edit::PropertyRefreshLevels::ValuesOnly)
  145. ;
  146. }
  147. }
  148. if (auto behaviorContext = azrtti_cast<BehaviorContext*>(context))
  149. {
  150. behaviorContext->Class<EditorDeferredFogComponent>()->RequestBus("DeferredFogRequestsBus");
  151. behaviorContext->ConstantProperty("EditorDeferredFogComponentTypeId", BehaviorConstant(Uuid(DeferredFog::EditorDeferredFogComponentTypeId)))
  152. ->Attribute(AZ::Script::Attributes::Module, "render")
  153. ->Attribute(AZ::Script::Attributes::Scope, AZ::Script::Attributes::ScopeFlags::Automation);
  154. }
  155. }
  156. EditorDeferredFogComponent::EditorDeferredFogComponent(const DeferredFogComponentConfig& config)
  157. : BaseClass(config)
  158. {
  159. }
  160. u32 EditorDeferredFogComponent::OnConfigurationChanged()
  161. {
  162. m_controller.OnConfigChanged();
  163. return Edit::PropertyRefreshLevels::AttributesAndValues;
  164. }
  165. }
  166. }