SMAABlendingWeightCalculationPass.cpp 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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 <Atom/RPI.Public/Image/ImageSystemInterface.h>
  9. #include <Atom/RPI.Public/Pass/PassUtils.h>
  10. #include <Atom/RPI.Public/Pass/PassFactory.h>
  11. #include <Atom/RPI.Public/Pass/FullscreenTrianglePass.h>
  12. #include <Atom/RPI.Public/RenderPipeline.h>
  13. #include <Atom/RPI.Public/RPIUtils.h>
  14. #include <Atom/RPI.Public/View.h>
  15. #include <Atom/RPI.Public/Shader/ShaderVariant.h>
  16. #include <Atom/RPI.Public/RPIUtils.h>
  17. #include <Atom/RPI.Reflect/Pass/PassTemplate.h>
  18. #include <Atom/RPI.Reflect/Shader/ShaderAsset.h>
  19. #include <Atom/RHI/Factory.h>
  20. #include <Atom/RHI/FrameScheduler.h>
  21. #include <Atom/RHI/DevicePipelineState.h>
  22. #include <AzCore/Asset/AssetCommon.h>
  23. #include <AzCore/Asset/AssetManagerBus.h>
  24. #include <PostProcessing/SMAACommon.h>
  25. #include <PostProcessing/SMAABlendingWeightCalculationPass.h>
  26. namespace AZ
  27. {
  28. namespace Render
  29. {
  30. RPI::Ptr<SMAABlendingWeightCalculationPass> SMAABlendingWeightCalculationPass::Create(const RPI::PassDescriptor& descriptor)
  31. {
  32. return aznew SMAABlendingWeightCalculationPass(descriptor);
  33. }
  34. SMAABlendingWeightCalculationPass::SMAABlendingWeightCalculationPass(const RPI::PassDescriptor& descriptor)
  35. : SMAABasePass(descriptor)
  36. , m_enableDiagonalDetectionFeatureOptionName(EnableDiagonalDetectionFeatureOptionName)
  37. , m_enableCornerDetectionFeatureOptionName(EnableCornerDetectionFeatureOptionName)
  38. {
  39. }
  40. void SMAABlendingWeightCalculationPass::SetMaxSearchSteps(int steps)
  41. {
  42. if (m_maxSearchSteps != steps)
  43. {
  44. m_maxSearchSteps = steps;
  45. InvalidateSRG();
  46. }
  47. }
  48. void SMAABlendingWeightCalculationPass::SetMaxSearchStepsDiagonal(int steps)
  49. {
  50. if (m_maxSearchStepsDiagonal != steps)
  51. {
  52. m_maxSearchStepsDiagonal = steps;
  53. InvalidateSRG();
  54. }
  55. }
  56. void SMAABlendingWeightCalculationPass::SetCornerRounding(int cornerRounding)
  57. {
  58. if (m_cornerRounding != cornerRounding)
  59. {
  60. m_cornerRounding = cornerRounding;
  61. InvalidateSRG();
  62. }
  63. }
  64. void SMAABlendingWeightCalculationPass::SetDiagonalDetectionEnable(bool enable)
  65. {
  66. if (m_enableDiagonalDetection != enable)
  67. {
  68. m_enableDiagonalDetection = enable;
  69. InvalidateShaderVariant();
  70. }
  71. }
  72. void SMAABlendingWeightCalculationPass::SetCornerDetectionEnable(bool enable)
  73. {
  74. if (m_enableCornerDetection != enable)
  75. {
  76. m_enableCornerDetection = enable;
  77. InvalidateShaderVariant();
  78. }
  79. }
  80. void SMAABlendingWeightCalculationPass::InitializeInternal()
  81. {
  82. SMAABasePass::InitializeInternal();
  83. AZ_Assert(m_shaderResourceGroup != nullptr, "SMAABlendingWeightCalculationPass %s has a null shader resource group when calling Init.", GetPathName().GetCStr());
  84. m_areaTexture = AZ::RPI::LoadStreamingTexture(PathToSMAAAreaTexture);
  85. m_searchTexture = AZ::RPI::LoadStreamingTexture(PathToSMAASearchTexture);
  86. m_areaTextureShaderInputIndex.Reset();
  87. m_searchTextureShaderInputIndex.Reset();
  88. m_renderTargetMetricsShaderInputIndex.Reset();
  89. m_maxSearchStepsShaderInputIndex.Reset();
  90. m_maxSearchStepsDiagonalShaderInputIndex.Reset();
  91. m_cornerRoundingShaderInputIndex.Reset();
  92. }
  93. void SMAABlendingWeightCalculationPass::UpdateSRG()
  94. {
  95. m_shaderResourceGroup->SetConstant(m_renderTargetMetricsShaderInputIndex, m_renderTargetMetrics);
  96. m_shaderResourceGroup->SetImage(m_areaTextureShaderInputIndex, m_areaTexture);
  97. m_shaderResourceGroup->SetImage(m_searchTextureShaderInputIndex, m_searchTexture);
  98. m_shaderResourceGroup->SetConstant(m_maxSearchStepsShaderInputIndex, m_maxSearchSteps);
  99. m_shaderResourceGroup->SetConstant(m_maxSearchStepsDiagonalShaderInputIndex, m_maxSearchStepsDiagonal);
  100. m_shaderResourceGroup->SetConstant(m_cornerRoundingShaderInputIndex, m_cornerRounding);
  101. }
  102. void SMAABlendingWeightCalculationPass::GetCurrentShaderOption(AZ::RPI::ShaderOptionGroup& shaderOption) const
  103. {
  104. shaderOption.SetValue(m_enableDiagonalDetectionFeatureOptionName, m_enableDiagonalDetection ? AZ::Name("true") : AZ::Name("false"));
  105. shaderOption.SetValue(m_enableCornerDetectionFeatureOptionName, m_enableCornerDetection ? AZ::Name("true") : AZ::Name("false"));
  106. }
  107. } // namespace Render
  108. } // namespace AZ