2
0
Panagiotis Christopoulos Charitos 13 жил өмнө
parent
commit
9817f3fdcf

+ 2 - 1
include/anki/scene/Sector.h

@@ -11,6 +11,7 @@ class SceneNode;
 class Scene;
 class Sector;
 class SectorGroup;
+class Renderer;
 
 /// @addtogroup Scene
 /// @{
@@ -80,7 +81,7 @@ public:
 	void placeSceneNode(SceneNode* sp);
 
 	/// XXX
-	void doVisibilityTests(SceneNode& fr, VisibilityTest test);
+	void doVisibilityTests(SceneNode& fr, VisibilityTest test, Renderer* r);
 
 private:
 	Scene* scene; ///< Keep it here to access various allocators

+ 29 - 11
src/scene/Sector.cpp

@@ -5,6 +5,7 @@
 #include "anki/scene/Frustumable.h"
 #include "anki/scene/Scene.h"
 #include "anki/core/Logger.h"
+#include "anki/renderer/Renderer.h"
 
 namespace anki {
 
@@ -116,7 +117,8 @@ void SectorGroup::placeSceneNode(SceneNode* sn)
 }
 
 //==============================================================================
-void SectorGroup::doVisibilityTests(SceneNode& sn, VisibilityTest test)
+void SectorGroup::doVisibilityTests(SceneNode& sn, VisibilityTest test,
+	Renderer* r)
 {
 	Frustumable* fr = sn.getFrustumable();
 	ANKI_ASSERT(fr != nullptr);
@@ -137,18 +139,34 @@ void SectorGroup::doVisibilityTests(SceneNode& sn, VisibilityTest test)
 	// Loop all portals and add other sectors
 	for(Portal* portal : portals)
 	{
-		// Portal is visible
-		// XXX Add tiler test for portals
-		if(fr->insideFrustum(portal->shape))
+		// Get the "other" sector of that portal
+		Sector* testAgainstSector;
+
+		if(portal->sectors[0] == &containerSector)
 		{
-			if(portal->sectors[0] != &containerSector)
-			{
-				visibleSectors.push_back(portal->sectors[0]);
-			}
-			else
+			testAgainstSector = portal->sectors[1];
+		}
+		else
+		{
+			ANKI_ASSERT(portal->sectors[1] == &containerSector);
+			testAgainstSector = portal->sectors[0];
+		}
+
+		// Search if portal is in the container from another portal
+		SceneVector<Sector*>::iterator it = std::find(visibleSectors.begin(),
+			visibleSectors.end(), testAgainstSector);
+
+		if(it == visibleSectors.end())
+		{
+			// Not found so test the portal
+
+			// Portal is visible
+			if(fr->insideFrustum(portal->shape))
 			{
-				ANKI_ASSERT(portal->sectors[1] != &containerSector);
-				visibleSectors.push_back(portal->sectors[1]);
+				if(r == nullptr || r->doVisibilityTests(portal->shape))
+				{
+					visibleSectors.push_back(testAgainstSector);
+				}
 			}
 		}
 	}