DecalComponent.h 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. // Copyright (C) 2009-present, 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 loadMetalRoughnessImageResource(CString fname, F32 blendFactor)
  31. {
  32. setLayer(fname, blendFactor, LayerType::kRoughnessMetalness);
  33. }
  34. private:
  35. enum class LayerType : U8
  36. {
  37. kDiffuse,
  38. kRoughnessMetalness,
  39. kCount
  40. };
  41. class Layer
  42. {
  43. public:
  44. ImageResourcePtr m_image;
  45. F32 m_blendFactor = 1.0f;
  46. U32 m_bindlessTextureIndex = kMaxU32;
  47. };
  48. ImageResourcePtr m_defaultDecalImage; ///< Keep that loaded to avoid loading it all the time when a new decal is constructed.
  49. Array<Layer, U(LayerType::kCount)> m_layers;
  50. GpuSceneArrays::Decal::Allocation m_gpuSceneDecal;
  51. Bool m_dirty = true;
  52. void setLayer(CString fname, F32 blendFactor, LayerType type);
  53. void update(SceneComponentUpdateInfo& info, Bool& updated) override;
  54. };
  55. /// @}
  56. } // end namespace anki