IndirectDiffuseProbes.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. // Copyright (C) 2009-2022, 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/Renderer/TraditionalDeferredShading.h>
  8. #include <AnKi/Renderer/RenderQueue.h>
  9. #include <AnKi/Collision/Forward.h>
  10. namespace anki {
  11. /// @addtogroup renderer
  12. /// @{
  13. /// Ambient global illumination passes.
  14. ///
  15. /// It builds a volume clipmap with ambient GI information.
  16. class IndirectDiffuseProbes : public RendererObject
  17. {
  18. public:
  19. IndirectDiffuseProbes(Renderer* r)
  20. : RendererObject(r)
  21. , m_lightShading(r)
  22. {
  23. }
  24. ~IndirectDiffuseProbes();
  25. Error init();
  26. /// Populate the rendergraph.
  27. void populateRenderGraph(RenderingContext& ctx);
  28. /// Return the volume RT given a cache entry index.
  29. const RenderTargetHandle& getVolumeRenderTarget(const GlobalIlluminationProbeQueueElement& probe) const;
  30. /// Set the render graph dependencies.
  31. void setRenderGraphDependencies(const RenderingContext& ctx, RenderPassDescriptionBase& pass,
  32. TextureUsageBit usage) const;
  33. /// Bind the volume textures to a command buffer.
  34. void bindVolumeTextures(const RenderingContext& ctx, RenderPassWorkContext& rgraphCtx, U32 set, U32 binding) const;
  35. private:
  36. class InternalContext;
  37. class CacheEntry
  38. {
  39. public:
  40. U64 m_uuid; ///< Probe UUID.
  41. Timestamp m_lastUsedTimestamp = 0; ///< When it was last seen by the renderer.
  42. TexturePtr m_volumeTex; ///< Contains the 6 directions.
  43. UVec3 m_volumeSize = UVec3(0u);
  44. Vec3 m_probeAabbMin = Vec3(0.0f);
  45. Vec3 m_probeAabbMax = Vec3(0.0f);
  46. U32 m_renderedCells = 0;
  47. };
  48. class
  49. {
  50. public:
  51. Array<RenderTargetDescription, GBUFFER_COLOR_ATTACHMENT_COUNT> m_colorRtDescrs;
  52. RenderTargetDescription m_depthRtDescr;
  53. FramebufferDescription m_fbDescr;
  54. } m_gbuffer; ///< G-buffer pass.
  55. class
  56. {
  57. public:
  58. RenderTargetDescription m_rtDescr;
  59. FramebufferDescription m_fbDescr;
  60. } m_shadowMapping;
  61. class LS
  62. {
  63. public:
  64. RenderTargetDescription m_rtDescr;
  65. FramebufferDescription m_fbDescr;
  66. TraditionalDeferredLightShading m_deferred;
  67. LS(Renderer* r)
  68. : m_deferred(r)
  69. {
  70. }
  71. } m_lightShading; ///< Light shading.
  72. class
  73. {
  74. public:
  75. ShaderProgramResourcePtr m_prog;
  76. ShaderProgramPtr m_grProg;
  77. } m_irradiance; ///< Irradiance.
  78. InternalContext* m_giCtx = nullptr;
  79. DynamicArray<CacheEntry> m_cacheEntries;
  80. HashMap<U64, U32> m_probeUuidToCacheEntryIdx;
  81. U32 m_tileSize = 0;
  82. U32 m_maxVisibleProbes = 0;
  83. Error initInternal();
  84. Error initGBuffer();
  85. Error initShadowMapping();
  86. Error initLightShading();
  87. Error initIrradiance();
  88. void runGBufferInThread(RenderPassWorkContext& rgraphCtx, InternalContext& giCtx) const;
  89. void runShadowmappingInThread(RenderPassWorkContext& rgraphCtx, InternalContext& giCtx) const;
  90. void runLightShading(RenderPassWorkContext& rgraphCtx, InternalContext& giCtx);
  91. void runIrradiance(RenderPassWorkContext& rgraphCtx, InternalContext& giCtx);
  92. void prepareProbes(InternalContext& giCtx);
  93. };
  94. /// @}
  95. } // end namespace anki