GlobalIlluminationProbeComponent.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. // Copyright (C) 2009-present, 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/Scene/Components/SceneComponent.h>
  7. #include <AnKi/Scene/Frustum.h>
  8. #include <AnKi/Scene/GpuSceneArray.h>
  9. #include <AnKi/Collision/Aabb.h>
  10. namespace anki {
  11. /// @addtogroup scene
  12. /// @{
  13. /// Global illumination probe component. It's an axis aligned box divided into cells.
  14. class GlobalIlluminationProbeComponent : public SceneComponent
  15. {
  16. ANKI_SCENE_COMPONENT(GlobalIlluminationProbeComponent)
  17. public:
  18. GlobalIlluminationProbeComponent(SceneNode* node);
  19. ~GlobalIlluminationProbeComponent();
  20. /// Set the cell size in meters.
  21. void setCellSize(F32 cellSize)
  22. {
  23. if(ANKI_EXPECT(cellSize > 0.0f) && m_cellSize != cellSize)
  24. {
  25. m_cellSize = cellSize;
  26. m_dirty = true;
  27. }
  28. }
  29. F32 getCellSize() const
  30. {
  31. return m_cellSize;
  32. }
  33. F32 getFadeDistance() const
  34. {
  35. return m_fadeDistance;
  36. }
  37. void setFadeDistance(F32 dist)
  38. {
  39. if(ANKI_EXPECT(dist > 0.0f) && m_fadeDistance != dist)
  40. {
  41. m_fadeDistance = dist;
  42. m_dirty = true;
  43. }
  44. }
  45. ANKI_INTERNAL Vec3 getBoxVolumeSize() const
  46. {
  47. return m_halfSize * 2.0f;
  48. }
  49. /// Check if any of the probe's cells need to be re-rendered.
  50. Bool getCellsNeedsRefresh() const
  51. {
  52. return m_cellsRefreshedCount < m_totalCellCount;
  53. }
  54. ANKI_INTERNAL U32 getNextCellForRefresh() const
  55. {
  56. ANKI_ASSERT(getCellsNeedsRefresh());
  57. return m_cellsRefreshedCount;
  58. }
  59. /// Add to the number of texels that got refreshed this frame.
  60. ANKI_INTERNAL void incrementRefreshedCells(U32 cellCount)
  61. {
  62. ANKI_ASSERT(getCellsNeedsRefresh());
  63. m_cellsRefreshedCount += cellCount;
  64. ANKI_ASSERT(m_cellsRefreshedCount <= m_totalCellCount);
  65. m_dirty = true;
  66. }
  67. /// The radius around the probe's center that can infuence the rendering of the env texture.
  68. ANKI_INTERNAL F32 getRenderRadius() const;
  69. ANKI_INTERNAL F32 getShadowsRenderRadius() const;
  70. ANKI_INTERNAL const Vec3& getWorldPosition() const
  71. {
  72. return m_worldPos;
  73. }
  74. ANKI_INTERNAL const UVec3& getCellCountsPerDimension() const
  75. {
  76. return m_cellCounts;
  77. }
  78. ANKI_INTERNAL U32 getCellCount() const
  79. {
  80. return m_totalCellCount;
  81. }
  82. ANKI_INTERNAL Texture& getVolumeTexture() const
  83. {
  84. return *m_volTex;
  85. }
  86. ANKI_INTERNAL const GpuSceneArrays::GlobalIlluminationProbe::Allocation& getGpuSceneAllocation() const
  87. {
  88. return m_gpuSceneProbe;
  89. }
  90. private:
  91. Vec3 m_halfSize = Vec3(0.5f);
  92. Vec3 m_worldPos = Vec3(0.0f);
  93. UVec3 m_cellCounts = UVec3(2u);
  94. U32 m_totalCellCount = 8u;
  95. F32 m_cellSize = 4.0f; ///< Cell size in meters.
  96. F32 m_fadeDistance = 0.2f;
  97. TexturePtr m_volTex;
  98. U32 m_volTexBindlessIdx = 0;
  99. GpuSceneArrays::GlobalIlluminationProbe::Allocation m_gpuSceneProbe;
  100. ShaderProgramResourcePtr m_clearTextureProg;
  101. U32 m_cellsRefreshedCount = 0;
  102. Bool m_dirty = true;
  103. void update(SceneComponentUpdateInfo& info, Bool& updated) override;
  104. };
  105. /// @}
  106. } // end namespace anki