ReflectionProbeComponent.h 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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. extern NumericCVar<U32> g_reflectionProbeResolutionCVar;
  13. /// @addtogroup scene
  14. /// @{
  15. /// Reflection probe component.
  16. class ReflectionProbeComponent : public QueryableSceneComponent<ReflectionProbeComponent>
  17. {
  18. ANKI_SCENE_COMPONENT(ReflectionProbeComponent)
  19. public:
  20. ReflectionProbeComponent(SceneNode* node);
  21. ~ReflectionProbeComponent();
  22. /// Set the local size of the probe volume.
  23. void setBoxVolumeSize(const Vec3& sizeXYZ)
  24. {
  25. m_halfSize = sizeXYZ / 2.0f;
  26. m_dirty = true;
  27. }
  28. Vec3 getBoxVolumeSize() const
  29. {
  30. return m_halfSize * 2.0f;
  31. }
  32. ANKI_INTERNAL WeakArray<Frustum> getFrustums()
  33. {
  34. return WeakArray<Frustum>(m_frustums);
  35. }
  36. ANKI_INTERNAL void setupReflectionProbeQueueElement(ReflectionProbeQueueElement& el) const
  37. {
  38. ANKI_ASSERT(!m_reflectionNeedsRefresh);
  39. ANKI_ASSERT(m_worldPos.x() != kMaxF32);
  40. el.m_worldPosition = m_worldPos;
  41. el.m_aabbMin = -m_halfSize + m_worldPos;
  42. el.m_aabbMax = m_halfSize + m_worldPos;
  43. ANKI_ASSERT(el.m_textureBindlessIndex != kMaxU32);
  44. el.m_textureBindlessIndex = m_reflectionTexBindlessIndex;
  45. el.m_index = m_gpuSceneProbe.getIndex();
  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. GpuSceneArrays::ReflectionProbe::Allocation m_gpuSceneProbe;
  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. };
  74. /// @}
  75. } // end namespace anki