Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Matrix4x4.h
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Matrix4x4.h	(revision 3102)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Matrix4x4.h	(revision 3279)
@@ -145,4 +145,5 @@
 								const Vector3 &vecTo);
 Matrix4x4 ScaleMatrix(float X, float Y, float Z);
+Matrix4x4 ScaleMatrix(float x);
 Matrix4x4 GenRotation(const Vector3 &x, const Vector3 &y,
 					  const Vector3 &z);
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/VisibilitySolutionLoader.h
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/VisibilitySolutionLoader.h	(revision 3257)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/VisibilitySolutionLoader.h	(revision 3279)
@@ -11,4 +11,5 @@
 struct ViewCell;
 class Bvh;
+class BvhNode;
 
 typedef std::vector<ViewCell *> ViewCellsContainer;
@@ -32,4 +33,7 @@
 	bool CreateIdSortedList(Bvh *bvh, BvhNodeContainer &nodes);
 
+	bool CreateIdSortedList2(BvhNode *n, BvhNodeContainer &nodes);
+
+
 	bool LoadPvs(FILE *fw, Bvh *bvh);
 
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/VisibilitySolutionLoader.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/VisibilitySolutionLoader.cpp	(revision 3271)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/VisibilitySolutionLoader.cpp	(revision 3279)
@@ -38,5 +38,4 @@
 
 	ViewCellsTree *viewCellsTree = new ViewCellsTree();
-
 	bool ok = viewCellsTree->_LoadFromFile(fr, viewCellsScaleFactor);
 
@@ -100,5 +99,5 @@
 		nodes.push_back(node);
 
-		if (!node->IsLeaf())
+		if (!node->IsVirtualLeaf())
 		{
 			BvhInterior *interior = static_cast<BvhInterior *>(node);
@@ -116,8 +115,27 @@
 
 
+bool VisibilitySolutionLoader::CreateIdSortedList2(BvhNode *n,
+												   BvhNodeContainer &nodes)
+{
+	nodes.push_back(n);
+
+	if (!n->IsVirtualLeaf())
+	{
+		BvhInterior *interior = static_cast<BvhInterior *>(n);
+
+		BvhNode *front = interior->GetFront();
+		BvhNode *back = interior->GetBack();
+
+		CreateIdSortedList2(front, nodes);
+		CreateIdSortedList2(back, nodes);
+	}
+
+	return true;
+}
+
+
 bool VisibilitySolutionLoader::LoadPvs(FILE *fw, Bvh *bvh)
 {
 	int number, entries;
-
 	fread(&number, sizeof(int), 1, fw);
 
@@ -135,6 +153,14 @@
 
 	BvhNodeContainer nodes;
-	CreateIdSortedList(bvh, nodes);
-	
+	CreateIdSortedList2(bvh->GetStaticRoot(), nodes);
+	//CreateIdSortedList(bvh, nodes);
+	ofstream outstream("test.log");
+
+	for (size_t i = 0; i < nodes.size(); ++ i)
+		outstream << "id " << nodes[i]->GetId() << endl;
+
+	outstream.close();
+	
+
 	for (int i = 0; i < number; ++ i) 
 	{
@@ -194,9 +220,5 @@
 			AxisAlignedBox3 newBox1 = box;
 			AxisAlignedBox3 newBox2 = box;
-			/*if (node->mPosition < newBox.Min(node->mAxis))
-				cout << "e: " << node->mPosition << " " << newBox.Min(node->mAxis) << endl;
-			else if (node->mPosition > newBox.Min(node->mAxis))
-				cout << "o: " << node->mPosition << " " << newBox.Min(node->mAxis) << endl;
-*/
+		
 			newBox1.SetMin(node->mAxis, node->mPosition);
 			newBox2.SetMax(node->mAxis, node->mPosition);
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SkyPreetham.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SkyPreetham.cpp	(revision 3276)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SkyPreetham.cpp	(revision 3279)
@@ -97,5 +97,6 @@
 								Camera *camera, 
 								RenderState *state, 
-								bool scaleToRange)
+								bool scaleToRange,
+								float skyDomeScaleFactor)
 {
 	pair<float, float> sun_theta;
@@ -109,11 +110,8 @@
 
 	// scale the sky dome so no intersection with the scene is visible
-	//const float scaleFactor = 80.0f;
-	const float scaleFactor = 1000.0f;
-
-	position.z -= 3.0f * scaleFactor;
+	position.z -= 3.0f * skyDomeScaleFactor;
 	Matrix4x4 m = TranslationMatrix(position);
 
-	Matrix4x4 s = ScaleMatrix(scaleFactor, scaleFactor, scaleFactor);
+	Matrix4x4 s = ScaleMatrix(skyDomeScaleFactor);
 	mSkyDome->GetTransform()->SetMatrix(s * m);
 	
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SkyPreetham.h
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SkyPreetham.h	(revision 3085)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SkyPreetham.h	(revision 3279)
@@ -26,5 +26,6 @@
 		               CHCDemoEngine::Camera *camera, 
 					   CHCDemoEngine::RenderState *state, 
-					   bool scaleToRange);
+					   bool scaleToRange,
+					   float skyDomeScaleFactor);
 
 	void ComputeFactors(const CHCDemoEngine::Vector3 &sunDir, 
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp	(revision 3277)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp	(revision 3279)
@@ -106,4 +106,6 @@
 const float fov = 50.0f;
 
+float skyDomeScaleFactor = 80.0f;
+
 SceneQuery *sceneQuery = NULL;
 RenderQueue *renderQueue = NULL;
@@ -377,5 +379,5 @@
 void RenderViewCell();
 
-void LoadPompeiiScene();
+void LoadPompeiiFloor();
 
 
@@ -471,5 +473,6 @@
 		env.GetBoolParam(string("useSkylightForIllum"), useSkylightForIllum);
 		env.GetFloatParam(string("viewCellsScaleFactor"), viewCellsScaleFactor);
-
+		env.GetFloatParam(string("skyDomeScaleFactor"), skyDomeScaleFactor);
+		
 		//env.GetStringParam(string("modelPath"), model_path);
 		//env.GetIntParam(string("numSssaoSamples"), numSsaoSamples);
@@ -509,4 +512,5 @@
 		cout << "view cells scale factor: " << viewCellsScaleFactor << endl;
 		cout << "use skylight for illumination: " << useSkylightForIllum << endl;
+		cout << "sky dome scale factor: " << skyDomeScaleFactor << endl;
 
 		//cout << "model path: " << model_path << endl;
@@ -599,5 +603,5 @@
 	//LoadModel("sibenik.dem", dynamicObjects);
 
-	if (0) LoadPompeiiScene();
+	if (1) LoadPompeiiFloor();
 
 #if 0
@@ -2259,5 +2263,5 @@
 
 		if (!statsWriter)
-			statsWriter = new StatsWriter(statsFilename);
+			statsWriter = new StatsWriter(statsFilename + ".log");
 			
 		FrameStats frameStats;
@@ -2406,5 +2410,5 @@
 		 (renderMethod == RENDER_DEFERRED)) && useHDR;
 	
-	preetham->RenderSkyDome(-light->GetDirection(), camera, &renderState, !useToneMapping);
+	preetham->RenderSkyDome(-light->GetDirection(), camera, &renderState, !useToneMapping, skyDomeScaleFactor);
 
 	/// once again reset the renderState just to make sure
@@ -2695,5 +2699,5 @@
 
 
-void LoadPompeiiScene()
+void LoadPompeiiFloor()
 {
 	AxisAlignedBox3 pompeiiBox = SceneEntity::ComputeBoundingBox(staticObjects);
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Matrix4x4.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Matrix4x4.cpp	(revision 3103)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Matrix4x4.cpp	(revision 3279)
@@ -401,4 +401,16 @@
 
 
+// uniform scale
+Matrix4x4 ScaleMatrix(float x)
+{
+	Matrix4x4 M = IdentityMatrix();
+
+	M.x[0][0] = x;
+	M.x[1][1] = x;
+	M.x[2][2] = x;
+
+	return M;
+}
+
 // Construct a rotation matrix that makes the x, y, z axes
 // correspond to the vectors given.
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/BvhExporter.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/BvhExporter.cpp	(revision 3274)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/BvhExporter.cpp	(revision 3279)
@@ -21,4 +21,5 @@
 	
 	int buffer[4];
+	buffer[3] = currentIdx ++;
 
 	if (node->IsVirtualLeaf()) 
@@ -29,6 +30,5 @@
 		buffer[1] = mTriangleRangeMap[leaf].second;
 		buffer[2] = -1;//leaf->GetAxis();
-		buffer[3] = currentIdx ++;
-
+		
 		fwrite(buffer, sizeof(int), 4, fw);
 	}
@@ -40,5 +40,4 @@
 		buffer[1] = interior->mLast;
 		buffer[2] = 0;//interior->mAxis;
-		buffer[3] = currentIdx ++;
 
 		fwrite(buffer, sizeof(int), 4, fw);
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/default.env
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/default.env	(revision 3277)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/default.env	(revision 3279)
@@ -9,9 +9,9 @@
 #filename=vienna_full_hp
 #bvhname=vienna_full_hp
-filename=tryvienna
-bvhname=tryvienna
-filename=mypompeii
-bvhname=mypompeii
-#filename=pompeii/pompeii_full
+#filename=tryvienna
+#bvhname=tryvienna
+#filename=mypompeii
+#bvhname=mypompeii
+filename=pompeii/pompeii_full
 #filename=pompeii/pompeii_part
 #filename=city
@@ -23,5 +23,5 @@
 recordedFramesSuffix=image
 # the filename for the statistics
-statsFilename=mystats.log
+statsFilename=mystats
 walkThroughSuffix=walkthrough_pp_1
 #walkThroughSuffix=path_pp
@@ -32,8 +32,12 @@
 # if using pvs, this specifies the name of the visibility solutin
 #visibilitySolution=vienna_full-8x3-pgv
-visibilitySolution=mypompeii-1x1-pgv
+#visibilitySolution=mypompeii-1x1-pgv
+visibilitySolution=mypompeii-2x1-obvh-pgv
+#visibilitySolution=myvienna-3x1-obvh-pgv
 
 viewCellsScaleFactor=1.0f
 useSkylightForIllum=1
+
+skyDomeScaleFactor=80.0f
 
 
@@ -62,5 +66,5 @@
 camPosition=483.398f 242.364f 186.078f
 # pompeii view point
-camPosition=1300.0f -2500.0f 10.0f
+#camPosition=1300.0f -2500.0f 10.0f
 # pompeii problematic
 #camPosition=627.003 -1725.33 25.2
@@ -108,4 +112,5 @@
 # skylight turbitity
 turbitity=3.0f
+#sky dome scale factor
 
 
@@ -143,2 +148,3 @@
 #camDirection=-0.0975121 0.994494 0.0383878
 #useSkylightForIllum=1
+#skyDomeScaleFactor=1000.0f
