Browse Source

Fixing a clusterer bug and a reflection bug

Panagiotis Christopoulos Charitos 10 years ago
parent
commit
4afac13098
3 changed files with 29 additions and 11 deletions
  1. 3 0
      include/anki/renderer/Clusterer.h
  2. 25 10
      src/renderer/Clusterer.cpp
  3. 1 1
      src/renderer/Ir.cpp

+ 3 - 0
include/anki/renderer/Clusterer.h

@@ -135,6 +135,9 @@ public:
 
 
 	/// Calculate and set a right looking plane.
 	/// Calculate and set a right looking plane.
 	void calcPlaneX(U j, const Vec4& projParams);
 	void calcPlaneX(U j, const Vec4& projParams);
+
+	/// Call this when a shape is visible by all tiles.
+	void totallyInsideAllTiles(U zBegin, U zEnd, ClustererTestResult& rez) const;
 };
 };
 /// @}
 /// @}
 
 

+ 25 - 10
src/renderer/Clusterer.cpp

@@ -239,6 +239,22 @@ void Clusterer::bin(const CollisionShape& cs, const Aabb& csBox,
 	}
 	}
 }
 }
 
 
+//==============================================================================
+void Clusterer::totallyInsideAllTiles(
+	U zBegin, U zEnd, ClustererTestResult& rez) const
+{
+	for(U z = zBegin; z < zEnd; ++z)
+	{
+		for(U y = 0; y < m_counts[1]; ++y)
+		{
+			for(U x = 0; x < m_counts[0]; ++x)
+			{
+				rez.pushBack(x, y, z);
+			}
+		}
+	}
+}
+
 //==============================================================================
 //==============================================================================
 void Clusterer::binSphere(const Sphere& s, const Aabb& aabb,
 void Clusterer::binSphere(const Sphere& s, const Aabb& aabb,
 	ClustererTestResult& rez) const
 	ClustererTestResult& rez) const
@@ -257,16 +273,7 @@ void Clusterer::binSphere(const Sphere& s, const Aabb& aabb,
 	if(ANKI_UNLIKELY(eye.getLengthSquared() <= srad * srad))
 	if(ANKI_UNLIKELY(eye.getLengthSquared() <= srad * srad))
 	{
 	{
 		// Camera totaly inside the sphere
 		// Camera totaly inside the sphere
-		for(U z = zBegin; z < zEnd; ++z)
-		{
-			for(U y = 0; y < m_counts[1]; ++y)
-			{
-				for(U x = 0; x < m_counts[0]; ++x)
-				{
-					rez.pushBack(x, y, z);
-				}
-			}
-		}
+		totallyInsideAllTiles(zBegin, zEnd, rez);
 		return;
 		return;
 	}
 	}
 
 
@@ -286,6 +293,14 @@ void Clusterer::binSphere(const Sphere& s, const Aabb& aabb,
 	for(Vec4& p : points)
 	for(Vec4& p : points)
 	{
 	{
 		p = vp * p;
 		p = vp * p;
+		if(p.w() <= 0.0)
+		{
+			// This point is behind the near plane. It's a big hustle to
+			// properly clip it. Mark the shape totally inside
+			totallyInsideAllTiles(zBegin, zEnd, rez);
+			return;
+		}
+
 		p = p.perspectiveDivide();
 		p = p.perspectiveDivide();
 
 
 		for(U i = 0; i < 2; ++i)
 		for(U i = 0; i < 2; ++i)

+ 1 - 1
src/renderer/Ir.cpp

@@ -61,7 +61,7 @@ public:
 		if(m_probeCount > 0)
 		if(m_probeCount > 0)
 		{
 		{
 			if(memcmp(&m_probeIds[0], &b.m_probeIds[0],
 			if(memcmp(&m_probeIds[0], &b.m_probeIds[0],
-				sizeof(U32) * m_probeCount) != 0)
+				sizeof(m_probeIds[0]) * m_probeCount) != 0)
 			{
 			{
 				return false;
 				return false;
 			}
 			}