GradientWeightModifierController.cpp 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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 <PostProcess/GradientWeightModifier/GradientWeightModifierController.h>
  9. #include <AzCore/Serialization/SerializeContext.h>
  10. namespace AZ
  11. {
  12. namespace Render
  13. {
  14. void GradientWeightModifierComponentController::Reflect(AZ::ReflectContext* context)
  15. {
  16. GradientWeightModifierComponentConfig::Reflect(context);
  17. if (auto* serializeContext = azrtti_cast<SerializeContext*>(context))
  18. {
  19. serializeContext->Class<GradientWeightModifierComponentController>()
  20. ->Version(0)
  21. ->Field("Configuration", &GradientWeightModifierComponentController::m_configuration);
  22. }
  23. }
  24. void GradientWeightModifierComponentController::GetProvidedServices(AZ::ComponentDescriptor::DependencyArrayType& provided)
  25. {
  26. provided.push_back(AZ_CRC_CE("PostFXWeightModifierService"));
  27. }
  28. void GradientWeightModifierComponentController::GetIncompatibleServices(AZ::ComponentDescriptor::DependencyArrayType& incompatible)
  29. {
  30. incompatible.push_back(AZ_CRC_CE("PostFXWeightModifierService"));
  31. }
  32. void GradientWeightModifierComponentController::GetRequiredServices(AZ::ComponentDescriptor::DependencyArrayType& required)
  33. {
  34. required.push_back(AZ_CRC_CE("PostFXLayerService"));
  35. }
  36. GradientWeightModifierComponentController::GradientWeightModifierComponentController(const GradientWeightModifierComponentConfig& config)
  37. : m_configuration(config)
  38. {
  39. }
  40. void GradientWeightModifierComponentController::Activate(EntityId entityId)
  41. {
  42. m_entityId = entityId;
  43. m_configuration.m_gradientSampler.m_ownerEntityId = entityId;
  44. PostFxWeightRequestBus::Handler::BusConnect(m_entityId);
  45. }
  46. void GradientWeightModifierComponentController::Deactivate()
  47. {
  48. PostFxWeightRequestBus::Handler::BusDisconnect(m_entityId);
  49. m_entityId.SetInvalid();
  50. }
  51. void GradientWeightModifierComponentController::SetConfiguration(const GradientWeightModifierComponentConfig& config)
  52. {
  53. m_configuration = config;
  54. }
  55. float GradientWeightModifierComponentController::GetWeightAtPosition(const AZ::Vector3& influencerPosition) const
  56. {
  57. return m_configuration.m_gradientSampler.GetValue(influencerPosition);
  58. }
  59. }
  60. }