StacksShaderCollectionFunctor.cpp 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. /*
  2. * All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
  3. * its licensors.
  4. *
  5. * For complete copyright and license terms please see the LICENSE at the root of this
  6. * distribution (the "License"). All use of this software is governed by the License,
  7. * or, if provided, by the license below or the license accompanying this file. Do not
  8. * remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
  9. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. *
  11. */
  12. #include <MaterialFunctors/StacksShaderCollectionFunctor.h>
  13. #include <Atom/RPI.Public/Material/Material.h>
  14. #include <Atom/RPI.Reflect/Shader/ShaderOptionGroup.h>
  15. namespace AtomSampleViewer
  16. {
  17. void StacksShaderCollectionFunctor::Reflect(AZ::ReflectContext* context)
  18. {
  19. if (auto* serializeContext = azrtti_cast<AZ::SerializeContext*>(context))
  20. {
  21. serializeContext->Class<StacksShaderCollectionFunctor, AZ::RPI::MaterialFunctor>()
  22. ->Version(1)
  23. ->Field("m_stackCountProperty", &StacksShaderCollectionFunctor::m_stackCountProperty)
  24. ->Field("m_highlightLastStackProperty", &StacksShaderCollectionFunctor::m_highlightLastStackProperty)
  25. ->Field("m_highlightLastStackOption", &StacksShaderCollectionFunctor::m_highlightLastStackOption)
  26. ;
  27. }
  28. }
  29. void StacksShaderCollectionFunctor::Process(RuntimeContext& context)
  30. {
  31. using namespace AZ::RPI;
  32. const uint32_t stackCount = context.GetMaterialPropertyValue<uint32_t>(m_stackCountProperty);
  33. const bool highlightLastStack = context.GetMaterialPropertyValue<bool>(m_highlightLastStackProperty);
  34. static const int AvailableStackCount = 4;
  35. for (uint32_t i = 0; i < AvailableStackCount; ++i)
  36. {
  37. const bool isLastStack = (i == stackCount - 1);
  38. const bool shouldHighlight = highlightLastStack && isLastStack;
  39. context.SetShaderOptionValue(i, m_highlightLastStackOption, ShaderOptionValue{ shouldHighlight });
  40. context.SetShaderEnabled(i, i < stackCount);
  41. }
  42. }
  43. } // namespace AtomSampleViewer