| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- // Copyright (C) 2009-2023, Panagiotis Christopoulos Charitos and contributors.
- // All rights reserved.
- // Code licensed under the BSD License.
- // http://www.anki3d.org/LICENSE
- #pragma once
- #include <AnKi/Scene/Components/SceneComponent.h>
- #include <AnKi/Scene/GpuSceneArray.h>
- #include <AnKi/Resource/ImageAtlasResource.h>
- #include <AnKi/Collision/Obb.h>
- namespace anki {
- /// @addtogroup scene
- /// @{
- /// Decal component. Contains all the relevant info for a deferred decal.
- class DecalComponent : public SceneComponent
- {
- ANKI_SCENE_COMPONENT(DecalComponent)
- public:
- static constexpr U32 kAtlasSubImageMargin = 16;
- DecalComponent(SceneNode* node);
- ~DecalComponent();
- Bool isEnabled() const
- {
- return m_layers[LayerType::kDiffuse].m_bindlessTextureIndex != kMaxU32
- || m_layers[LayerType::kRoughnessMetalness].m_bindlessTextureIndex != kMaxU32;
- }
- void loadDiffuseImageResource(CString fname, F32 blendFactor)
- {
- setLayer(fname, blendFactor, LayerType::kDiffuse);
- }
- void loadRoughnessMetalnessImageResource(CString fname, F32 blendFactor)
- {
- setLayer(fname, blendFactor, LayerType::kRoughnessMetalness);
- }
- /// Update the internal structures.
- void setBoxVolumeSize(const Vec3& sizeXYZ)
- {
- m_boxSize = sizeXYZ;
- m_dirty = true;
- }
- const Vec3& getBoxVolumeSize() const
- {
- return m_boxSize;
- }
- private:
- enum class LayerType : U8
- {
- kDiffuse,
- kRoughnessMetalness,
- kCount
- };
- class Layer
- {
- public:
- ImageResourcePtr m_image;
- F32 m_blendFactor = 0.0f;
- U32 m_bindlessTextureIndex = kMaxU32;
- };
- Array<Layer, U(LayerType::kCount)> m_layers;
- Mat4 m_biasProjViewMat = Mat4::getIdentity();
- Vec3 m_boxSize = Vec3(1.0f);
- Obb m_obb = Obb(Vec4(0.0f), Mat3x4::getIdentity(), Vec4(0.5f, 0.5f, 0.5f, 0.0f));
- GpuSceneArrays::Decal::Allocation m_gpuSceneDecal;
- Bool m_dirty = true;
- void setLayer(CString fname, F32 blendFactor, LayerType type);
- Error update(SceneComponentUpdateInfo& info, Bool& updated) override;
- };
- /// @}
- } // end namespace anki
|