VolumetricFog.h 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. // Copyright (C) 2009-2021, Panagiotis Christopoulos Charitos and contributors.
  2. // All rights reserved.
  3. // Code licensed under the BSD License.
  4. // http://www.anki3d.org/LICENSE
  5. #pragma once
  6. #include <AnKi/Renderer/RendererObject.h>
  7. namespace anki
  8. {
  9. /// @addtogroup renderer
  10. /// @{
  11. /// VolumetricFog effects.
  12. class VolumetricFog : public RendererObject
  13. {
  14. public:
  15. VolumetricFog(Renderer* r)
  16. : RendererObject(r)
  17. {
  18. }
  19. ~VolumetricFog()
  20. {
  21. }
  22. ANKI_USE_RESULT Error init(const ConfigSet& config);
  23. void setFogParticleColor(const Vec3& col)
  24. {
  25. m_fogDiffuseColor = col;
  26. }
  27. const Vec3& getFogParticleColor() const
  28. {
  29. return m_fogDiffuseColor;
  30. }
  31. void setParticleDensity(F32 d)
  32. {
  33. m_fogDensity = d;
  34. }
  35. F32 getParticleDensity() const
  36. {
  37. return m_fogDensity;
  38. }
  39. /// Populate the rendergraph.
  40. void populateRenderGraph(RenderingContext& ctx);
  41. RenderTargetHandle getRt() const
  42. {
  43. return m_runCtx.m_rt;
  44. }
  45. const Array<U32, 3>& getVolumeSize() const
  46. {
  47. return m_volumeSize;
  48. }
  49. /// Get the last cluster split in Z axis that will be affected by lighting.
  50. U32 getFinalClusterInZ() const
  51. {
  52. return m_finalZSplit;
  53. }
  54. private:
  55. ShaderProgramResourcePtr m_prog;
  56. ShaderProgramPtr m_grProg;
  57. RenderTargetDescription m_rtDescr;
  58. U32 m_finalZSplit = 0;
  59. Array<U32, 2> m_workgroupSize = {};
  60. Array<U32, 3> m_volumeSize;
  61. Vec3 m_fogDiffuseColor = Vec3(1.0f);
  62. F32 m_fogDensity = 0.9f;
  63. F32 m_fogScatteringCoeff = 0.01f;
  64. F32 m_fogAbsorptionCoeff = 0.02f;
  65. class
  66. {
  67. public:
  68. RenderTargetHandle m_rt;
  69. const RenderingContext* m_ctx = nullptr;
  70. } m_runCtx; ///< Runtime context.
  71. void run(RenderPassWorkContext& rgraphCtx);
  72. };
  73. /// @}
  74. } // end namespace anki