StacksShaderCollectionFunctor.cpp 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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 <MaterialFunctors/StacksShaderCollectionFunctor.h>
  9. #include <Atom/RPI.Public/Material/Material.h>
  10. #include <Atom/RPI.Reflect/Shader/ShaderOptionGroup.h>
  11. namespace AtomSampleViewer
  12. {
  13. void StacksShaderCollectionFunctor::Reflect(AZ::ReflectContext* context)
  14. {
  15. if (auto* serializeContext = azrtti_cast<AZ::SerializeContext*>(context))
  16. {
  17. serializeContext->Class<StacksShaderCollectionFunctor, AZ::RPI::MaterialFunctor>()
  18. ->Version(1)
  19. ->Field("m_stackCountProperty", &StacksShaderCollectionFunctor::m_stackCountProperty)
  20. ->Field("m_highlightLastStackProperty", &StacksShaderCollectionFunctor::m_highlightLastStackProperty)
  21. ->Field("m_highlightLastStackOption", &StacksShaderCollectionFunctor::m_highlightLastStackOption)
  22. ;
  23. }
  24. }
  25. void StacksShaderCollectionFunctor::Process(RuntimeContext& context)
  26. {
  27. using namespace AZ::RPI;
  28. const uint32_t stackCount = context.GetMaterialPropertyValue<uint32_t>(m_stackCountProperty);
  29. const bool highlightLastStack = context.GetMaterialPropertyValue<bool>(m_highlightLastStackProperty);
  30. static const int AvailableStackCount = 4;
  31. for (uint32_t i = 0; i < AvailableStackCount; ++i)
  32. {
  33. const bool isLastStack = (i == stackCount - 1);
  34. const bool shouldHighlight = highlightLastStack && isLastStack;
  35. context.SetShaderOptionValue(i, m_highlightLastStackOption, ShaderOptionValue{ shouldHighlight });
  36. context.SetShaderEnabled(i, i < stackCount);
  37. }
  38. }
  39. } // namespace AtomSampleViewer