LightingChannelConfiguration.cpp 3.2 KB

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