LensFlareComponent.h 2.1 KB

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