StacksShaderCollectionFunctor.cpp 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project. For complete copyright and license terms please see the LICENSE at the root of this distribution.
  3. *
  4. * SPDX-License-Identifier: Apache-2.0 OR MIT
  5. *
  6. */
  7. #include <MaterialFunctors/StacksShaderCollectionFunctor.h>
  8. #include <Atom/RPI.Public/Material/Material.h>
  9. #include <Atom/RPI.Reflect/Shader/ShaderOptionGroup.h>
  10. namespace AtomSampleViewer
  11. {
  12. void StacksShaderCollectionFunctor::Reflect(AZ::ReflectContext* context)
  13. {
  14. if (auto* serializeContext = azrtti_cast<AZ::SerializeContext*>(context))
  15. {
  16. serializeContext->Class<StacksShaderCollectionFunctor, AZ::RPI::MaterialFunctor>()
  17. ->Version(1)
  18. ->Field("m_stackCountProperty", &StacksShaderCollectionFunctor::m_stackCountProperty)
  19. ->Field("m_highlightLastStackProperty", &StacksShaderCollectionFunctor::m_highlightLastStackProperty)
  20. ->Field("m_highlightLastStackOption", &StacksShaderCollectionFunctor::m_highlightLastStackOption)
  21. ;
  22. }
  23. }
  24. void StacksShaderCollectionFunctor::Process(RuntimeContext& context)
  25. {
  26. using namespace AZ::RPI;
  27. const uint32_t stackCount = context.GetMaterialPropertyValue<uint32_t>(m_stackCountProperty);
  28. const bool highlightLastStack = context.GetMaterialPropertyValue<bool>(m_highlightLastStackProperty);
  29. static const int AvailableStackCount = 4;
  30. for (uint32_t i = 0; i < AvailableStackCount; ++i)
  31. {
  32. const bool isLastStack = (i == stackCount - 1);
  33. const bool shouldHighlight = highlightLastStack && isLastStack;
  34. context.SetShaderOptionValue(i, m_highlightLastStackOption, ShaderOptionValue{ shouldHighlight });
  35. context.SetShaderEnabled(i, i < stackCount);
  36. }
  37. }
  38. } // namespace AtomSampleViewer