Panagiotis Christopoulos Charitos 2 years ago
parent
commit
78eb03c792

+ 1 - 1
AnKi/Renderer/TileAllocator.cpp

@@ -261,7 +261,7 @@ TileAllocatorResult TileAllocator::allocate(Timestamp crntTimestamp, Timestamp l
 				tileViewport = {tile.m_viewport[0], tile.m_viewport[1], tile.m_viewport[2], tile.m_viewport[3]};
 
 				const Bool needsReRendering =
-					tile.m_lightDrawcallCount != drawcallCount || tile.m_lightTimestamp != lightTimestamp;
+					tile.m_lightDrawcallCount != drawcallCount || tile.m_lightTimestamp < lightTimestamp;
 
 				tile.m_lightTimestamp = lightTimestamp;
 				tile.m_lastUsedTimestamp = crntTimestamp;

+ 2 - 1
AnKi/Scene/Components/CameraComponent.cpp

@@ -72,7 +72,8 @@ Error CameraComponent::update(SceneComponentUpdateInfo& info, Bool& updated)
 
 	if(m_usesExtendedFrustum)
 	{
-		updated = updated || m_extendedFrustum.update();
+		const Bool extendedUpdated = m_extendedFrustum.update();
+		updated = updated || extendedUpdated;
 	}
 
 	return Error::kNone;

+ 9 - 5
AnKi/Scene/Components/GlobalIlluminationProbeComponent.cpp

@@ -53,9 +53,6 @@ Error GlobalIlluminationProbeComponent::update(SceneComponentUpdateInfo& info, B
 		m_spatial.setBoundingShape(aabb);
 	}
 
-	const Bool spatialUpdated = m_spatial.update(info.m_node->getSceneGraph().getOctree());
-	updated = updated || spatialUpdated;
-
 	if(m_markedForRendering) [[unlikely]]
 	{
 		updated = true;
@@ -80,11 +77,18 @@ Error GlobalIlluminationProbeComponent::update(SceneComponentUpdateInfo& info, B
 			// and that causes the sky to bleed to GI rendering
 			m_frustums[i].setLodDistances({effectiveDistance - 3.0f * kEpsilonf, effectiveDistance - 2.0f * kEpsilonf,
 										   effectiveDistance - 1.0f * kEpsilonf});
-
-			m_frustums[i].update();
 		}
 	}
 
+	for(U32 i = 0; i < 6; ++i)
+	{
+		const Bool frustumUpdated = m_frustums[i].update();
+		updated = updated || frustumUpdated;
+	}
+
+	const Bool spatialUpdated = m_spatial.update(info.m_node->getSceneGraph().getOctree());
+	updated = updated || spatialUpdated;
+
 	return Error::kNone;
 }
 

+ 9 - 6
AnKi/Scene/Components/LightComponent.cpp

@@ -86,7 +86,6 @@ Error LightComponent::update(SceneComponentUpdateInfo& info, Bool& updated)
 												 kPi / 2.0f);
 					m_frustums[i].setWorldTransform(Transform(m_worldTransform.getOrigin(),
 															  Frustum::getOmnidirectionalFrustumRotations()[i], 1.0f));
-					m_frustums[i].update();
 				}
 			}
 
@@ -103,8 +102,6 @@ Error LightComponent::update(SceneComponentUpdateInfo& info, Bool& updated)
 					m_frustums[i].setWorldTransform(Transform(m_worldTransform.getOrigin(),
 															  Frustum::getOmnidirectionalFrustumRotations()[i], 1.0f));
 				}
-
-				m_frustums[i].update();
 			}
 		}
 	}
@@ -142,7 +139,6 @@ Error LightComponent::update(SceneComponentUpdateInfo& info, Bool& updated)
 				m_frustums[0].setPerspective(kClusterObjectFrustumNearPlane, m_spot.m_distance, m_spot.m_outerAngle,
 											 m_spot.m_outerAngle);
 				m_frustums[0].setWorldTransform(m_worldTransform);
-				m_frustums[0].update();
 			}
 
 			// Update the frustum
@@ -157,8 +153,6 @@ Error LightComponent::update(SceneComponentUpdateInfo& info, Bool& updated)
 			{
 				m_frustums[0].setWorldTransform(m_worldTransform);
 			}
-
-			m_frustums[0].update();
 		}
 	}
 	else if(m_type == LightComponentType::kDirectional)
@@ -170,6 +164,15 @@ Error LightComponent::update(SceneComponentUpdateInfo& info, Bool& updated)
 	const Bool spatialUpdated = m_spatial.update(info.m_node->getSceneGraph().getOctree());
 	updated = updated || spatialUpdated;
 
+	if(m_shadow)
+	{
+		for(U32 i = 0; i < m_frustumCount; ++i)
+		{
+			const Bool frustumUpdated = m_frustums[i].update();
+			updated = updated || frustumUpdated;
+		}
+	}
+
 	return Error::kNone;
 }
 

+ 11 - 19
AnKi/Scene/Components/ReflectionProbeComponent.cpp

@@ -40,19 +40,10 @@ Error ReflectionProbeComponent::update(SceneComponentUpdateInfo& info, Bool& upd
 	m_dirty = false;
 	updated = moved || shapeUpdated;
 
-	if(moved) [[unlikely]]
+	if(updated) [[unlikely]]
 	{
 		m_worldPos = info.m_node->getWorldTransform().getOrigin().xyz();
 
-		for(U32 i = 0; i < 6; ++i)
-		{
-			m_frustums[i].setWorldTransform(
-				Transform(m_worldPos.xyz0(), Frustum::getOmnidirectionalFrustumRotations()[i], 1.0f));
-		}
-	}
-
-	if(shapeUpdated) [[unlikely]]
-	{
 		F32 effectiveDistance = max(m_halfSize.x(), m_halfSize.y());
 		effectiveDistance = max(effectiveDistance, m_halfSize.z());
 		effectiveDistance =
@@ -63,6 +54,9 @@ Error ReflectionProbeComponent::update(SceneComponentUpdateInfo& info, Bool& upd
 
 		for(U32 i = 0; i < 6; ++i)
 		{
+			m_frustums[i].setWorldTransform(
+				Transform(m_worldPos.xyz0(), Frustum::getOmnidirectionalFrustumRotations()[i], 1.0f));
+
 			m_frustums[i].setFar(effectiveDistance);
 			m_frustums[i].setShadowCascadeDistance(0, shadowCascadeDistance);
 
@@ -71,25 +65,23 @@ Error ReflectionProbeComponent::update(SceneComponentUpdateInfo& info, Bool& upd
 			m_frustums[i].setLodDistances({effectiveDistance - 3.0f * kEpsilonf, effectiveDistance - 2.0f * kEpsilonf,
 										   effectiveDistance - 1.0f * kEpsilonf});
 		}
-	}
 
-	if(updated) [[unlikely]]
-	{
 		// Set a new UUID to force the renderer to update the probe
 		m_uuid = info.m_node->getSceneGraph().getNewUuid();
 
-		for(U32 i = 0; i < 6; ++i)
-		{
-			m_frustums[i].update();
-		}
-
-		Aabb aabbWorld(-m_halfSize + m_worldPos, m_halfSize + m_worldPos);
+		const Aabb aabbWorld(-m_halfSize + m_worldPos, m_halfSize + m_worldPos);
 		m_spatial.setBoundingShape(aabbWorld);
 	}
 
 	const Bool spatialUpdated = m_spatial.update(info.m_node->getSceneGraph().getOctree());
 	updated = updated || spatialUpdated;
 
+	for(U32 i = 0; i < 6; ++i)
+	{
+		const Bool frustumUpdated = m_frustums[i].update();
+		updated = updated || frustumUpdated;
+	}
+
 	return Error::kNone;
 }
 

+ 2 - 0
AnKi/Scene/Frustum.cpp

@@ -195,6 +195,8 @@ Bool Frustum::update()
 		}
 	}
 
+	m_updatedThisFrame = updated;
+
 	return updated;
 }
 

+ 6 - 0
AnKi/Scene/Frustum.h

@@ -310,6 +310,11 @@ public:
 		m_earlyZDistance = dist;
 	}
 
+	Bool getUpdatedThisFrame() const
+	{
+		return m_updatedThisFrame;
+	}
+
 	Bool update();
 
 	/// Get the precalculated rotations of each of the 6 frustums of an omnidirectional source (eg a point light).
@@ -392,6 +397,7 @@ private:
 	Bool m_shapeDirty : 1 = true;
 	Bool m_miscDirty : 1 = true;
 	Bool m_worldTransformDirty : 1 = true;
+	Bool m_updatedThisFrame : 1 = true;
 
 	static Array<Mat3x4, 6> m_omnidirectionalRotations;
 };

+ 8 - 7
AnKi/Scene/Visibility.cpp

@@ -289,7 +289,6 @@ void VisibilityTestTask::test(ThreadHive& hive, U32 taskId)
 
 	// Iterate
 	RenderQueueView& result = m_frcCtx->m_queueViews[taskId];
-	[[maybe_unused]] U32 visibleCount = 0;
 	for(U i = 0; i < m_spatialToTestCount; ++i)
 	{
 		Spatial* spatial = m_spatialsToTest[i];
@@ -616,17 +615,19 @@ void VisibilityTestTask::test(ThreadHive& hive, U32 taskId)
 			}
 		}
 
-		++visibleCount;
-
 		// Update timestamp
-		Timestamp& timestamp = m_frcCtx->m_queueViews[taskId].m_timestamp;
 		ANKI_ASSERT(comp.getTimestamp() > 0);
-		timestamp = max(timestamp, comp.getTimestamp());
+		m_frcCtx->m_queueViews[taskId].m_timestamp =
+			max(m_frcCtx->m_queueViews[taskId].m_timestamp, comp.getTimestamp());
 	} // end for
 
-	if(visibleCount)
+	if(testedFrustum.getUpdatedThisFrame())
+	{
+		m_frcCtx->m_queueViews[taskId].m_timestamp = m_frcCtx->m_visCtx->m_scene->getGlobalTimestamp();
+	}
+	else
 	{
-		ANKI_ASSERT(m_frcCtx->m_queueViews[taskId].m_timestamp > 0);
+		m_frcCtx->m_queueViews[taskId].m_timestamp = max<Timestamp>(m_frcCtx->m_queueViews[taskId].m_timestamp, 1);
 	}
 }
 

+ 6 - 9
Samples/Sponza/Assets/Scene.lua

@@ -109,9 +109,9 @@ scene:setActiveCameraNode(node)
 comp = node:newCameraComponent()
 comp:setPerspective(0.100000, 200.000000, getMainRenderer():getAspectRatio() * 1.024779, 1.024779)
 trf = Transform.new()
-trf:setOrigin(Vec4.new(18.599913, 10.657731, 6.683091, 0))
+trf:setOrigin(Vec4.new(17.666607, 11.278920, 1.745400, 0))
 rot = Mat3x4.new()
-rot:setAll(0.598707, -0.049779, 0.799420, 0.000000, 0.011874, 0.998509, 0.053284, 0.000000, -0.800880, -0.022409, 0.598405, 0.000000)
+rot:setAll(0.214489, -0.116674, 0.969733, 0.000000, 0.011718, 0.993076, 0.116891, 0.000000, -0.976656, -0.013709, 0.214371, 0.000000)
 trf:setRotation(rot)
 trf:setScale(1.000000)
 node:setLocalTransform(trf)
@@ -1357,7 +1357,7 @@ node:newModelComponent():loadModelResource("Assets/arch_support_tiny_column_c_74
 trf = Transform.new()
 trf:setOrigin(Vec4.new(-24.851360, 11.845250, 9.920128, 0))
 rot = Mat3x4.new()
-rot:setAll(-0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, -1.000000, 0.000000, -0.000000, 0.000000)
+rot:setAll(0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, -1.000000, 0.000000, 0.000000, 0.000000)
 trf:setRotation(rot)
 trf:setScale(1.000000)
 node:setLocalTransform(trf)
@@ -1387,7 +1387,7 @@ node:newModelComponent():loadModelResource("Assets/arch_support_tiny_column_c_74
 trf = Transform.new()
 trf:setOrigin(Vec4.new(22.683060, 3.497290, -11.135740, 0))
 rot = Mat3x4.new()
-rot:setAll(-0.000000, 0.000000, -1.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 1.000000, 0.000000, -0.000000, 0.000000)
+rot:setAll(0.000000, 0.000000, -1.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 0.000000)
 trf:setRotation(rot)
 trf:setScale(1.000000)
 node:setLocalTransform(trf)
@@ -2257,7 +2257,7 @@ node:newModelComponent():loadModelResource("Assets/arch_support_tiny_column_c_74
 trf = Transform.new()
 trf:setOrigin(Vec4.new(-24.851360, 3.497289, 9.920128, 0))
 rot = Mat3x4.new()
-rot:setAll(-0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, -1.000000, 0.000000, -0.000000, 0.000000)
+rot:setAll(0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, -1.000000, 0.000000, 0.000000, 0.000000)
 trf:setRotation(rot)
 trf:setScale(1.000000)
 node:setLocalTransform(trf)
@@ -2687,7 +2687,7 @@ node:newModelComponent():loadModelResource("Assets/arch_support_tiny_column_c_74
 trf = Transform.new()
 trf:setOrigin(Vec4.new(22.683060, 11.845250, -11.135740, 0))
 rot = Mat3x4.new()
-rot:setAll(-0.000000, 0.000000, -1.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 1.000000, 0.000000, -0.000000, 0.000000)
+rot:setAll(0.000000, 0.000000, -1.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 0.000000)
 trf:setRotation(rot)
 trf:setScale(1.000000)
 node:setLocalTransform(trf)
@@ -2874,6 +2874,3 @@ rot:setAll(1.000000, 0.000000, 0.000000, 0.000000, 0.000000, -0.376587, 0.926381
 trf:setRotation(rot)
 trf:setScale(1.000000)
 node:setLocalTransform(trf)
-
-node = scene:tryFindSceneNode("Camera.001")
-getEventManager():newAnimationEvent("Assets/Camera.001Action.003_67159cf18109479.ankianim", "Camera.001", node)

BIN
Samples/Sponza/Assets/arch_support_big_68d8367a811fb94b.ankimesh


BIN
Samples/Sponza/Assets/arch_support_med_f674c0ad36e855d5.ankimesh


BIN
Samples/Sponza/Assets/arch_support_tiny_6e5678a158e0a576.ankimesh


BIN
Samples/Sponza/Assets/carpet_9773eaac1e11dc54.ankimesh


BIN
Samples/Sponza/Assets/ceiling_3fd94cde277a48e1.ankimesh


BIN
Samples/Sponza/Assets/fabric_a_945c29fc221550fb.ankimesh


BIN
Samples/Sponza/Assets/fabric_b_e8dd2769dc642ab7.ankimesh


BIN
Samples/Sponza/Assets/vase_45c3983f6cc9c489.ankimesh