SkinnedMeshShaderOptionsCache.cpp 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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 <SkinnedMesh/SkinnedMeshShaderOptionsCache.h>
  9. #include <Atom/RPI.Public/Shader/Shader.h>
  10. namespace AZ
  11. {
  12. namespace Render
  13. {
  14. void CachedSkinnedMeshShaderOptions::SetShader(Data::Instance<RPI::Shader> shader)
  15. {
  16. m_shader = shader;
  17. // Cache the different possible indices and values so they are efficent to set later
  18. const RPI::ShaderOptionGroupLayout* layout = m_shader->GetAsset()->GetShaderOptionGroupLayout();
  19. m_skinningMethodOptionIndex = layout->FindShaderOptionIndex(AZ::Name("o_skinningMethod"));
  20. m_skinningMethodLinearSkinningValue = layout->FindValue(m_skinningMethodOptionIndex, AZ::Name("SkinningMethod::LinearSkinning"));
  21. m_skinningMethodDualQuaternionValue = layout->FindValue(m_skinningMethodOptionIndex, AZ::Name("SkinningMethod::DualQuaternion"));
  22. m_skinningMethodNoSkinningValue = layout->FindValue(m_skinningMethodOptionIndex, AZ::Name("SkinningMethod::NoSkinning"));
  23. m_applyMorphTargetOptionIndex = layout->FindShaderOptionIndex(AZ::Name("o_applyMorphTargets"));
  24. m_applyMorphTargetFalseValue = layout->FindValue(m_applyMorphTargetOptionIndex, AZ::Name("false"));
  25. m_applyMorphTargetTrueValue = layout->FindValue(m_applyMorphTargetOptionIndex, AZ::Name("true"));
  26. SkinnedMeshShaderOptionNotificationBus::Event(this, &SkinnedMeshShaderOptionNotificationBus::Events::OnShaderReinitialized, this);
  27. }
  28. void CachedSkinnedMeshShaderOptions::ConnectToShaderReinitializedEvent(SkinnedMeshShaderOptionNotificationBus::Handler& shaderReinitializedEventHandler)
  29. {
  30. shaderReinitializedEventHandler.BusConnect(this);
  31. }
  32. RPI::ShaderOptionGroup CachedSkinnedMeshShaderOptions::CreateShaderOptionGroup(const SkinnedMeshShaderOptions& shaderOptions) const
  33. {
  34. RPI::ShaderOptionGroup shaderOptionGroup = m_shader->CreateShaderOptionGroup();
  35. switch (shaderOptions.m_skinningMethod)
  36. {
  37. case SkinningMethod::DualQuaternion:
  38. shaderOptionGroup.SetValue(m_skinningMethodOptionIndex, m_skinningMethodDualQuaternionValue);
  39. break;
  40. case SkinningMethod::NoSkinning:
  41. shaderOptionGroup.SetValue(m_skinningMethodOptionIndex, m_skinningMethodNoSkinningValue);
  42. break;
  43. case SkinningMethod::LinearSkinning:
  44. default:
  45. shaderOptionGroup.SetValue(m_skinningMethodOptionIndex, m_skinningMethodLinearSkinningValue);
  46. }
  47. if (shaderOptions.m_applyMorphTargets)
  48. {
  49. shaderOptionGroup.SetValue(m_applyMorphTargetOptionIndex, m_applyMorphTargetTrueValue);
  50. }
  51. else
  52. {
  53. shaderOptionGroup.SetValue(m_applyMorphTargetOptionIndex, m_applyMorphTargetFalseValue);
  54. }
  55. shaderOptionGroup.SetUnspecifiedToDefaultValues();
  56. return shaderOptionGroup;
  57. }
  58. } // namespace Render
  59. } // namespace AZ