LensFlareComponent.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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/SceneNode.h>
  7. #include <AnKi/Gr.h>
  8. #include <AnKi/Resource/ImageResource.h>
  9. #include <AnKi/Renderer/RenderQueue.h>
  10. namespace anki {
  11. /// @addtogroup scene
  12. /// @{
  13. /// Lens flare scene component.
  14. class LensFlareComponent final : public SceneComponent
  15. {
  16. ANKI_SCENE_COMPONENT(LensFlareComponent)
  17. public:
  18. LensFlareComponent(SceneNode* node);
  19. ~LensFlareComponent();
  20. ANKI_USE_RESULT Error loadImageResource(CString filename);
  21. Bool isLoaded() const
  22. {
  23. return m_image.isCreated();
  24. }
  25. CString getImageResourceFilename() const
  26. {
  27. return (m_image) ? m_image->getFilename() : CString();
  28. }
  29. void setWorldPosition(const Vec3& worldPosition)
  30. {
  31. m_worldPosition = worldPosition;
  32. }
  33. const Vec3& getWorldPosition() const
  34. {
  35. return m_worldPosition;
  36. }
  37. void setFirstFlareSize(const Vec2& size)
  38. {
  39. m_firstFlareSize = size;
  40. }
  41. const Vec2& getFirstFlareSize() const
  42. {
  43. return m_firstFlareSize;
  44. }
  45. void setOtherFlareSize(const Vec2& size)
  46. {
  47. m_otherFlareSize = size;
  48. }
  49. const Vec2& getOtherFlareSize() const
  50. {
  51. return m_otherFlareSize;
  52. }
  53. void setColorMultiplier(const Vec4& color)
  54. {
  55. m_colorMul = color;
  56. }
  57. const Vec4& getColorMultiplier() const
  58. {
  59. return m_colorMul;
  60. }
  61. TexturePtr getTexture() const
  62. {
  63. return m_image->getTexture();
  64. }
  65. void setupLensFlareQueueElement(LensFlareQueueElement& el) const
  66. {
  67. el.m_worldPosition = m_worldPosition;
  68. el.m_firstFlareSize = m_firstFlareSize;
  69. el.m_colorMultiplier = m_colorMul;
  70. el.m_textureView = m_image->getTextureView().get();
  71. el.m_userData = this;
  72. el.m_drawCallback = debugDrawCallback;
  73. }
  74. private:
  75. Vec4 m_colorMul = Vec4(1.0f); ///< Color multiplier.
  76. SceneNode* m_node;
  77. ImageResourcePtr m_image; ///< Array of textures.
  78. Vec2 m_firstFlareSize = Vec2(1.0f);
  79. Vec2 m_otherFlareSize = Vec2(1.0f);
  80. Vec3 m_worldPosition = Vec3(0.0f);
  81. static void debugDrawCallback(RenderQueueDrawContext& ctx, ConstWeakArray<void*> userData)
  82. {
  83. // Do nothing
  84. }
  85. };
  86. /// @}
  87. } // end namespace anki