ReflectionProbeComponent.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. // Copyright (C) 2009-2023, 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/Spatial.h>
  9. #include <AnKi/Renderer/RenderQueue.h>
  10. #include <AnKi/Collision/Aabb.h>
  11. namespace anki {
  12. /// @addtogroup scene
  13. /// @{
  14. /// Reflection probe component.
  15. class ReflectionProbeComponent : public SceneComponent
  16. {
  17. ANKI_SCENE_COMPONENT(ReflectionProbeComponent)
  18. public:
  19. ReflectionProbeComponent(SceneNode* node);
  20. ~ReflectionProbeComponent();
  21. /// Set the local size of the probe volume.
  22. void setBoxVolumeSize(const Vec3& sizeXYZ)
  23. {
  24. m_halfSize = sizeXYZ / 2.0f;
  25. m_dirty = true;
  26. }
  27. Vec3 getBoxVolumeSize() const
  28. {
  29. return m_halfSize * 2.0f;
  30. }
  31. ANKI_INTERNAL WeakArray<Frustum> getFrustums()
  32. {
  33. return WeakArray<Frustum>(m_frustums);
  34. }
  35. ANKI_INTERNAL void setupReflectionProbeQueueElement(ReflectionProbeQueueElement& el) const
  36. {
  37. ANKI_ASSERT(!m_reflectionNeedsRefresh);
  38. ANKI_ASSERT(m_worldPos.x() != kMaxF32);
  39. el.m_worldPosition = m_worldPos;
  40. el.m_aabbMin = -m_halfSize + m_worldPos;
  41. el.m_aabbMax = m_halfSize + m_worldPos;
  42. ANKI_ASSERT(el.m_textureBindlessIndex != kMaxU32);
  43. el.m_textureBindlessIndex = m_reflectionTexBindlessIndex;
  44. ANKI_ASSERT(m_gpuSceneIndex != kMaxU32);
  45. el.m_index = m_gpuSceneIndex;
  46. }
  47. ANKI_INTERNAL void setupReflectionProbeQueueElementForRefresh(ReflectionProbeQueueElementForRefresh& el) const
  48. {
  49. ANKI_ASSERT(m_reflectionNeedsRefresh);
  50. el.m_worldPosition = m_worldPos;
  51. el.m_reflectionTexture = m_reflectionTex.get();
  52. }
  53. ANKI_INTERNAL Bool getReflectionNeedsRefresh() const
  54. {
  55. return m_reflectionNeedsRefresh;
  56. }
  57. ANKI_INTERNAL void setReflectionNeedsRefresh(Bool needsRefresh)
  58. {
  59. m_reflectionNeedsRefresh = needsRefresh;
  60. }
  61. private:
  62. Vec3 m_worldPos = Vec3(kMaxF32);
  63. Vec3 m_halfSize = Vec3(1.0f);
  64. U32 m_gpuSceneIndex = kMaxU32;
  65. Spatial m_spatial;
  66. Array<Frustum, 6> m_frustums;
  67. TexturePtr m_reflectionTex;
  68. TextureViewPtr m_reflectionView;
  69. U32 m_reflectionTexBindlessIndex = kMaxU32;
  70. Bool m_dirty = true;
  71. Bool m_reflectionNeedsRefresh = true;
  72. Error update(SceneComponentUpdateInfo& info, Bool& updated);
  73. void onDestroy(SceneNode& node);
  74. };
  75. /// @}
  76. } // end namespace anki