|
|
@@ -0,0 +1,97 @@
|
|
|
+// Copyright (C) 2009-2018, 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/renderer/RenderQueue.h>
|
|
|
+#include <anki/collision/Aabb.h>
|
|
|
+#include <anki/collision/Sphere.h>
|
|
|
+
|
|
|
+namespace anki
|
|
|
+{
|
|
|
+
|
|
|
+/// @addtogroup scene
|
|
|
+/// @{
|
|
|
+
|
|
|
+/// Fog density component. Controls the fog density.
|
|
|
+class FogDensityComponent : public SceneComponent
|
|
|
+{
|
|
|
+public:
|
|
|
+ static const SceneComponentType CLASS_TYPE = SceneComponentType::FOG_DENSITY;
|
|
|
+
|
|
|
+ FogDensityComponent(SceneNode* node)
|
|
|
+ : SceneComponent(CLASS_TYPE, node)
|
|
|
+ {
|
|
|
+ }
|
|
|
+
|
|
|
+ void setBoundingBox(const Vec4& aabbMin, const Vec4& aabbMax)
|
|
|
+ {
|
|
|
+ m_aabbMin = aabbMin;
|
|
|
+ m_aabbMax = aabbMax;
|
|
|
+ m_box = true;
|
|
|
+ }
|
|
|
+
|
|
|
+ void setSphere(F32 radius)
|
|
|
+ {
|
|
|
+ m_sphereRadius = radius;
|
|
|
+ m_box = false;
|
|
|
+ }
|
|
|
+
|
|
|
+ void setDensity(F32 d)
|
|
|
+ {
|
|
|
+ ANKI_ASSERT(d >= 0.0f);
|
|
|
+ m_density = d;
|
|
|
+ }
|
|
|
+
|
|
|
+ F32 getDensity() const
|
|
|
+ {
|
|
|
+ return m_density;
|
|
|
+ }
|
|
|
+
|
|
|
+ void updatePosition(const Vec4& pos)
|
|
|
+ {
|
|
|
+ m_worldPos = pos;
|
|
|
+ }
|
|
|
+
|
|
|
+ void setupFogDensityQueueElement(FogDensityQueueElement& el) const
|
|
|
+ {
|
|
|
+ el.m_density = m_density;
|
|
|
+ el.m_isBox = m_box;
|
|
|
+ if(m_box)
|
|
|
+ {
|
|
|
+ el.m_aabbMin = (m_aabbMin + m_worldPos).xyz();
|
|
|
+ el.m_aabbMax = (m_aabbMax + m_worldPos).xyz();
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ el.m_sphereCenter = m_worldPos.xyz();
|
|
|
+ el.m_sphereRadius = m_sphereRadius;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /// Implements SceneComponent::update.
|
|
|
+ ANKI_USE_RESULT Error update(Second, Second, Bool& updated) override
|
|
|
+ {
|
|
|
+ updated = false;
|
|
|
+ return Error::NONE;
|
|
|
+ }
|
|
|
+
|
|
|
+private:
|
|
|
+ Vec4 m_aabbMin{0.0f};
|
|
|
+
|
|
|
+ union
|
|
|
+ {
|
|
|
+ Vec4 m_aabbMax{1.0f};
|
|
|
+ F32 m_sphereRadius;
|
|
|
+ };
|
|
|
+
|
|
|
+ Vec4 m_worldPos{0.0f};
|
|
|
+
|
|
|
+ F32 m_density = 1.0f;
|
|
|
+ Bool8 m_box = false;
|
|
|
+};
|
|
|
+
|
|
|
+} // end namespace anki
|