LookModificationSettings.cpp 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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 <AzCore/Serialization/SerializeContext.h>
  9. #include <AzCore/Utils/TypeHash.h>
  10. #include <Atom/RPI.Public/Pass/PassSystemInterface.h>
  11. #include <ACES/Aces.h>
  12. #include <PostProcess/LookModification/LookModificationSettings.h>
  13. #include <PostProcess/PostProcessFeatureProcessor.h>
  14. namespace AZ
  15. {
  16. namespace Render
  17. {
  18. HashValue64 LutBlendItem::GetHash(HashValue64 seed) const
  19. {
  20. seed = TypeHash64(m_intensity, seed);
  21. seed = TypeHash64(m_overrideStrength, seed);
  22. seed = TypeHash64(m_asset.GetId(), seed);
  23. seed = TypeHash64(m_shaperPreset, seed);
  24. seed = TypeHash64(m_customMinExposure, seed);
  25. seed = TypeHash64(m_customMaxExposure, seed);
  26. return seed;
  27. }
  28. LookModificationSettings::LookModificationSettings(PostProcessFeatureProcessor* featureProcessor)
  29. : PostProcessBase(featureProcessor)
  30. {
  31. }
  32. void LookModificationSettings::OnConfigChanged()
  33. {
  34. m_parentSettings->OnConfigChanged();
  35. }
  36. void LookModificationSettings::ApplySettingsTo(LookModificationSettings* target, float alpha) const
  37. {
  38. AZ_Assert(target != nullptr, "LookModificationSettings::ApplySettingsTo called with nullptr as argument.");
  39. auto lutAsset = GetColorGradingLut();
  40. if (GetEnabled() && lutAsset.GetId().IsValid())
  41. {
  42. Render::LutBlendItem lutBlend;
  43. lutBlend.m_intensity = GetColorGradingLutIntensity();
  44. lutBlend.m_overrideStrength = GetColorGradingLutOverride() * alpha;
  45. lutBlend.m_asset = lutAsset;
  46. lutBlend.m_shaperPreset = GetShaperPresetType();
  47. lutBlend.m_customMinExposure = GetCustomMinExposure();
  48. lutBlend.m_customMaxExposure = GetCustomMaxExposure();
  49. target->AddLutBlend(lutBlend);
  50. }
  51. }
  52. void LookModificationSettings::Simulate(float deltaTime)
  53. {
  54. AZ_UNUSED(deltaTime);
  55. }
  56. void LookModificationSettings::AddLutBlend(LutBlendItem lutBlendItem)
  57. {
  58. if (m_lutBlendStack.size() < MaxBlendLuts)
  59. {
  60. m_lutBlendStack.push_back(lutBlendItem);
  61. }
  62. else
  63. {
  64. AZ_Warning("LookModificationSettings", false, "Attempted to add more than the maxiumum number of LUTs of %u for blending.", MaxBlendLuts);
  65. }
  66. }
  67. void LookModificationSettings::PrepareLutBlending()
  68. {
  69. if (m_preparedForBlending == true)
  70. {
  71. return;
  72. }
  73. // If color grading LUT enabled for this setting, push the LUT entry onto the head of the blend stack
  74. if (GetEnabled())
  75. {
  76. auto lutAsset = GetColorGradingLut();
  77. if (lutAsset.GetId().IsValid())
  78. {
  79. LutBlendItem blendItem;
  80. blendItem.m_intensity = GetColorGradingLutIntensity();
  81. blendItem.m_overrideStrength = GetColorGradingLutOverride();
  82. blendItem.m_asset = GetColorGradingLut();
  83. blendItem.m_shaperPreset = GetShaperPresetType();
  84. blendItem.m_customMinExposure = GetCustomMinExposure();
  85. blendItem.m_customMaxExposure = GetCustomMaxExposure();
  86. m_lutBlendStack.insert(m_lutBlendStack.begin(), blendItem);
  87. }
  88. }
  89. // The override strength of the lowest priority LUT should not be considered, but setting to 1.0 here because it makes calculating the weights cleaner with less special casing
  90. if (m_lutBlendStack.size() > 0)
  91. {
  92. m_lutBlendStack[0].m_overrideStrength = 1.0;
  93. }
  94. m_preparedForBlending = true;
  95. }
  96. size_t LookModificationSettings::GetLutBlendStackSize()
  97. {
  98. return m_lutBlendStack.size();
  99. }
  100. LutBlendItem& LookModificationSettings::GetLutBlendItem(size_t lutIndex)
  101. {
  102. return m_lutBlendStack[lutIndex];
  103. }
  104. HashValue64 LookModificationSettings::GetHash() const
  105. {
  106. HashValue64 seed = TypeHash64(m_lutBlendStack.size());
  107. for (int index = 0; index < m_lutBlendStack.size(); index++)
  108. {
  109. seed = m_lutBlendStack[index].GetHash(seed);
  110. }
  111. return seed;
  112. }
  113. } // namespace Render
  114. } // namespace AZ