Browse Source

Add some missing render queue functionality

Panagiotis Christopoulos Charitos 8 năm trước cách đây
mục cha
commit
301e97215b

+ 1 - 1
sandbox/Main.cpp

@@ -111,7 +111,7 @@ Error MyApp::userMainLoop(Bool& quit)
 	}
 	if(in.getKey(KeyCode::_2))
 	{
-		mover = &scene.findSceneNode("Lamp").getComponent<MoveComponent>();
+		mover = &scene.findSceneNode("decal0").getComponent<MoveComponent>();
 	}
 
 	if(in.getKey(KeyCode::L) == 1)

+ 0 - 1
src/anki/collision/Aabb.cpp

@@ -6,7 +6,6 @@
 #include <anki/collision/Aabb.h>
 #include <anki/collision/Plane.h>
 #include <anki/collision/Obb.h>
-#include <array>
 
 namespace anki
 {

+ 7 - 1
src/anki/renderer/Common.h

@@ -30,7 +30,6 @@ class Tonemapping;
 class Bloom;
 class FinalComposite;
 class Dbg;
-class Tiler;
 class Indirect;
 class ForwardShadingUpscale;
 class DownscaleBlur;
@@ -41,6 +40,13 @@ class TemporalAA;
 class RenderingContext;
 class DebugDrawer;
 
+class RenderQueue;
+class RenderableQueueElement;
+class PointLightQueueElement;
+class SpotLightQueueElement;
+class ReflectionProbeQueueElement;
+class DecalQueueElement;
+
 class ShaderProgramResourceVariant;
 
 /// @addtogroup renderer

+ 23 - 4
src/anki/renderer/RenderQueue.h

@@ -12,9 +12,6 @@
 namespace anki
 {
 
-// Forward
-class RenderQueue;
-
 /// @addtogroup renderer
 /// @{
 
@@ -47,6 +44,9 @@ public:
 	F32 m_distanceFromCamera;
 };
 
+static_assert(
+	std::is_trivially_destructible<RenderableQueueElement>::value == true, "Should be trivially destructible");
+
 class PointLightQueueElement final
 {
 public:
@@ -59,6 +59,9 @@ public:
 	U32 m_textureArrayIndex; ///< Renderer internal.
 };
 
+static_assert(
+	std::is_trivially_destructible<PointLightQueueElement>::value == true, "Should be trivially destructible");
+
 class SpotLightQueueElement final
 {
 public:
@@ -73,6 +76,8 @@ public:
 	U32 m_textureArrayIndex; ///< Renderer internal.
 };
 
+static_assert(std::is_trivially_destructible<SpotLightQueueElement>::value == true, "Should be trivially destructible");
+
 /// Normally the visibility tests don't perform tests on the reflection probes because probes dont's change that often.
 /// This callback will be used by the renderer to inform a reflection probe that on the next frame it will be rendererd.
 /// In that case the probe should fill the render queues.
@@ -90,6 +95,9 @@ public:
 	U32 m_textureArrayIndex; ///< Renderer internal.
 };
 
+static_assert(
+	std::is_trivially_destructible<ReflectionProbeQueueElement>::value == true, "Should be trivially destructible");
+
 class LensFlareQueueElement final
 {
 public:
@@ -99,6 +107,8 @@ public:
 	Texture* m_texture; ///< Totaly unsafe but we can't have a smart ptr in here since there will be no deletion.
 };
 
+static_assert(std::is_trivially_destructible<LensFlareQueueElement>::value == true, "Should be trivially destructible");
+
 class DecalQueueElement final
 {
 public:
@@ -108,10 +118,16 @@ public:
 	Vec4 m_normalRoughnessAtlasUv;
 	F32 m_diffuseAtlasBlendFactor;
 	F32 m_normalRoughnessAtlasBlendFactor;
+	Mat4 m_textureMatrix;
+	Vec3 m_obbCenter;
+	Vec3 m_obbExtend;
+	Mat3 m_obbRotation;
 };
 
+static_assert(std::is_trivially_destructible<DecalQueueElement>::value == true, "Should be trivially destructible");
+
 /// The render queue.
-class RenderQueue
+class RenderQueue : public RenderingMatrices
 {
 public:
 	WeakArray<RenderableQueueElement> m_renderables; ///< Deferred shading or shadow renderables.
@@ -121,6 +137,9 @@ public:
 	WeakArray<ReflectionProbeQueueElement> m_reflectionProbes;
 	WeakArray<LensFlareQueueElement> m_lensFlares;
 	WeakArray<DecalQueueElement> m_decals;
+
+	/// Applies only if the RenderQueue holds shadow casters. It's the timesamp that modified
+	Timestamp m_shadowRenderablesLastUpdateTimestamp = 0;
 };
 /// @}
 

+ 9 - 0
src/anki/scene/DecalComponent.cpp

@@ -45,6 +45,7 @@ Error DecalComponent::setLayer(CString texAtlasFname, CString texAtlasSubtexName
 
 void DecalComponent::updateInternal()
 {
+	// Calculate the texture matrix
 	Mat4 worldTransform(m_trf);
 
 	Mat4 viewMat = worldTransform.getInverse();
@@ -59,6 +60,14 @@ void DecalComponent::updateInternal()
 	static const Mat4 biasMat4(0.5, 0.0, 0.0, 0.5, 0.0, 0.5, 0.0, 0.5, 0.0, 0.0, 0.5, 0.5, 0.0, 0.0, 0.0, 1.0);
 
 	m_biasProjViewMat = biasMat4 * projMat * viewMat;
+
+	// Calculate the OBB
+	Vec4 center(0.0f, 0.0f, -m_sizes.z() / 2.0f, 0.0f);
+	Vec4 extend(m_sizes.x() / 2.0f, m_sizes.y() / 2.0f, m_sizes.z() / 2.0f, 0.0f);
+
+	Obb obbL(center, Mat3x4::getIdentity(), extend);
+
+	m_obb = obbL.getTransformed(m_trf);
 }
 
 } // end namespace anki

+ 11 - 1
src/anki/scene/DecalComponent.h

@@ -61,6 +61,11 @@ public:
 		return m_sizes.z();
 	}
 
+	const Obb& getBoundingVolume() const
+	{
+		return m_obb;
+	}
+
 	void updateTransform(const Transform& trf)
 	{
 		ANKI_ASSERT(trf.getScale() == 1.0f);
@@ -125,6 +130,10 @@ public:
 		el.m_normalRoughnessAtlasUv = m_layers[LayerType::NORMAL_ROUGHNESS].m_uv;
 		el.m_diffuseAtlasBlendFactor = m_layers[LayerType::DIFFUSE].m_blendFactor;
 		el.m_normalRoughnessAtlasBlendFactor = m_layers[LayerType::NORMAL_ROUGHNESS].m_blendFactor;
+		el.m_textureMatrix = m_biasProjViewMat;
+		el.m_obbCenter = m_obb.getCenter().xyz();
+		el.m_obbExtend = m_obb.getExtend().xyz();
+		el.m_obbRotation = m_obb.getRotation().getRotationPart();
 	}
 
 private:
@@ -145,8 +154,9 @@ private:
 
 	Array<Layer, U(LayerType::COUNT)> m_layers;
 	Mat4 m_biasProjViewMat;
-	Vec3 m_sizes = Vec3(1.0);
+	Vec3 m_sizes = Vec3(1.0f);
 	Transform m_trf = Transform::getIdentity();
+	Obb m_obb = Obb(Vec4(0.0f), Mat3x4::getIdentity(), Vec4(1.0f, 1.0f, 1.0f, 0.0f));
 	Bool8 m_markedForUpdate = true;
 
 	ANKI_USE_RESULT Error setLayer(CString texAtlasFname, CString texAtlasSubtexName, F32 blendFactor, LayerType type);

+ 4 - 19
src/anki/scene/DecalNode.cpp

@@ -52,7 +52,7 @@ public:
 
 		if(decalc.getTimestamp() == node.getGlobalTimestamp())
 		{
-			static_cast<DecalNode&>(node).onDecalUpdated(decalc);
+			static_cast<DecalNode&>(node).onDecalUpdated();
 		}
 
 		return ErrorCode::NONE;
@@ -67,9 +67,9 @@ Error DecalNode::init()
 {
 	newComponent<MoveComponent>(this);
 	newComponent<DecalMoveFeedbackComponent>(this);
-	newComponent<DecalComponent>(this);
+	DecalComponent* decalc = newComponent<DecalComponent>(this);
 	newComponent<DecalShapeFeedbackComponent>(this);
-	newComponent<SpatialComponent>(this, &m_obbW);
+	newComponent<SpatialComponent>(this, &decalc->getBoundingVolume());
 
 	return ErrorCode::NONE;
 }
@@ -82,27 +82,12 @@ void DecalNode::onMove(MoveComponent& movec)
 
 	DecalComponent& decalc = getComponent<DecalComponent>();
 	decalc.updateTransform(movec.getWorldTransform());
-
-	updateObb(movec.getWorldTransform(), decalc);
 }
 
-void DecalNode::onDecalUpdated(DecalComponent& decalc)
+void DecalNode::onDecalUpdated()
 {
 	SpatialComponent& sc = getComponent<SpatialComponent>();
 	sc.markForUpdate();
-
-	const MoveComponent& movec = getComponent<MoveComponent>();
-	updateObb(movec.getWorldTransform(), decalc);
-}
-
-void DecalNode::updateObb(const Transform& trf, const DecalComponent& decalc)
-{
-	Vec4 center(0.0f, 0.0f, -decalc.getDepth() / 2.0f, 0.0f);
-	Vec4 extend(decalc.getWidth() / 2.0f, decalc.getHeight() / 2.0f, decalc.getDepth() / 2.0f, 0.0f);
-
-	Obb obbL(center, Mat3x4::getIdentity(), extend);
-
-	m_obbW = obbL.getTransformed(trf);
 }
 
 } // end namespace anki

+ 1 - 4
src/anki/scene/DecalNode.h

@@ -31,11 +31,8 @@ public:
 	ANKI_USE_RESULT Error init();
 
 private:
-	Obb m_obbW; ///< OBB in world space.
-
 	void onMove(MoveComponent& movec);
-	void onDecalUpdated(DecalComponent& decalc);
-	void updateObb(const Transform& trf, const DecalComponent& decalc);
+	void onDecalUpdated();
 };
 /// @}