Bloom.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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. #include <AnKi/Gr.h>
  8. #include <AnKi/Resource/ImageResource.h>
  9. namespace anki
  10. {
  11. /// @addtogroup renderer
  12. /// @{
  13. /// Bloom passes.
  14. class Bloom : public RendererObject
  15. {
  16. public:
  17. Bloom(Renderer* r);
  18. ~Bloom();
  19. ANKI_USE_RESULT Error init(const ConfigSet& cfg)
  20. {
  21. ANKI_R_LOGI("Initializing bloom passes");
  22. Error err = initInternal(cfg);
  23. if(err)
  24. {
  25. ANKI_R_LOGE("Failed to initialize bloom passes");
  26. }
  27. return err;
  28. }
  29. /// Populate the rendergraph.
  30. void populateRenderGraph(RenderingContext& ctx);
  31. RenderTargetHandle getRt() const
  32. {
  33. return m_runCtx.m_upscaleRt;
  34. }
  35. F32 getThreshold() const
  36. {
  37. return m_exposure.m_threshold;
  38. }
  39. void setThreshold(F32 t)
  40. {
  41. m_exposure.m_threshold = t;
  42. }
  43. F32 getScale() const
  44. {
  45. return m_exposure.m_scale;
  46. }
  47. void setScale(F32 t)
  48. {
  49. m_exposure.m_scale = t;
  50. }
  51. private:
  52. static constexpr Format RT_PIXEL_FORMAT = Format::A2B10G10R10_UNORM_PACK32;
  53. const Array<U32, 3> m_workgroupSize = {16, 16, 1};
  54. class
  55. {
  56. public:
  57. ShaderProgramResourcePtr m_prog;
  58. ShaderProgramPtr m_grProg;
  59. F32 m_threshold = 10.0f; ///< How bright it is
  60. F32 m_scale = 1.0f;
  61. U32 m_width = 0;
  62. U32 m_height = 0;
  63. RenderTargetDescription m_rtDescr;
  64. } m_exposure;
  65. class
  66. {
  67. public:
  68. ImageResourcePtr m_lensDirtImage;
  69. ShaderProgramResourcePtr m_prog;
  70. ShaderProgramPtr m_grProg;
  71. U32 m_width = 0;
  72. U32 m_height = 0;
  73. RenderTargetDescription m_rtDescr;
  74. } m_upscale;
  75. class
  76. {
  77. public:
  78. RenderTargetHandle m_exposureRt;
  79. RenderTargetHandle m_upscaleRt;
  80. } m_runCtx;
  81. ANKI_USE_RESULT Error initExposure(const ConfigSet& cfg);
  82. ANKI_USE_RESULT Error initUpscale(const ConfigSet& cfg);
  83. ANKI_USE_RESULT Error initInternal(const ConfigSet& cfg)
  84. {
  85. ANKI_CHECK(initExposure(cfg));
  86. ANKI_CHECK(initUpscale(cfg));
  87. return Error::NONE;
  88. }
  89. void runExposure(RenderPassWorkContext& rgraphCtx);
  90. void runUpscaleAndSslf(RenderPassWorkContext& rgraphCtx);
  91. };
  92. /// @}
  93. } // end namespace anki