Browse Source

Push the scene stuff

Panagiotis Christopoulos Charitos 7 years ago
parent
commit
a49d6f7a4c

+ 1 - 0
README.md

@@ -36,6 +36,7 @@ Prerequisites:
 - GCC 5.0 and up or Clang 3.7 and up
 - libx11-dev installed
 - libxrandr-dev installed
+- libx11-xcb-dev installed
 - [Optional] libxinerama-dev if you want proper multi-monitor support
 
 To build the release version:

+ 2 - 0
src/anki/Scene.h

@@ -21,6 +21,7 @@
 #include <anki/scene/Octree.h>
 #include <anki/scene/PhysicsDebugNode.h>
 #include <anki/scene/TriggerNode.h>
+#include <anki/scene/FogDensityNode.h>
 
 #include <anki/scene/components/MoveComponent.h>
 #include <anki/scene/components/RenderComponent.h>
@@ -38,6 +39,7 @@
 #include <anki/scene/components/FrustumComponent.h>
 #include <anki/scene/components/JointComponent.h>
 #include <anki/scene/components/TriggerComponent.h>
+#include <anki/scene/components/FogDensityComponent.h>
 
 #include <anki/scene/events/EventManager.h>
 #include <anki/scene/events/Event.h>

+ 27 - 0
src/anki/renderer/RenderQueue.h

@@ -208,6 +208,33 @@ public:
 
 static_assert(std::is_trivially_destructible<UiQueueElement>::value == true, "Should be trivially destructible");
 
+/// Fog density queue element.
+class FogDensityQueueElement final
+{
+public:
+	union
+	{
+		Vec3 m_aabbMin;
+		Vec3 m_sphereCenter;
+	};
+
+	union
+	{
+		Vec3 m_aabbMax;
+		F32 m_sphereRadius;
+	};
+
+	F32 m_density;
+	Bool8 m_isBox;
+
+	FogDensityQueueElement()
+	{
+	}
+};
+
+static_assert(
+	std::is_trivially_destructible<FogDensityQueueElement>::value == true, "Should be trivially destructible");
+
 /// A callback to fill a coverage buffer.
 using FillCoverageBufferCallback = void (*)(void* userData, F32* depthValues, U32 width, U32 height);
 

+ 45 - 0
src/anki/scene/FogDensityNode.cpp

@@ -0,0 +1,45 @@
+// Copyright (C) 2009-2018, Panagiotis Christopoulos Charitos and contributors.
+// All rights reserved.
+// Code licensed under the BSD License.
+// http://www.anki3d.org/LICENSE
+
+#include <anki/scene/FogDensityNode.h>
+#include <anki/scene/components/MoveComponent.h>
+#include <anki/scene/components/FogDensityComponent.h>
+
+namespace anki
+{
+
+class FogDensityNode::FeedbackComponent : public SceneComponent
+{
+public:
+	FeedbackComponent(SceneNode* node)
+		: SceneComponent(SceneComponentType::NONE, node)
+	{
+	}
+
+	ANKI_USE_RESULT Error update(Second, Second, Bool& updated) override
+	{
+		updated = false;
+
+		MoveComponent& movec = m_node->getComponent<MoveComponent>();
+		if(movec.getTimestamp() == m_node->getGlobalTimestamp())
+		{
+			FogDensityComponent& fogc = m_node->getComponent<FogDensityComponent>();
+			fogc.updatePosition(movec.getWorldTransform().getOrigin());
+		}
+
+		return Error::NONE;
+	}
+};
+
+FogDensityNode::FogDensityNode(SceneGraph* scene, CString name)
+	: SceneNode(scene, name)
+{
+	// Create components
+	newComponent<MoveComponent>(MoveComponentFlag::NONE);
+	newComponent<FeedbackComponent>();
+	newComponent<FogDensityComponent>();
+}
+
+} // end namespace anki

+ 34 - 0
src/anki/scene/FogDensityNode.h

@@ -0,0 +1,34 @@
+// 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/SceneNode.h>
+
+namespace anki
+{
+
+/// @addtogroup scene
+/// @{
+
+/// Fog density node.
+class FogDensityNode : public SceneNode
+{
+public:
+	FogDensityNode(SceneGraph* scene, CString name);
+
+	~FogDensityNode();
+
+	ANKI_USE_RESULT Error init()
+	{
+		return Error::NONE;
+	}
+
+private:
+	class FeedbackComponent;
+};
+/// @}
+
+} // end namespace anki

+ 97 - 0
src/anki/scene/components/FogDensityComponent.h

@@ -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

+ 2 - 0
src/anki/scene/components/SceneComponent.h

@@ -34,6 +34,7 @@ enum class SceneComponentType : U16
 	SCRIPT,
 	JOINT,
 	TRIGGER,
+	FOG_DENSITY,
 	PLAYER_CONTROLLER,
 
 	COUNT,
@@ -74,6 +75,7 @@ public:
 	/// Called only by the SceneGraph
 	ANKI_USE_RESULT Error updateReal(Second prevTime, Second crntTime, Bool& updated);
 
+	/// Unique ID in the same run.
 	U64 getUuid() const
 	{
 		return m_uuid;