LightingChannelConfiguration.cpp 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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 <Atom/Feature/LightingChannel/LightingChannelConfiguration.h>
  9. #include <AzCore/Serialization/SerializeContext.h>
  10. #include <AzCore/Serialization/EditContext.h>
  11. namespace AZ
  12. {
  13. namespace Render
  14. {
  15. void LightingChannelConfiguration::Reflect(AZ::ReflectContext* context)
  16. {
  17. if (auto* serializeContext = azrtti_cast<AZ::SerializeContext*>(context))
  18. {
  19. serializeContext->Class<LightingChannelConfiguration>()
  20. ->Version(0)
  21. ->Field("lightingChannelFlags", &LightingChannelConfiguration::m_lightingChannelFlags)
  22. ;
  23. if (auto* editContext = serializeContext->GetEditContext())
  24. {
  25. editContext->Class<AZ::Render::LightingChannelConfiguration>("Lighting Channel Config", "")
  26. ->ClassElement(AZ::Edit::ClassElements::EditorData, "")
  27. ->Attribute(AZ::Edit::Attributes::AutoExpand, true)
  28. ->Attribute(AZ::Edit::Attributes::Visibility, AZ::Edit::PropertyVisibility::ShowChildrenOnly)
  29. ->DataElement(AZ::Edit::UIHandlers::Default, &AZ::Render::LightingChannelConfiguration::m_lightingChannelFlags,
  30. "Lighting Channels", "Lights can only shine the objects in the same lighting channel with the light.")
  31. ->Attribute(AZ::Edit::Attributes::ChangeNotify, AZ::Edit::PropertyRefreshLevels::AttributesAndValues)
  32. ->Attribute(AZ::Edit::Attributes::ContainerCanBeModified, false)
  33. ->Attribute(AZ::Edit::Attributes::ContainerReorderAllow, false)
  34. ->Attribute(AZ::Edit::Attributes::AutoExpand, false)
  35. ->Attribute(AZ::Edit::Attributes::IndexedChildNameLabelOverride, &LightingChannelConfiguration::GetLabelForIndex)
  36. ;
  37. }
  38. }
  39. }
  40. void LightingChannelConfiguration::SetLightingChannelMask(const uint32_t mask)
  41. {
  42. for (uint32_t index = 0; index < m_lightingChannelFlags.size(); ++index)
  43. {
  44. m_lightingChannelFlags[index] = (static_cast<bool>(mask >> index) & 0x01);
  45. }
  46. }
  47. uint32_t LightingChannelConfiguration::GetLightingChannelMask() const
  48. {
  49. uint32_t mask = 0;
  50. for (uint32_t index = 0; index < m_lightingChannelFlags.size(); ++index)
  51. {
  52. mask |= (static_cast<uint32_t>(m_lightingChannelFlags[index]) << (index));
  53. }
  54. return mask;
  55. }
  56. AZStd::string LightingChannelConfiguration::GetLabelForIndex(int index) const
  57. {
  58. return AZStd::string::format("Lighting Channel %d", index);
  59. }
  60. } // namespace Render
  61. } // namespace AZ