DeferredFogPass.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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/Memory/SystemAllocator.h>
  10. #include <Atom/RHI/CommandList.h>
  11. #include <Atom/RHI/DrawItem.h>
  12. #include <Atom/RHI/ScopeProducer.h>
  13. #include <Atom/RHI.Reflect/ShaderResourceGroupLayoutDescriptor.h>
  14. #include <Atom/RPI.Public/Pass/FullscreenTrianglePass.h>
  15. #include <Atom/RPI.Public/Shader/Shader.h>
  16. #include <Atom/RPI.Public/Shader/ShaderResourceGroup.h>
  17. #include <ScreenSpace/DeferredFogSettings.h>
  18. namespace AZ
  19. {
  20. namespace Render
  21. {
  22. static const char* const DeferredFogPassTemplateName = "DeferredFogPassTemplate";
  23. // Deferred screen space fog pass class. The fog is calculated post
  24. // the main render using the linear depth and turbulence texture with two blended
  25. // octaves that emulate the fog thickness and fog animation along the view ray direction.
  26. // The fog can be a full screen fog or a thin 3D layer fog representing mountains morning mist.
  27. // The pass also exposes the fog settings to be used by an editor component node that will
  28. // control the visual properties of the fog.
  29. // Enhancements of this fog can contain more advanced noise handling (real volumetric), areal
  30. // mask, blending between areal fog nodes and other enhancements required for production.
  31. class DeferredFogPass final
  32. : public RPI::FullscreenTrianglePass
  33. {
  34. AZ_RPI_PASS(DeferredFogPass);
  35. public:
  36. AZ_RTTI(DeferredFogPass, "{0406C8AB-E95D-43A7-AF53-BDEE22D36746}", RPI::FullscreenTrianglePass);
  37. AZ_CLASS_ALLOCATOR(DeferredFogPass, SystemAllocator);
  38. ~DeferredFogPass() = default;
  39. static RPI::Ptr<DeferredFogPass> Create(const RPI::PassDescriptor& descriptor);
  40. DeferredFogSettings* GetPassFogSettings();
  41. virtual bool IsEnabled() const override;
  42. protected:
  43. DeferredFogPass(const RPI::PassDescriptor& descriptor);
  44. // Pass behavior overrides...
  45. void InitializeInternal() override;
  46. // Scope producer functions...
  47. void SetupFrameGraphDependencies(RHI::FrameGraphInterface frameGraph) override;
  48. void CompileResources(const RHI::FrameGraphCompileContext& context) override;
  49. //! Set the binding indices of all members of the SRG
  50. void SetSrgBindIndices();
  51. //! Bind SRG constants - done via macro reflection
  52. void SetSrgConstants();
  53. //! Check if the pass should be enabled or disabled
  54. void UpdateEnable(DeferredFogSettings* fogSettings);
  55. void UpdateShaderOptions();
  56. private:
  57. // When a component is not present we want to fall back to the default settings and
  58. // actively pass them to the shader.
  59. DeferredFogSettings m_fallbackSettings;
  60. // Shader options for variant generation (texture and layer activation in this case)
  61. AZ::RPI::ShaderVariantKey m_ShaderOptions;
  62. };
  63. } // namespace Render
  64. } // namespace AZ