Bloom.h 2.0 KB

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