EditorPhysicalSkyComponent.cpp 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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 <SkyBox/EditorPhysicalSkyComponent.h>
  9. #include <AzCore/RTTI/BehaviorContext.h>
  10. namespace AZ
  11. {
  12. namespace Render
  13. {
  14. void EditorPhysicalSkyComponent::Reflect(AZ::ReflectContext* context)
  15. {
  16. BaseClass::Reflect(context);
  17. if (AZ::SerializeContext* serializeContext = azrtti_cast<AZ::SerializeContext*>(context))
  18. {
  19. serializeContext->Class<EditorPhysicalSkyComponent, BaseClass>()
  20. ->Version(1, ConvertToEditorRenderComponentAdapter<1>);
  21. if (AZ::EditContext* editContext = serializeContext->GetEditContext())
  22. {
  23. editContext->Class<EditorPhysicalSkyComponent>(
  24. "Physical Sky", "Physical Sky render the background of your scene with physical simulation")
  25. ->ClassElement(AZ::Edit::ClassElements::EditorData, "")
  26. ->Attribute(AZ::Edit::Attributes::Category, "Graphics/Environment")
  27. ->Attribute(AZ::Edit::Attributes::Icon, "Icons/Components/Component_Placeholder.svg")
  28. ->Attribute(AZ::Edit::Attributes::ViewportIcon, "Icons/Components/Viewport/Component_Placeholder.svg")
  29. ->Attribute(AZ::Edit::Attributes::AppearsInAddComponentMenu, AZ_CRC_CE("Game"))
  30. ->Attribute(AZ::Edit::Attributes::AutoExpand, true)
  31. ->Attribute(AZ::Edit::Attributes::HelpPageURL, "https://o3de.org/docs/user-guide/components/reference/atom/physical-sky/")
  32. ;
  33. editContext->Class<PhysicalSkyComponentController>(
  34. "PhysicalSkyComponentController", "")
  35. ->ClassElement(AZ::Edit::ClassElements::EditorData, "")
  36. ->Attribute(AZ::Edit::Attributes::AutoExpand, true)
  37. ->DataElement(AZ::Edit::UIHandlers::Default, &PhysicalSkyComponentController::m_configuration, "Configuration", "")
  38. ->Attribute(AZ::Edit::Attributes::Visibility, AZ::Edit::PropertyVisibility::ShowChildrenOnly)
  39. ;
  40. editContext->Class<PhysicalSkyComponentConfig>(
  41. "PhysicalSkyComponentConfig", "")
  42. ->ClassElement(AZ::Edit::ClassElements::EditorData, "")
  43. ->DataElement(Edit::UIHandlers::ComboBox, &PhysicalSkyComponentConfig::m_intensityMode, "Intensity Mode", "Specifying the light unit")
  44. ->EnumAttribute(PhotometricUnit::Ev100Luminance, "Ev100")
  45. ->EnumAttribute(PhotometricUnit::Nit, "Nit")
  46. ->DataElement(AZ::Edit::UIHandlers::Slider, &PhysicalSkyComponentConfig::m_skyIntensity, "Sky Intensity", "Brightness of the sky")
  47. ->Attribute(AZ::Edit::Attributes::Min, &PhysicalSkyComponentConfig::GetSkyIntensityMin)
  48. ->Attribute(AZ::Edit::Attributes::Max, &PhysicalSkyComponentConfig::GetSkyIntensityMax)
  49. ->Attribute(Edit::Attributes::Suffix, &PhysicalSkyComponentConfig::GetIntensitySuffix)
  50. ->DataElement(AZ::Edit::UIHandlers::Slider, &PhysicalSkyComponentConfig::m_sunIntensity, "Sun Intensity", "Brightness of the sun")
  51. ->Attribute(AZ::Edit::Attributes::Min, &PhysicalSkyComponentConfig::GetSunIntensityMin)
  52. ->Attribute(AZ::Edit::Attributes::Max, &PhysicalSkyComponentConfig::GetSunIntensityMax)
  53. ->Attribute(Edit::Attributes::Suffix, &PhysicalSkyComponentConfig::GetIntensitySuffix)
  54. ->DataElement(AZ::Edit::UIHandlers::Slider, &PhysicalSkyComponentConfig::m_sunRadiusFactor, "Sun Radius Factor", "A factor for Physical sun radius in millions of km. 1 unit is 695,508 km")
  55. ->Attribute(AZ::Edit::Attributes::Min, 0.1f)
  56. ->Attribute(AZ::Edit::Attributes::Max, 2.f)
  57. ->DataElement(AZ::Edit::UIHandlers::Slider, &PhysicalSkyComponentConfig::m_turbidity, "Turbidity", "A measure of the aerosol content in the air. Default is 1.")
  58. ->Attribute(AZ::Edit::Attributes::Min, 1)
  59. ->Attribute(AZ::Edit::Attributes::Max, 10)
  60. ->Attribute(AZ::Edit::Attributes::Step, 1)
  61. ->DataElement(AZ::Edit::UIHandlers::Default, &PhysicalSkyComponentConfig::m_skyBoxFogSettings, "Fog", "Fog settings for rendering on top of physical sky")
  62. ->Attribute(AZ::Edit::Attributes::AutoExpand, true)
  63. ;
  64. }
  65. }
  66. if (auto behaviorContext = azrtti_cast<BehaviorContext*>(context))
  67. {
  68. behaviorContext->Class<EditorPhysicalSkyComponent>()
  69. ->RequestBus("PhysicalSkyRequestBus")
  70. ->RequestBus("SkyBoxFogRequestBus");
  71. behaviorContext->ConstantProperty("EditorPhysicalSkyComponentTypeId", BehaviorConstant(Uuid(EditorPhysicalSkyComponentTypeId)))
  72. ->Attribute(AZ::Script::Attributes::Module, "render")
  73. ->Attribute(AZ::Script::Attributes::Scope, AZ::Script::Attributes::ScopeFlags::Automation);
  74. }
  75. }
  76. EditorPhysicalSkyComponent::EditorPhysicalSkyComponent(const PhysicalSkyComponentConfig& config)
  77. : BaseClass(config)
  78. {
  79. }
  80. u32 EditorPhysicalSkyComponent::OnConfigurationChanged()
  81. {
  82. // If the intensity mode changes in the editor, convert the photometric value and update the intensity
  83. if (m_controller.m_configuration.m_intensityMode != m_controller.m_skyPhotometricValue.GetType())
  84. {
  85. m_controller.m_skyPhotometricValue.ConvertToPhotometricUnit(m_controller.m_configuration.m_intensityMode);
  86. m_controller.m_configuration.m_skyIntensity = m_controller.m_skyPhotometricValue.GetIntensity();
  87. m_controller.m_sunPhotometricValue.ConvertToPhotometricUnit(m_controller.m_configuration.m_intensityMode);
  88. m_controller.m_configuration.m_sunIntensity = m_controller.m_sunPhotometricValue.GetIntensity();
  89. }
  90. BaseClass::OnConfigurationChanged();
  91. return Edit::PropertyRefreshLevels::AttributesAndValues;
  92. }
  93. }
  94. }