EditorCubeMapCaptureComponent.cpp 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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 <CubeMapCapture/EditorCubeMapCaptureComponent.h>
  9. namespace AZ
  10. {
  11. namespace Render
  12. {
  13. void EditorCubeMapCaptureComponent::Reflect(AZ::ReflectContext* context)
  14. {
  15. BaseClass::Reflect(context);
  16. if (AZ::SerializeContext* serializeContext = azrtti_cast<AZ::SerializeContext*>(context))
  17. {
  18. serializeContext->Class<EditorCubeMapCaptureComponent, BaseClass>()
  19. ->Version(1, ConvertToEditorRenderComponentAdapter<1>);
  20. if (AZ::EditContext* editContext = serializeContext->GetEditContext())
  21. {
  22. editContext->Class<EditorCubeMapCaptureComponent>(
  23. "CubeMap Capture", "The CubeMap Capture component captures a specular or diffuse cubemap at a specific position in the level")
  24. ->ClassElement(AZ::Edit::ClassElements::EditorData, "")
  25. ->Attribute(AZ::Edit::Attributes::Category, "Graphics/Lighting")
  26. ->Attribute(AZ::Edit::Attributes::Icon, "Icons/Components/Component_Placeholder.svg")
  27. ->Attribute(AZ::Edit::Attributes::ViewportIcon, "Icons/Components/Viewport/Component_Placeholder.svg")
  28. ->Attribute(AZ::Edit::Attributes::AppearsInAddComponentMenu, AZ_CRC_CE("Game"))
  29. ->Attribute(AZ::Edit::Attributes::AutoExpand, true)
  30. ->Attribute(AZ::Edit::Attributes::Visibility, AZ::Edit::PropertyVisibility::ShowChildrenOnly)
  31. ->UIElement(AZ::Edit::UIHandlers::Button, "Capture CubeMap", "Capture CubeMap")
  32. ->Attribute(AZ::Edit::Attributes::NameLabelOverride, "")
  33. ->Attribute(AZ::Edit::Attributes::ButtonText, "Capture CubeMap")
  34. ->Attribute(AZ::Edit::Attributes::ChangeNotify, &EditorCubeMapCaptureComponent::CaptureCubeMap)
  35. ;
  36. editContext->Class<CubeMapCaptureComponentController>(
  37. "CubeMapCaptureComponentController", "")
  38. ->ClassElement(AZ::Edit::ClassElements::EditorData, "")
  39. ->Attribute(AZ::Edit::Attributes::AutoExpand, true)
  40. ->DataElement(AZ::Edit::UIHandlers::Default, &CubeMapCaptureComponentController::m_configuration, "Configuration", "")
  41. ->Attribute(AZ::Edit::Attributes::Visibility, AZ::Edit::PropertyVisibility::ShowChildrenOnly)
  42. ;
  43. editContext->Class<CubeMapCaptureComponentConfig>(
  44. "CubeMapCaptureComponentConfig", "")
  45. ->ClassElement(AZ::Edit::ClassElements::EditorData, "")
  46. ->Attribute(AZ::Edit::Attributes::AutoExpand, true)
  47. ->DataElement(AZ::Edit::UIHandlers::Slider, &CubeMapCaptureComponentConfig::m_exposure, "Exposure", "Exposure to use when capturing the cubemap")
  48. ->Attribute(AZ::Edit::Attributes::SoftMin, -16.0f)
  49. ->Attribute(AZ::Edit::Attributes::SoftMax, 16.0f)
  50. ->Attribute(AZ::Edit::Attributes::Min, -20.0f)
  51. ->Attribute(AZ::Edit::Attributes::Max, 20.0f)
  52. ->DataElement(AZ::Edit::UIHandlers::ComboBox, &CubeMapCaptureComponentConfig::m_captureType, "Capture Type", "The type of cubemap to capture")
  53. ->EnumAttribute(CubeMapCaptureType::Specular, "Specular IBL")
  54. ->EnumAttribute(CubeMapCaptureType::Diffuse, "Diffuse IBL")
  55. ->Attribute(AZ::Edit::Attributes::ChangeNotify, &CubeMapCaptureComponentConfig::OnCaptureTypeChanged)
  56. ->DataElement(AZ::Edit::UIHandlers::ComboBox, &CubeMapCaptureComponentConfig::m_specularQualityLevel, "Specular IBL CubeMap Quality", "Resolution of the Specular IBL cubemap")
  57. ->Attribute(AZ::Edit::Attributes::Visibility, &CubeMapCaptureComponentConfig::GetSpecularQualityVisibilitySetting)
  58. ->Attribute(AZ::Edit::Attributes::ChangeNotify, &CubeMapCaptureComponentConfig::OnSpecularQualityChanged)
  59. ->EnumAttribute(CubeMapSpecularQualityLevel::VeryLow, "Very Low")
  60. ->EnumAttribute(CubeMapSpecularQualityLevel::Low, "Low")
  61. ->EnumAttribute(CubeMapSpecularQualityLevel::Medium, "Medium")
  62. ->EnumAttribute(CubeMapSpecularQualityLevel::High, "High")
  63. ->EnumAttribute(CubeMapSpecularQualityLevel::VeryHigh, "Very High")
  64. ->DataElement(AZ::Edit::UIHandlers::MultiLineEdit, &CubeMapCaptureComponentConfig::m_relativePath, "CubeMap Path", "CubeMap Path")
  65. ->Attribute(AZ::Edit::Attributes::ReadOnly, true)
  66. ;
  67. }
  68. }
  69. if (auto behaviorContext = azrtti_cast<BehaviorContext*>(context))
  70. {
  71. behaviorContext->EBus<EditorCubeMapCaptureBus>("EditorCubeMapCaptureBus")
  72. ->Attribute(AZ::Script::Attributes::Scope, AZ::Script::Attributes::ScopeFlags::Common)
  73. ->Attribute(AZ::Script::Attributes::Module, "render")
  74. ->Event("CaptureCubeMap", &EditorCubeMapCaptureInterface::CaptureCubeMap)
  75. ;
  76. behaviorContext->ConstantProperty("EditorCubeMapCaptureComponentTypeId", BehaviorConstant(Uuid(EditorCubeMapCaptureComponentTypeId)))
  77. ->Attribute(AZ::Script::Attributes::Module, "render")
  78. ->Attribute(AZ::Script::Attributes::Scope, AZ::Script::Attributes::ScopeFlags::Automation);
  79. }
  80. }
  81. EditorCubeMapCaptureComponent::EditorCubeMapCaptureComponent(const CubeMapCaptureComponentConfig& config)
  82. : BaseClass(config)
  83. {
  84. }
  85. void EditorCubeMapCaptureComponent::Activate()
  86. {
  87. BaseClass::Activate();
  88. EditorCubeMapCaptureBus::Handler::BusConnect(GetEntityId());
  89. }
  90. void EditorCubeMapCaptureComponent::Deactivate()
  91. {
  92. EditorCubeMapCaptureBus::Handler::BusDisconnect(GetEntityId());
  93. BaseClass::Deactivate();
  94. }
  95. AZ::u32 EditorCubeMapCaptureComponent::CaptureCubeMap()
  96. {
  97. CubeMapCaptureComponentConfig& configuration = m_controller.m_configuration;
  98. AzToolsFramework::ScopedUndoBatch undoBatch("CubeMap Render");
  99. SetDirty();
  100. return RenderCubeMap(
  101. [&](RenderCubeMapCallback callback, AZStd::string& relativePath) { m_controller.RenderCubeMap(callback, relativePath); },
  102. "Capturing Cubemap...",
  103. GetEntity(),
  104. "CubeMapCaptures",
  105. configuration.m_relativePath,
  106. configuration.m_captureType,
  107. configuration.m_specularQualityLevel);
  108. }
  109. } // namespace Render
  110. } // namespace AZ