Index: /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Pvs.h
===================================================================
--- /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Pvs.h	(revision 3283)
+++ /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Pvs.h	(revision 3284)
@@ -11,4 +11,25 @@
 class Bvh;
 
+struct PvsEntry
+{
+	PvsEntry(SceneEntity *ent, float t): 
+	mEntity(ent)
+	//, mTimeStamp(t) 
+	{}
+
+	friend bool operator<(const PvsEntry &a, const PvsEntry &b);
+
+
+	///////////////
+
+	SceneEntity *mEntity;
+	//float mTimeStamp;
+};
+
+
+
+
+typedef std::vector<PvsEntry> PvsEntryContainer;
+
 
 /** Class representing the Potentially Visible Set (PVS) from a view cell.
@@ -16,5 +37,4 @@
 class Pvs
 {
-
 public:
 
@@ -22,12 +42,18 @@
 
 	bool Empty() const;
-
-	void AddEntry(Bvh *bvh, BvhNode *node);
+	/** Convencience method adding all scene entities associated with a bvh node.
+	*/
+	void AddEntry(Bvh *bvh, BvhNode *node, float timeStamp = -1);
 
 	int GetSize() const;
 
-	inline SceneEntity *GetEntry(int i) const;
+	inline SceneEntity *GetEntity(int i) const;
+	
+	inline PvsEntry GetEntry(int i) const;
 
-	inline void AddEntry(SceneEntity *ent, float timeStamp = 0.0f);
+	inline void AddEntry(const PvsEntry &entry);
+	/* Sort entries by timestamp
+	*/
+	void Sort();
 
 
@@ -35,12 +61,15 @@
 
 	/// vector of PVS entries
-	SceneEntityContainer mEntries; 
-	std::vector<float> mTimeStamps;
-
-	static bool sStoreTimeStamps;
+	PvsEntryContainer mEntries; 
 };
 
 
-inline SceneEntity *Pvs::GetEntry(int i) const 
+inline SceneEntity *Pvs::GetEntity(int i) const 
+{
+	return mEntries[i].mEntity; 
+}
+
+
+inline PvsEntry Pvs::GetEntry(int i) const 
 {
 	return mEntries[i]; 
@@ -48,12 +77,7 @@
 
 
-inline void Pvs::AddEntry(SceneEntity *ent, float timeStamp) 
+inline void Pvs::AddEntry(const PvsEntry &entry) 
 {
-	mEntries.push_back(ent); 
-
-	if (sStoreTimeStamps)
-	{
-		mTimeStamps.push_back(timeStamp);
-	}
+	mEntries.push_back(entry);
 }
 
@@ -65,5 +89,5 @@
 
 
-inline void Pvs::AddEntry(Bvh *bvh, BvhNode *node) 
+inline void Pvs::AddEntry(Bvh *bvh, BvhNode *node, float timeStamp) 
 {
 	int geometrySize;
@@ -73,7 +97,8 @@
 	for (int i = 0; i < geometrySize; ++ i)
 	{
-		AddEntry(entities[i]);
+		AddEntry(PvsEntry(entities[i], timeStamp));
 	}
 }
+
 
 
Index: /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Geometry.cpp
===================================================================
--- /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Geometry.cpp	(revision 3282)
+++ /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Geometry.cpp	(revision 3284)
@@ -40,5 +40,5 @@
 	if (delData)
 	{
-		//DEL_ARRAY_PTR(mVertices);
+		DEL_ARRAY_PTR(mVertices);
 		DEL_ARRAY_PTR(mNormals);
 		DEL_ARRAY_PTR(mTexCoords);
Index: /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg
===================================================================
--- /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg	(revision 3271)
+++ /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg	(revision 3284)
@@ -249,5 +249,5 @@
 		{
 			float2 mynoise = tex2Dlod(noiseTex, float4(IN.texCoord * 4.0f, 0, 0)).xy;
-			//offsetTransformed = myreflect(offset, mynoise);
+			//offset = myreflect(samples[i], mynoise);
 			offset = myrotate(samples[i], mynoise.x);
 		}
Index: /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg
===================================================================
--- /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg	(revision 3230)
+++ /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg	(revision 3284)
@@ -89,5 +89,5 @@
 	for (int i = 0; i < NUM_PCF_TABS; ++ i) 
 	{
-		const float2 offset = samples[i];
+		float2 offset;
 		const float w = weights[i];
 
@@ -96,11 +96,12 @@
 		//-- add random noise: reflect around random normal vector (warning: slow!)
 
-		float2 mynoise = tex2D(noiseTexture, IN.texCoord).xy;
-		const float2 offsetTransformed = myreflect(offset, mynoise);
+		float2 mynoise = tex2D(noiseTexture, IN.texCoord * 4.0f).xy;
+		//offset = myreflect(samples[i], mynoise);
+		offset = myrotate(samples[i], mynoise.x);
 #else
-		const float2 offsetTransformed = offset;
+		offset = samples[i];
 #endif
 		// weight with projected coordinate to reach similar kernel size for near and far
-		float2 texcoord = lightSpacePos + offsetTransformed * scale;
+		float2 texcoord = lightSpacePos + offset * scale;
 
 		float shadowDepth = tex2D(shadowMap, texcoord).x;
Index: /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/VisibilitySolutionLoader.cpp
===================================================================
--- /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/VisibilitySolutionLoader.cpp	(revision 3282)
+++ /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/VisibilitySolutionLoader.cpp	(revision 3284)
@@ -149,5 +149,6 @@
 	if (number != mViewCells.size()) 
 	{
-		cerr << "Warning: Number of view cells (" << number << ", " << (int)mViewCells.size() << ") does not match when loading PVSs!" << endl;
+		cerr << "Warning: Number of view cells (" << number << ", " 
+			 << (int)mViewCells.size() << ") does not match when loading PVSs!" << endl;
 		return false;
 	}
@@ -176,11 +177,7 @@
 
 			outstream << n->GetFirstEntity() << " " << n->GetLastEntity() << " " << n->GetBox() << " " << box << endl;
-			
-		}
-	}
-		
-	outstream.close();
-	
-
+		}
+	}
+		
 	for (int i = 0; i < number; ++ i) 
 	{
@@ -196,7 +193,11 @@
 	
 			BvhNode *node = nodes[objectId];
-			mViewCells[i]->mPvs.AddEntry(bvh, node);
-		}
-	}
+			if (i == 100)
+				outstream << "t " << time << " ";
+			mViewCells[i]->mPvs.AddEntry(bvh, node, time);
+		}
+	}
+
+	outstream.close();
 
 	return true;
Index: /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/PvsCollectionRenderer.h
===================================================================
--- /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/PvsCollectionRenderer.h	(revision 3258)
+++ /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/PvsCollectionRenderer.h	(revision 3284)
@@ -40,5 +40,6 @@
 	void SetViewCell(ViewCell *vc) { mViewCell = vc; }
 
-	virtual int GetType() const { return CULL_COLLECTOR; }
+	//virtual int GetType() const { return CULL_COLLECTOR; }
+	virtual int GetType() const { return -1; }
 
 protected:
Index: /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp
===================================================================
--- /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp	(revision 3282)
+++ /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp	(revision 3284)
@@ -154,4 +154,7 @@
 static int globalVisibleId = 0;
 
+PerfTimer applicationTimer;
+
+float shotRays = .0f;
 
 
@@ -927,7 +930,7 @@
 		tr = new CHCPlusPlusTraverser();
 		break;
-	case RenderTraverser::CULL_COLLECTOR:
-		tr = new PvsCollectionRenderer();
-		break;
+	//case RenderTraverser::CULL_COLLECTOR:
+	//	tr = new PvsCollectionRenderer();
+	//	break;
 	default:
 		tr = new FrustumCullingTraverser();
@@ -1229,5 +1232,9 @@
 	if (1 && usePvs)
 	{
-		if (!viewCellsTree)	LoadVisibilitySolution();
+		if (!viewCellsTree)	
+		{
+			applicationTimer.Start();
+			LoadVisibilitySolution();
+		}
 
 		if (viewCellsTree) LoadPvs();
@@ -1313,10 +1320,7 @@
 	else
 	{
-		if (traverser->GetType() == RenderTraverser::CULL_COLLECTOR)
-			((PvsCollectionRenderer *)traverser)->SetViewCell(usePvs ? viewCell : NULL);
-
-		//for (size_t i = 0; i < staticObjects.size(); ++ i)
-		//	staticObjects[i]->Render(&renderState);
-		
+		//if (traverser->GetType() == RenderTraverser::CULL_COLLECTOR)
+		//	((PvsCollectionRenderer *)traverser)->SetViewCell(usePvs ? viewCell : NULL);
+
 		// actually render the scene geometry using the specified algorithm
 		traverser->RenderScene();
@@ -2372,7 +2376,8 @@
 			, "CHC"
 			, "CHC ++"
-			, "Collector"
+//			, "Collector"
 		};
-		
+	
+#if 0
 		if (!showAlgorithmTime)
 		{
@@ -2388,8 +2393,9 @@
 			myfont.DrawString(msg[7], 1.3f, 690.0f, 760.0f);//, top_color, bottom_color);
 		}
-
-		
-		//sprintf(msg[8], "algorithm time: %6.1f ms", rTime);
-		//myfont.DrawString(msg[8], 720.0f, 730.0f);		
+#else
+		int mrays = (int)shotRays / 1000000;
+		sprintf(msg[7], "%s:  %04d M rays", alg_str[renderMode], mrays);	
+		myfont.DrawString(msg[7], 1.3f, 690.0f, 760.0f);//, top_color, bottom_color);
+#endif
 	}
 
@@ -2428,4 +2434,5 @@
 			RenderShadowMap(newFar);
 		}
+
 		// initialize deferred rendering
 		InitDeferredRendering();
@@ -2651,5 +2658,9 @@
 	viewCell = viewCellsTree->GetViewCell(camera->GetPosition());
 
-	int numTriangles = 0;
+	// assume 60 FPS and 1M rays per second
+	const float scale = 1e6f / 60.0f;
+
+	//const float elapsedAlgorithmTime = applicationTimer.Elapsedms(false);
+	//int numTriangles = 0;
 
 	SceneEntity::SetCurrentVisibleId(globalVisibleId);
@@ -2657,11 +2668,14 @@
 	for (int i = 0; i < viewCell->mPvs.GetSize(); ++ i)
 	{
-		SceneEntity *ent = viewCell->mPvs.GetEntry(i);
-		ent->SetVisibleId(globalVisibleId);
-		//ent->Render(&renderState);
-
-		numTriangles += ent->CountNumTriangles();
-	}
-
+		PvsEntry entry = viewCell->mPvs.GetEntry(i);
+
+		if (1)//(entry.mTimeStamp < 0.0f) || (entry.mTimeStamp <= shotRays))
+		{
+			entry.mEntity->SetVisibleId(globalVisibleId);
+			//numTriangles += entry.mEntity->CountNumTriangles();
+		}
+	}
+
+	shotRays += scale;
 	++ globalVisibleId;
 }
@@ -2701,5 +2715,6 @@
 void LoadPompeiiFloor()
 {
-	AxisAlignedBox3 pompeiiBox = SceneEntity::ComputeBoundingBox(staticObjects);
+	AxisAlignedBox3 pompeiiBox = 
+		SceneEntity::ComputeBoundingBox(staticObjects);
 
 	// todo: dispose texture
@@ -2722,6 +2737,8 @@
 	depthPass->SetLightingEnabled(false);
 
-	ShaderProgram *defaultFragmentTexProgramMrt = ShaderManager::GetSingleton()->GetShaderProgram("defaultFragmentTexMrt");
-	ShaderProgram *defaultVertexProgramMrt = ShaderManager::GetSingleton()->GetShaderProgram("defaultVertexMrt");
+	ShaderProgram *defaultFragmentTexProgramMrt =
+		ShaderManager::GetSingleton()->GetShaderProgram("defaultFragmentTexMrt");
+	ShaderProgram *defaultVertexProgramMrt = 
+		ShaderManager::GetSingleton()->GetShaderProgram("defaultVertexMrt");
 
 	deferred->SetFragmentProgram(defaultFragmentTexProgramMrt);
Index: /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Pvs.cpp
===================================================================
--- /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Pvs.cpp	(revision 3283)
+++ /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Pvs.cpp	(revision 3284)
@@ -7,5 +7,10 @@
 {
 
-bool Pvs::sStoreTimeStamps = false;
+
+bool operator<(const PvsEntry &a, const PvsEntry &b) 
+{
+   //return a.mTimeStamp < b.mTimeStamp;
+	return true;
+}
 
 
@@ -22,4 +27,9 @@
 
 
+void Pvs::Sort()
+{
+}
+
+
 
 }
Index: /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderTraverser.h
===================================================================
--- /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderTraverser.h	(revision 3258)
+++ /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderTraverser.h	(revision 3284)
@@ -54,5 +54,5 @@
 		  STOP_AND_WAIT, 
 		  CHC, CHCPLUSPLUS, 
-		  CULL_COLLECTOR,
+		  //CULL_COLLECTOR,
 		  NUM_TRAVERSAL_TYPES};
 
Index: /GTP/trunk/App/Demos/Vis/FriendlyCulling/FriendlyCulling.vcproj
===================================================================
--- /GTP/trunk/App/Demos/Vis/FriendlyCulling/FriendlyCulling.vcproj	(revision 3262)
+++ /GTP/trunk/App/Demos/Vis/FriendlyCulling/FriendlyCulling.vcproj	(revision 3284)
@@ -284,4 +284,12 @@
 			</File>
 			<File
+				RelativePath=".\src\VisibilitySolutionLoader.cpp"
+				>
+			</File>
+			<File
+				RelativePath=".\src\VisibilitySolutionLoader.h"
+				>
+			</File>
+			<File
 				RelativePath=".\src\WalkThroughRecorder.cpp"
 				>
@@ -579,8 +587,4 @@
 				</File>
 				<File
-					RelativePath=".\src\VisibilitySolutionLoader.h"
-					>
-				</File>
-				<File
 					RelativePath=".\src\Visualization.h"
 					>
@@ -683,4 +687,8 @@
 				</File>
 				<File
+					RelativePath=".\src\Pvs.cpp"
+					>
+				</File>
+				<File
 					RelativePath=".\src\RenderQueue.cpp"
 					>
@@ -778,8 +786,4 @@
 				<File
 					RelativePath=".\src\ViewCellsTree.cpp"
-					>
-				</File>
-				<File
-					RelativePath=".\src\VisibilitySolutionLoader.cpp"
 					>
 				</File>
Index: /GTP/trunk/App/Demos/Vis/FriendlyCulling/default.env
===================================================================
--- /GTP/trunk/App/Demos/Vis/FriendlyCulling/default.env	(revision 3282)
+++ /GTP/trunk/App/Demos/Vis/FriendlyCulling/default.env	(revision 3284)
@@ -9,12 +9,12 @@
 #filename=vienna_full_hp
 #bvhname=vienna_full_hp
-filename=tryvienna2
-bvhname=tryvienna2
+#filename=tryvienna2
+#bvhname=tryvienna2
 #filename=mypompeii
 #bvhname=mypompeii
 #filename=pompeii/pompeii_full
 #filename=pompeii/pompeii_part
-#filename=city
-#bvhname=city
+filename=city
+bvhname=city
 useLODs=1
 # shadow map size
@@ -32,4 +32,6 @@
 # if using pvs, this specifies the name of the visibility solutin
 #visibilitySolution=vienna_full-8x3-pgv
+#visibilitySolution=vienna_full-8x3-spgvu
+#visibilitySolution=vienna_full-8x3-refu
 #visibilitySolution=mypompeii-1x1-pgv
 #visibilitySolution=mypompeii-2x1-obvh-pgv
