DepthOfFieldSettings.h 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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 <AzCore/RTTI/ReflectContext.h>
  10. #include <Atom/RHI.Reflect/ShaderResourceGroupLayoutDescriptor.h>
  11. #include <Atom/Feature/PostProcess/DepthOfField/DepthOfFieldSettingsInterface.h>
  12. #include <Atom/RPI.Public/Image/StreamingImage.h>
  13. #include <PostProcess/PostProcessBase.h>
  14. #include <Atom/RPI.Public/View.h>
  15. namespace AZ
  16. {
  17. namespace Render
  18. {
  19. class PostProcessSettings;
  20. struct DepthOfFieldViewSRG
  21. {
  22. // x : viewFar, y : viewNear, z : focusDistance
  23. AZStd::array<float, 3> m_cameraParameters = { { 0.0f, 0.0f, 0.0f } };
  24. // scale / offset to convert DofFactor to blend ratio for back buffer.
  25. AZStd::array<float, 2> m_backBlendFactorDivision2 = { { 0.0f, 0.0f } };
  26. AZStd::array<float, 2> m_backBlendFactorDivision4 = { { 0.0f, 0.0f } };
  27. AZStd::array<float, 2> m_backBlendFactorDivision8 = { { 0.0f, 0.0f } };
  28. // scale / offset to convert DofFactor to blend ratio for front buffer.
  29. AZStd::array<float, 2> m_frontBlendFactorDivision2 = { { 0.0f, 0.0f } };
  30. AZStd::array<float, 2> m_frontBlendFactorDivision4 = { { 0.0f, 0.0f } };
  31. AZStd::array<float, 2> m_frontBlendFactorDivision8 = { { 0.0f, 0.0f } };
  32. // Used to determine the pencilMap texture coordinates from depth.
  33. float m_pencilMapTexcoordToCocRadius = 0.0f;
  34. float m_pencilMapFocusPointTexcoordU = 0.0f;
  35. // circle of confusion to screen ratio.
  36. float m_cocToScreenRatio = 0.0f;
  37. };
  38. // The post process sub-settings class for the Depth of Field feature
  39. class DepthOfFieldSettings final
  40. : public DepthOfFieldSettingsInterface
  41. , public PostProcessBase
  42. {
  43. friend class PostProcessSettings;
  44. friend class PostProcessFeatureProcessor;
  45. friend class DepthOfFieldBokehBlurPass;
  46. friend class DepthOfFieldMaskPass;
  47. friend class DepthOfFieldReadBackFocusDepthPass;
  48. friend class DepthOfFieldCompositePass;
  49. public:
  50. AZ_RTTI(AZ::Render::DepthOfFieldSettings, "{64782D63-80E0-4935-9E26-47EFC735305D}",
  51. AZ::Render::DepthOfFieldSettingsInterface, AZ::Render::PostProcessBase);
  52. AZ_CLASS_ALLOCATOR(DepthOfFieldSettings, SystemAllocator);
  53. DepthOfFieldSettings(PostProcessFeatureProcessor* featureProcessor);
  54. ~DepthOfFieldSettings() = default;
  55. // DepthOfFieldSettingsInterface overrides...
  56. void OnConfigChanged() override;
  57. // Applies settings from this onto target using override settings and passed alpha value for blending
  58. void ApplySettingsTo(DepthOfFieldSettings* target, float alpha) const;
  59. AZ::RHI::Handle<uint32_t> GetSplitSizeForPass(const Name& passName) const;
  60. // Set dof related settings to the viewSrg
  61. void SetValuesToViewSrg(AZ::Data::Instance<RPI::ShaderResourceGroup> viewSrg);
  62. // Generate all getters and override setters.
  63. // Declare non-override setters, which will be defined in the .cpp
  64. #define AZ_GFX_COMMON_PARAM(ValueType, Name, MemberName, DefaultValue) \
  65. ValueType Get##Name() const override { return MemberName; } \
  66. void Set##Name(ValueType val) override; \
  67. #define AZ_GFX_COMMON_OVERRIDE(ValueType, Name, MemberName, OverrideValueType) \
  68. OverrideValueType Get##Name##Override() const override { return MemberName##Override; } \
  69. void Set##Name##Override(OverrideValueType val) override { MemberName##Override = val; } \
  70. #include <Atom/Feature/ParamMacros/MapAllCommon.inl>
  71. #include <Atom/Feature/PostProcess/DepthOfField/DepthOfFieldParams.inl>
  72. #include <Atom/Feature/ParamMacros/EndParams.inl>
  73. private:
  74. // Generate members...
  75. #include <Atom/Feature/ParamMacros/StartParamMembers.inl>
  76. #include <Atom/Feature/PostProcess/DepthOfField/DepthOfFieldParams.inl>
  77. #include <Atom/Feature/ParamMacros/EndParams.inl>
  78. void Simulate(float deltaTime);
  79. void UpdateFNumber();
  80. PostProcessSettings* m_parentSettings = nullptr;
  81. // From DepthOfFieldFeatureProcessor...
  82. void LoadPencilMap();
  83. void UpdatePencilMapTexture() const;
  84. AZ::Data::Instance<AZ::RPI::StreamingImage> m_pencilMap;
  85. RHI::ShaderInputImageIndex m_pencilMapIndex;
  86. // From DepthOfFieldRenderProxy...
  87. void UpdateCameraParameters();
  88. void UpdateBlendFactor();
  89. void UpdateAutoFocusDepth(bool enabled);
  90. AZ::RHI::ShaderInputNameIndex m_cameraParametersIndex = "m_dof.m_cameraParameters";
  91. AZ::RHI::ShaderInputNameIndex m_pencilMapTexcoordToCocRadiusIndex = "m_dof.m_pencilMapTexcoordToCocRadius";
  92. AZ::RHI::ShaderInputNameIndex m_pencilMapFocusPointTexcoordUIndex = "m_dof.m_pencilMapFocusPointTexcoordU";
  93. AZ::RHI::ShaderInputNameIndex m_cocToScreenRatioIndex = "m_dof.m_cocToScreenRatio";
  94. AZ::RHI::NameIdReflectionMap<AZ::RHI::Handle<uint32_t>> m_passListWithHashOfDivisionNumber;
  95. DepthOfFieldViewSRG m_configurationToViewSRG;
  96. float m_viewAspectRatio = 0.0f;
  97. float m_maxBokehRadiusDivision2 = 0.0f;
  98. float m_minBokehRadiusDivision2 = 0.0f;
  99. float m_maxBokehRadiusDivision4 = 0.0f;
  100. float m_minBokehRadiusDivision4 = 0.0f;
  101. float m_maxBokehRadiusDivision8 = 0.0f;
  102. float m_minBokehRadiusDivision8 = 0.0f;
  103. // Radial division count of bokeh blur kernel.
  104. uint32_t m_sampleRadialDivision2 = 0;
  105. uint32_t m_sampleRadialDivision4 = 0;
  106. uint32_t m_sampleRadialDivision8 = 0;
  107. // camera parameters
  108. float m_viewFovRadian = 0.0f;
  109. float m_viewWidth = 0.0f;
  110. float m_viewHeight = 0.0f;
  111. float m_viewNear = 0.0f;
  112. float m_viewFar = 0.0f;
  113. float m_normalizedFocusDistanceForAutoFocus = 0.0f;
  114. float m_deltaTime = 0.0f;
  115. };
  116. }
  117. }