FogDensityComponent.h 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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/Collision/Aabb.h>
  9. #include <AnKi/Collision/Sphere.h>
  10. namespace anki {
  11. /// @addtogroup scene
  12. /// @{
  13. /// @memberof FogDensityComponent
  14. enum class FogDensityComponentShape : U8
  15. {
  16. kSphere,
  17. kBox,
  18. kCount
  19. };
  20. /// Fog density component. Controls the fog density.
  21. class FogDensityComponent : public SceneComponent
  22. {
  23. ANKI_SCENE_COMPONENT(FogDensityComponent)
  24. public:
  25. static constexpr F32 kMinShapeSize = 1.0_cm;
  26. FogDensityComponent(SceneNode* node);
  27. ~FogDensityComponent();
  28. void setShapeType(FogDensityComponentShape type)
  29. {
  30. if(ANKI_EXPECT(type < FogDensityComponentShape::kCount) && type != m_type)
  31. {
  32. m_type = type;
  33. m_dirty = true;
  34. }
  35. }
  36. FogDensityComponentShape getShapeType() const
  37. {
  38. return m_type;
  39. }
  40. void setDensity(F32 density)
  41. {
  42. if(ANKI_EXPECT(density >= 0.0f) && m_density != density)
  43. {
  44. m_dirty = true;
  45. m_density = density;
  46. }
  47. }
  48. F32 getDensity() const
  49. {
  50. return m_density;
  51. }
  52. private:
  53. GpuSceneArrays::FogDensityVolume::Allocation m_gpuSceneVolume;
  54. F32 m_density = 1.0f;
  55. FogDensityComponentShape m_type = FogDensityComponentShape::kSphere;
  56. Bool m_dirty = true;
  57. void update(SceneComponentUpdateInfo& info, Bool& updated) override;
  58. Error serialize(SceneSerializer& serializer) override;
  59. };
  60. } // end namespace anki