DecalComponent.h 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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/GpuSceneArray.h>
  8. #include <AnKi/Resource/ImageAtlasResource.h>
  9. #include <AnKi/Collision/Obb.h>
  10. namespace anki {
  11. /// @addtogroup scene
  12. /// @{
  13. /// Decal component. Contains all the relevant info for a deferred decal.
  14. class DecalComponent : public SceneComponent
  15. {
  16. ANKI_SCENE_COMPONENT(DecalComponent)
  17. public:
  18. static constexpr U32 kAtlasSubImageMargin = 16;
  19. DecalComponent(SceneNode* node);
  20. ~DecalComponent();
  21. Bool isEnabled() const
  22. {
  23. return m_layers[LayerType::kDiffuse].m_bindlessTextureIndex != kMaxU32
  24. || m_layers[LayerType::kRoughnessMetalness].m_bindlessTextureIndex != kMaxU32;
  25. }
  26. void loadDiffuseImageResource(CString fname, F32 blendFactor)
  27. {
  28. setLayer(fname, blendFactor, LayerType::kDiffuse);
  29. }
  30. void loadRoughnessMetalnessImageResource(CString fname, F32 blendFactor)
  31. {
  32. setLayer(fname, blendFactor, LayerType::kRoughnessMetalness);
  33. }
  34. /// Update the internal structures.
  35. void setBoxVolumeSize(const Vec3& sizeXYZ)
  36. {
  37. m_boxSize = sizeXYZ;
  38. m_dirty = true;
  39. }
  40. const Vec3& getBoxVolumeSize() const
  41. {
  42. return m_boxSize;
  43. }
  44. private:
  45. enum class LayerType : U8
  46. {
  47. kDiffuse,
  48. kRoughnessMetalness,
  49. kCount
  50. };
  51. class Layer
  52. {
  53. public:
  54. ImageResourcePtr m_image;
  55. F32 m_blendFactor = 0.0f;
  56. U32 m_bindlessTextureIndex = kMaxU32;
  57. };
  58. Array<Layer, U(LayerType::kCount)> m_layers;
  59. Mat4 m_biasProjViewMat = Mat4::getIdentity();
  60. Vec3 m_boxSize = Vec3(1.0f);
  61. Obb m_obb = Obb(Vec4(0.0f), Mat3x4::getIdentity(), Vec4(0.5f, 0.5f, 0.5f, 0.0f));
  62. GpuSceneArrays::Decal::Allocation m_gpuSceneDecal;
  63. Bool m_dirty = true;
  64. void setLayer(CString fname, F32 blendFactor, LayerType type);
  65. Error update(SceneComponentUpdateInfo& info, Bool& updated) override;
  66. };
  67. /// @}
  68. } // end namespace anki