SMAAEdgeDetectionPass.h 4.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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. #pragma once
  9. #include <Atom/Feature/PostProcessing/SMAAFeatureProcessorInterface.h>
  10. #include <PostProcessing/SMAABasePass.h>
  11. namespace AZ
  12. {
  13. namespace Render
  14. {
  15. static const char* const SMAAEdgeDetectionPassTemplateName = "SMAAEdgeDetectionTemplate";
  16. //! There are three methods for edge detection. The first one uses depth information, second one uses luma information which is calculated
  17. //! from color value and the third one uses color information. Also, a predication option can be used when using the second and
  18. //! the third method are used. Detected edges information will be output as an edge texture.
  19. class SMAAEdgeDetectionPass final
  20. : public SMAABasePass
  21. {
  22. public:
  23. AZ_RTTI(SMAAEdgeDetectionPass, "{26D07086-9938-4FAB-A212-BB3CB4166641}", SMAABasePass);
  24. AZ_CLASS_ALLOCATOR(SMAAEdgeDetectionPass, SystemAllocator);
  25. virtual ~SMAAEdgeDetectionPass() = default;
  26. //! Creates a SMAAEdgeDetectionPass
  27. static RPI::Ptr<SMAAEdgeDetectionPass> Create(const RPI::PassDescriptor& descriptor);
  28. void SetEdgeDetectionMode(SMAAEdgeDetectionMode mode);
  29. void SetChromaThreshold(float threshold);
  30. void SetDepthThreshold(float threshold);
  31. void SetLocalContrastAdaptationFactor(float factor);
  32. void SetPredicationEnable(bool enable);
  33. void SetPredicationThreshold(float threshold);
  34. void SetPredicationScale(float scale);
  35. void SetPredicationStrength(float strength);
  36. private:
  37. SMAAEdgeDetectionPass(const RPI::PassDescriptor& descriptor);
  38. // Pass behavior overrides
  39. void InitializeInternal() override;
  40. // SMAABasePass functions...
  41. void UpdateSRG() override;
  42. void GetCurrentShaderOption(AZ::RPI::ShaderOptionGroup& shaderOption) const override;
  43. RHI::ShaderInputNameIndex m_renderTargetMetricsShaderInputIndex = "m_renderTargetMetrics";
  44. RHI::ShaderInputNameIndex m_chromaThresholdShaderInputIndex = "m_chromaThreshold";
  45. RHI::ShaderInputNameIndex m_depthThresholdShaderInputIndex = "m_depthThreshold";
  46. RHI::ShaderInputNameIndex m_localContrastAdaptationFactorShaderInputIndex = "m_localContrastAdaptationFactor";
  47. RHI::ShaderInputNameIndex m_predicationThresholdShaderInputIndex = "m_predicationThreshold";
  48. RHI::ShaderInputNameIndex m_predicationScaleShaderInputIndex = "m_predicationScale";
  49. RHI::ShaderInputNameIndex m_predicationStrengthShaderInputIndex = "m_predicationStrength";
  50. const AZ::Name m_enablePredicationFeatureOptionName;
  51. const AZ::Name m_edgeDetectionModeOptionName;
  52. // This is a threshold value for edge detection sensitivity. For details please check comment related to SMAA_THRESHOLD in SMAA.azsli.
  53. float m_chromaThreshold = 0.1f;
  54. // This is a threshold value for depth edge detection sensitivity. For details please check comment related to SMAA_DEPTH_THRESHOLD in SMAA.azsli.
  55. float m_depthThreshold = 0.01f;
  56. // This is a tweak value for the local contrast adaptation feature. For details please check comment related to SMAA_LOCAL_CONTRAST_ADAPTATION_FACTOR in SMAA.azsli.
  57. float m_localContrastAdaptationFactor = 2.0f;
  58. // This is a threshold value for predication feature. For details please check comment related to SMAA_PREDICATION_THRESHOLD in SMAA.azsli.
  59. float m_predicationThreshold = 0.01f;
  60. // This is a tweak value for predication feature. For details please check comment related to SMAA_PREDICATION_SCALE in SMAA.azsli.
  61. float m_predicationScale = 2.0f;
  62. // This is a tweak value for predication feature. For details please check comment related to SMAA_PREDICATION_STRENGTH in SMAA.azsli.
  63. float m_predicationStrength = 0.4f;
  64. // This is a edge detection mode variable.
  65. SMAAEdgeDetectionMode m_edgeDetectionMode = SMAAEdgeDetectionMode::Color;
  66. // A flag for predication feature. For details please check comment related to SMAA_PREDICATION in SMAA.azsli.
  67. bool m_predicationEnable = false;
  68. };
  69. } // namespace Render
  70. } // namespace AZ