ReflectionProbeComponent.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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/Scene/Components/SceneComponent.h>
  7. #include <AnKi/Renderer/RenderQueue.h>
  8. #include <AnKi/Collision/Aabb.h>
  9. namespace anki {
  10. /// @addtogroup scene
  11. /// @{
  12. /// Reflection probe component.
  13. class ReflectionProbeComponent : public SceneComponent
  14. {
  15. ANKI_SCENE_COMPONENT(ReflectionProbeComponent)
  16. public:
  17. ReflectionProbeComponent(SceneNode* node);
  18. ~ReflectionProbeComponent();
  19. /// Set the local size of the probe volume.
  20. void setBoxVolumeSize(const Vec3& sizeXYZ)
  21. {
  22. m_halfSize = sizeXYZ / 2.0f;
  23. m_markedForUpdate = true;
  24. }
  25. Vec3 getBoxVolumeSize() const
  26. {
  27. return m_halfSize * 2.0f;
  28. }
  29. Vec3 getWorldPosition() const
  30. {
  31. return m_worldPos;
  32. }
  33. void setWorldPosition(const Vec3& pos)
  34. {
  35. m_worldPos = pos;
  36. m_markedForUpdate = true;
  37. }
  38. Aabb getAabbWorldSpace() const
  39. {
  40. return Aabb(-m_halfSize + m_worldPos, m_halfSize + m_worldPos);
  41. }
  42. Bool getMarkedForRendering() const
  43. {
  44. return m_markedForRendering;
  45. }
  46. void setupReflectionProbeQueueElement(ReflectionProbeQueueElement& el) const
  47. {
  48. el.m_feedbackCallback = reflectionProbeQueueElementFeedbackCallback;
  49. el.m_feedbackCallbackUserData = const_cast<ReflectionProbeComponent*>(this);
  50. el.m_uuid = m_uuid;
  51. el.m_worldPosition = m_worldPos;
  52. el.m_aabbMin = -m_halfSize + m_worldPos;
  53. el.m_aabbMax = m_halfSize + m_worldPos;
  54. el.m_textureArrayIndex = MAX_U32;
  55. el.m_debugDrawCallback = [](RenderQueueDrawContext& ctx, ConstWeakArray<void*> userData) {
  56. ANKI_ASSERT(userData.getSize() == 1);
  57. static_cast<const ReflectionProbeComponent*>(userData[0])->draw(ctx);
  58. };
  59. el.m_debugDrawCallbackUserData = this;
  60. }
  61. Error update(SceneNode& node, Second prevTime, Second crntTime, Bool& updated) override
  62. {
  63. updated = m_markedForUpdate;
  64. m_markedForUpdate = false;
  65. return Error::NONE;
  66. }
  67. private:
  68. SceneNode* m_node = nullptr;
  69. U64 m_uuid = 0;
  70. Vec3 m_worldPos = Vec3(0.0f);
  71. Vec3 m_halfSize = Vec3(1.0f);
  72. Bool m_markedForRendering : 1;
  73. Bool m_markedForUpdate : 1;
  74. ImageResourcePtr m_debugImage;
  75. static void reflectionProbeQueueElementFeedbackCallback(Bool fillRenderQueuesOnNextFrame, void* userData)
  76. {
  77. ANKI_ASSERT(userData);
  78. static_cast<ReflectionProbeComponent*>(userData)->m_markedForRendering = fillRenderQueuesOnNextFrame;
  79. }
  80. void draw(RenderQueueDrawContext& ctx) const;
  81. };
  82. /// @}
  83. } // end namespace anki