DeferredFogSettings.h 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  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/Math/Vector2.h>
  10. #include <AzCore/Math/Vector3.h>
  11. #include <AzCore/RTTI/ReflectContext.h>
  12. #include <Atom/RHI.Reflect/ShaderResourceGroupLayoutDescriptor.h>
  13. #include <Atom/RPI.Public/Shader/Shader.h>
  14. #include <Atom/RPI.Public/Shader/ShaderResourceGroup.h>
  15. #include <Atom/RPI.Public/Image/StreamingImage.h>
  16. #include <Atom/Feature/ParamMacros/ParamMacrosHowTo.inl> // for education purposes
  17. #include <Atom/Feature/ScreenSpace/DeferredFogSettingsInterface.h>
  18. #include <PostProcess/PostProcessBase.h>
  19. namespace AZ
  20. {
  21. namespace Render
  22. {
  23. class PostProcessSettings;
  24. // The post process sub-settings class for the exposure control feature over
  25. // full screen deferred fog.
  26. // The fog is calculated using the linear depth and turbulence texture with two blended
  27. // octaves that emulate the fog thickness and motion along the view ray direction.
  28. //
  29. // [GFX TODO] most methods in this class can be auto generated using a reflection mechanism
  30. // based on the PerPass Srg. Currently we don't have such a reflection system in place
  31. // and so, a temporary approach demonstrating partial reflection through preprocessor
  32. // macros is used.
  33. class DeferredFogSettings final :
  34. public DeferredFogSettingsInterface,
  35. public PostProcessBase
  36. {
  37. friend class DeferredFogPass;
  38. friend class PostProcessSettings;
  39. friend class PostProcessFeatureProcessor;
  40. public:
  41. AZ_RTTI(DeferredFogSettings, "{FD822CC5-4E7B-4471-AA7D-1FCDF6CAC979}",
  42. AZ::Render::DeferredFogSettingsInterface, AZ::Render::PostProcessBase);
  43. AZ_CLASS_ALLOCATOR(AZ::Render::DeferredFogSettings, SystemAllocator);
  44. DeferredFogSettings(PostProcessFeatureProcessor* featureProcessor);
  45. DeferredFogSettings();
  46. ~DeferredFogSettings() = default;
  47. // DeferredFogSettingsInterface overrides...
  48. void OnSettingsChanged() override;
  49. bool GetSettingsNeedUpdate()
  50. {
  51. return m_needUpdate;
  52. }
  53. void SetSettingsNeedUpdate(bool needUpdate)
  54. {
  55. m_needUpdate = needUpdate;
  56. }
  57. void SetEnabled(bool value) override;
  58. bool GetEnabled() const override
  59. {
  60. return m_enabled;
  61. }
  62. void SetInitialized(bool isInitialized) override
  63. {
  64. m_isInitialized = isInitialized;
  65. }
  66. bool IsInitialized() override
  67. {
  68. return m_isInitialized;
  69. }
  70. void SetUseNoiseTextureShaderOption(bool value) override
  71. {
  72. m_useNoiseTextureShaderOption = value;
  73. }
  74. bool GetUseNoiseTextureShaderOption() override
  75. {
  76. return m_useNoiseTextureShaderOption;
  77. }
  78. void SetEnableFogLayerShaderOption(bool value) override
  79. {
  80. m_enableFogLayerShaderOption = value;
  81. }
  82. bool GetEnableFogLayerShaderOption() override
  83. {
  84. return m_enableFogLayerShaderOption;
  85. }
  86. // Called by the post effects feature processor for doing per frame prep if required
  87. void Simulate([[maybe_unused]]float deltaTime) {};
  88. // Applies settings from this onto target using override settings and passed alpha value for blending
  89. void ApplySettingsTo(DeferredFogSettings* target, float alpha) const;
  90. Data::Instance<RPI::StreamingImage> LoadStreamingImage(const char* textureFilePath, const char* sampleName);
  91. //---------------------------------------------------------
  92. // Generate Get / Set override methods
  93. #define AZ_GFX_COMMON_PARAM(ValueType, Name, MemberName, DefaultValue) \
  94. ValueType Get##Name() const override; \
  95. void Set##Name(ValueType val) override; \
  96. #include <Atom/Feature/ParamMacros/MapParamCommon.inl>
  97. #include <Atom/Feature/ScreenSpace/DeferredFogParams.inl>
  98. #include <Atom/Feature/ParamMacros/EndParams.inl>
  99. private:
  100. //---------------------------------------------------------
  101. // SRG constants
  102. #define AZ_GFX_COMMON_PARAM(ValueType, Name, MemberName, DefaultValue) \
  103. ValueType MemberName = DefaultValue; \
  104. #include <Atom/Feature/ParamMacros/MapParamCommon.inl>
  105. #include <Atom/Feature/ScreenSpace/DeferredFogParams.inl>
  106. #include <Atom/Feature/ParamMacros/EndParams.inl>
  107. //---------------------------------------------------------
  108. // SRG constants binding indices
  109. #define AZ_GFX_COMMON_PARAM(ValueType, Name, MemberName, DefaultValue) \
  110. RHI::ShaderInputConstantIndex MemberName##SrgIndex; \
  111. #include <Atom/Feature/ParamMacros/MapParamCommon.inl>
  112. // Change the handling for texture handles
  113. #undef AZ_GFX_TEXTURE2D_PARAM
  114. #define AZ_GFX_TEXTURE2D_PARAM(Name, MemberName, DefaultValue) \
  115. RHI::ShaderInputImageIndex MemberName##SrgIndex; \
  116. #include <Atom/Feature/ScreenSpace/DeferredFogParams.inl>
  117. #include <Atom/Feature/ParamMacros/EndParams.inl>
  118. //---------------------------------------------------------
  119. // Generate all Image members instances
  120. // Set all macros to be empty, but override the texture for defining image members
  121. #include <Atom/Feature/ParamMacros/MapParamEmpty.inl>
  122. // Macro to replace only the image macro for defining only image resources
  123. #undef AZ_GFX_TEXTURE2D_PARAM
  124. #define AZ_GFX_TEXTURE2D_PARAM(Name, MemberName, DefaultValue) \
  125. Data::Instance<AZ::RPI::Image> MemberName##Image; \
  126. #include <Atom/Feature/ScreenSpace/DeferredFogParams.inl>
  127. #include <Atom/Feature/ParamMacros/EndParams.inl>
  128. PostProcessSettings* m_parentSettings = nullptr;
  129. // 'm_enabled' indicates if the pass should be enabled. By default this is set to true since if the
  130. // pass is data driven enabled, the default settings should not disable it. If it is driven by
  131. // an engine component, these settings will be replaced by the component's settings controlled by
  132. // the user.
  133. bool m_enabled = true;
  134. // Indication if the SRG indices were set
  135. bool m_isInitialized = false;
  136. // Indicates that the srg indices were set
  137. bool m_needUpdate = true;
  138. bool m_useNoiseTextureShaderOption = true;
  139. bool m_enableFogLayerShaderOption = true;
  140. };
  141. }
  142. }