StacksShaderCollectionFunctorSourceData.cpp 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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/StacksShaderCollectionFunctorSourceData.h>
  9. #include <Atom/RPI.Reflect/Shader/ShaderOptionGroupLayout.h>
  10. #include <AzCore/Serialization/SerializeContext.h>
  11. namespace AtomSampleViewer
  12. {
  13. void StacksShaderCollectionFunctorSourceData::Reflect(AZ::ReflectContext* context)
  14. {
  15. if (auto* serializeContext = azrtti_cast<AZ::SerializeContext*>(context))
  16. {
  17. serializeContext->Class<StacksShaderCollectionFunctorSourceData>()
  18. ->Version(2)
  19. ;
  20. }
  21. }
  22. AZ::RPI::MaterialFunctorSourceData::FunctorResult StacksShaderCollectionFunctorSourceData::CreateFunctor(const RuntimeContext& context) const
  23. {
  24. using namespace AZ;
  25. using namespace AZ::RPI;
  26. Ptr<StacksShaderCollectionFunctor> functor = aznew StacksShaderCollectionFunctor;
  27. functor->m_stackCountProperty = context.FindMaterialPropertyIndex(Name("stacks.stackCount"));
  28. functor->m_highlightLastStackProperty = context.FindMaterialPropertyIndex(Name("stacks.highlightLastStack"));
  29. AddMaterialPropertyDependency(functor, functor->m_stackCountProperty);
  30. AddMaterialPropertyDependency(functor, functor->m_highlightLastStackProperty);
  31. // StacksShaderCollectionFunctorSourceData directly corresponds to Comprehensive.material, which uses the same ShaderAsset for all passes,
  32. // so we can just use the ShaderOptionGroupLayout from the first ShaderAsset.
  33. functor->m_highlightLastStackOption = context.FindShaderOptionIndex(0, AZ::Name{"o_highlighted2"});
  34. return Success(Ptr<MaterialFunctor>(functor));
  35. }
  36. }