IndirectDiffuseProbes.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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/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. ANKI_USE_RESULT 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. SamplerPtr m_shadowSampler;
  61. } m_shadowMapping;
  62. class LS
  63. {
  64. public:
  65. RenderTargetDescription m_rtDescr;
  66. FramebufferDescription m_fbDescr;
  67. TraditionalDeferredLightShading m_deferred;
  68. LS(Renderer* r)
  69. : m_deferred(r)
  70. {
  71. }
  72. } m_lightShading; ///< Light shading.
  73. class
  74. {
  75. public:
  76. ShaderProgramResourcePtr m_prog;
  77. ShaderProgramPtr m_grProg;
  78. } m_irradiance; ///< Irradiance.
  79. InternalContext* m_giCtx = nullptr;
  80. DynamicArray<CacheEntry> m_cacheEntries;
  81. HashMap<U64, U32> m_probeUuidToCacheEntryIdx;
  82. U32 m_tileSize = 0;
  83. U32 m_maxVisibleProbes = 0;
  84. ANKI_USE_RESULT Error initInternal();
  85. ANKI_USE_RESULT Error initGBuffer();
  86. ANKI_USE_RESULT Error initShadowMapping();
  87. ANKI_USE_RESULT Error initLightShading();
  88. ANKI_USE_RESULT Error initIrradiance();
  89. void runGBufferInThread(RenderPassWorkContext& rgraphCtx, InternalContext& giCtx) const;
  90. void runShadowmappingInThread(RenderPassWorkContext& rgraphCtx, InternalContext& giCtx) const;
  91. void runLightShading(RenderPassWorkContext& rgraphCtx, InternalContext& giCtx);
  92. void runIrradiance(RenderPassWorkContext& rgraphCtx, InternalContext& giCtx);
  93. void prepareProbes(InternalContext& giCtx);
  94. };
  95. /// @}
  96. } // end namespace anki