Index: /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaderenv.h
===================================================================
--- /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaderenv.h	(revision 3371)
+++ /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaderenv.h	(revision 3372)
@@ -8,12 +8,12 @@
 //#define NUM_PRECOMPUTED_SAMPLES 8124
 #define NUM_PRECOMPUTED_SAMPLES 4096
-//#define NUM_PRECOMPUTED_SAMPLES 1024
+//#define NUM_PRECOMPUTED_SAMPLES 16
 
-//#define NUM_SAMPLES 16
-#define NUM_SAMPLES 16
+#define NUM_SAMPLES 32
+//#define NUM_SAMPLES 24
 //#define NUM_SAMPLES 32
 //#define NUM_SAMPLES 64
 
-#define MIN_SAMPLES 16
+#define MIN_SAMPLES 8
 //#define MIN_SAMPLES 48
 
@@ -26,6 +26,6 @@
 
 //#define SSAO_CONVERGENCE_THRESHOLD 300.0f
-#define SSAO_CONVERGENCE_THRESHOLD 700.0f
-//#define SSAO_CONVERGENCE_THRESHOLD 1300.0f
+//#define SSAO_CONVERGENCE_THRESHOLD 700.0f
+#define SSAO_CONVERGENCE_THRESHOLD 1300.0f
 //#define SSAO_CONVERGENCE_THRESHOLD 1500.0f
 
@@ -66,5 +66,5 @@
 #define NUM_DOF_TABS 16
 
-//#define USE_GTX
+#define USE_GTX
 
 #define SSAO_FILTER_RADIUS 5
@@ -74,5 +74,5 @@
 #define PERFORMANCE_TEST 1
 
-#define USE_OPTIMIZATION 0
+#define USE_OPTIMIZATION 1
 
 
Index: /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg
===================================================================
--- /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg	(revision 3371)
+++ /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg	(revision 3372)
@@ -53,19 +53,6 @@
 
 	// get position exactly between texel centers
-	float2 center = (floor(texCoord * res) + float2(.5f)) * texCoord;
-	//center.x = (floor(texCoord.x * res.x - .5f) + 1.0f) / res.x;
-	//center.y = (floor(texCoord.y * res.y - .5f) + 1.0f) / res.y;
-	//center.y = (floor(texCoord.y * res.y) + .5f) * yOffs;
-
-	/*texelCenterConv.x = tex2Dlod(tex, float4(center + float2( xoffs,  yoffs), 0, 0)).y;
-	texelCenterConv.y = tex2Dlod(tex, float4(center + float2( xoffs, -yoffs), 0, 0)).y;
-	texelCenterConv.z = tex2Dlod(tex, float4(center + float2(-xoffs, -yoffs), 0, 0)).y;
-	texelCenterConv.w = tex2Dlod(tex, float4(center + float2(-xoffs,  yoffs), 0, 0)).y;
-
-	const float m1 = min(texelCenterConv.x, texelCenterConv.y);
-	const float m2 = min(texelCenterConv.z, texelCenterConv.w);
-
-	const float convergence = min(m1, m2);*/
-
+	float2 center = (floor(texCoord * res) + float2(.5f)) * invRes;
+	
 	//const float convergence = tex2Dlod(tex, float4(center, 0, 0)).y;
 	const float convergence = tex2Dlod(tex, float4(texCoord, 0, 0)).y;
@@ -133,21 +120,23 @@
 
 	if (1
-		&& (oldTexCoords.x > 0) && (oldTexCoords.x < 1.0f)
-		&& (oldTexCoords.y > 0) && (oldTexCoords.y < 1.0f)
+		&& (oldTexCoords.x > .0f) && (oldTexCoords.x < 1.0f)
+		&& (oldTexCoords.y > .0f) && (oldTexCoords.y < 1.0f)
 		&& (depthDif <= MIN_DEPTH_DIFF) 
 		)
 	{
-		// pixel valid => retrieve the convergence weight
-		/*float w1 = tex2Dlod(oldTex, float4(oldTexCoords + float2(0.5f / 1024.0f, 0), .0f, .0f)).y;
-		float w2 = tex2Dlod(oldTex, float4(oldTexCoords - float2(0.5f / 1024.0f, 0), .0f, .0f)).y;
-		float w3 = tex2Dlod(oldTex, float4(oldTexCoords + float2(0, 0.5f / 768.0f), .0f, .0f)).y;
-		float w4 = tex2Dlod(oldTex, float4(oldTexCoords - float2(0, 0.5f / 768.0f), .0f, .0f)).y;
-
-		w = min(min(w1, w2), min(w3, w4));*/
+#if 0
+		idx = floor(oldPixel.z);
+#else
+
+		// nearest neighbour
+		float2 center;
+		center.x = (floor(oldTexCoords.x * 1024) + .5f) / 1024;
+		center.y = (floor(oldTexCoords.y * 768) + .5f) / 768;
 		
-		//w = ComputeConvergence(oldTex, oldTexCoords, float2(1024.0f, 768.0f));
-		w   = oldPixel.y;
-		idx = floor(oldPixel.z);
-		//idx = oldPixel.z;
+		const float4 oldPixelExact = tex2Dlod(oldTex, float4(center, .0f, .0f)); 
+		idx = oldPixelExact.z;
+#endif
+
+		w = oldPixel.y;
 	}
 	else
@@ -487,5 +476,5 @@
 		float2 offset;
 
-		const float2 ssaoOffset = tex2Dlod(samples, float4((0.5f + i + oldIdx) / NUM_PRECOMPUTED_SAMPLES, .5f, .0f, .0f)).xy;
+		const float2 ssaoOffset = tex2Dlod(samples, float4((.5f + i + floor(oldIdx)) / NUM_PRECOMPUTED_SAMPLES, .5f, .0f, .0f)).xy;
 		//const float2 ssaoOffset = dummySamples[i];
 
@@ -494,6 +483,6 @@
 		//-- (affects performance for some reason!)
 
-		if (1)//!USE_OPTIMIZATION ||
-			//(convergence < SSAO_CONVERGENCE_THRESHOLD))
+		if (!USE_OPTIMIZATION ||
+			(convergence < SSAO_CONVERGENCE_THRESHOLD))
 		{
 			float2 mynoise = tex2Dlod(noiseTex, float4(IN.texCoord * 4.0f, 0, 0)).xy;
@@ -521,5 +510,4 @@
 		float3 dirSample = samplePos - centerPosition;
 
-		const float minDist = 1e-6f;
 		const float eps = 1e-3f;
 
@@ -527,5 +515,5 @@
 		const float sampleWeight = 1.0f / max(lengthToSample, eps);
 
-		dirSample /= max(length(dirSample), minDist); // normalize
+		dirSample /= max(length(dirSample), eps); // normalize
 
 		// angle between current normal and direction to sample controls AO intensity.
@@ -540,6 +528,5 @@
 
 
-//#ifdef PERFORMANCE_TEST
-#if 1
+#ifdef PERFORMANCE_TEST
 		// check if the samples have been valid in the last frame
 		// only mark sample as invalid if in the last / current frame
@@ -552,10 +539,16 @@
 		const float distanceDiff = abs(oldDistance - lengthToSample);
 
-		float pixelValid = (oldSamplePos.x > 1e14f) ? 100.0f : .0f;
-
-		if ((cosAngle >= 0) && (pixelValid < 90.0f))// || (cosAngle2 >= 0))
-		{
-			pixelValid = (distanceDiff > 1e-3f) ? 100.0f : .0f;
-			//pixelValid = (distanceDiff > 1e-3f) ? 5.0f : .0f;
+		float pixelValid = .0f;
+
+		if ((texcoord.x > .0f) && (texcoord.x < 1.0f) && (texcoord.y > .0f) && (texcoord.y < 1.0f))
+		{
+			if ((oldSamplePos.x > 1e14f))// || ((cosAngle >= 0) && (distanceDiff > 1e-3f)))
+			{
+				pixelValid = 100.0f;
+			}
+			else if ((cosAngle >= 0) && (distanceDiff > 1e-3f))
+			{
+				pixelValid = 5.0f;
+			}
 		}
 
@@ -742,4 +735,5 @@
 
 		oldWeight = min(oldWeight, factor * NUM_SAMPLES);
+
 		if (newIdx >= factor * NUM_SAMPLES) 
 		{
Index: /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/combineSsaoSep.cg
===================================================================
--- /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/combineSsaoSep.cg	(revision 3369)
+++ /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/combineSsaoSep.cg	(revision 3372)
@@ -3,7 +3,7 @@
 
 
-/*************************************************/
-/*     Filter for combining ssao with image      */
-/*************************************************/
+/********************************************************/
+/*         Filter for combining ssao with image         */
+/********************************************************/
 
 
Index: /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg
===================================================================
--- /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg	(revision 3369)
+++ /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg	(revision 3372)
@@ -315,4 +315,5 @@
 	float3 translatedPos = -oldEyePos + worldPos.xyz + difVec;
 	
+
 	/////////////////
 	//-- reproject into old frame and calculate texture position of sample in old frame
@@ -381,5 +382,6 @@
 	pix.color.z = color.w;
 */
-	const float3 translatedPos = ComputeTranslatedPos(color, difVec.xyz, IN.view, oldEyePos, oldModelViewProj);
+	const float3 translatedPos = 
+		ComputeTranslatedPos(color, difVec.xyz, IN.view, oldEyePos, oldModelViewProj);
 
 	pix.color.xyz = translatedPos;
Index: /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ResourceManager.cpp
===================================================================
--- /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ResourceManager.cpp	(revision 3371)
+++ /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ResourceManager.cpp	(revision 3372)
@@ -356,10 +356,7 @@
     str.read(reinterpret_cast<char *>(vertices), sizeof(Vector3) * vertexCount);
 	
-	//cout << "vertexCount: " << vertexCount << endl;
-
 	normals = new Vector3[vertexCount];
 	str.read(reinterpret_cast<char *>(normals), sizeof(Vector3) * vertexCount);
 
-
 	Vector3 *tangents;
 
@@ -377,5 +374,4 @@
 	str.read(reinterpret_cast<char *>(&texCoordCount), sizeof(int));
 
-	//cout << "texCoordCount: " << texCoordCount << endl;
 
 	if (texCoordCount)
Index: /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Halton.cpp
===================================================================
--- /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Halton.cpp	(revision 3322)
+++ /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Halton.cpp	(revision 3372)
@@ -79,5 +79,5 @@
 	}
 
-	// only even prime number
+	// only even prime numbers
 	if (idx == 1) return 2;
 
Index: /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SampleGenerator.cpp
===================================================================
--- /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SampleGenerator.cpp	(revision 3371)
+++ /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SampleGenerator.cpp	(revision 3372)
@@ -248,11 +248,11 @@
 	for (int i = 0; i < mNumSamples; ++ i)
 	{
-		x[0] = RandomValue(0, 1); x[1] = RandomValue(0, 1);
-		//mHalton->GetNext(x);
+		//x[0] = RandomValue(0, 1); x[1] = RandomValue(0, 1);
+		mHalton->GetNext(x);
 		
 		const float a = 2.0f * M_PI * x[0];
 		const float r = sqrt(x[1]);
-		//const float rad = mRadius * r * r * r * r;
-		const float rad = mRadius * r;// * r;
+		
+		const float rad = mRadius * r;
 
 		s[i].x = rad * cos(a);
Index: /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp
===================================================================
--- /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp	(revision 3371)
+++ /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp	(revision 3372)
@@ -645,5 +645,6 @@
 	VertexArray positions;
 	//const float factor2 = 1.6f;
-	const float factor2 = 1.5f;
+	const float factor2 = .0f;
+	//const float factor2 = 1.5f;
 
 	// for buddha (lowres)
@@ -835,5 +836,4 @@
 	// another color buffer
 	fbo->AddColorBuffer(ColorBufferObject::RGBA_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_LINEAR, ColorBufferObject::FILTER_NEAREST);
-
 
 	for (int i = 0; i < 4; ++ i)
Index: /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.cpp
===================================================================
--- /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.cpp	(revision 3371)
+++ /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.cpp	(revision 3372)
@@ -226,6 +226,4 @@
 	case DeferredRenderer::SAMPLING_QUADRATIC:
 		{
-			//PoissonDiscSampleGenerator2D poisson(NUM_PRECOMPUTED_SAMPLES, 1.0f);
-			//poisson.Generate((float *)samples2);
 			QuadraticDiscSampleGenerator2D g(NUM_PRECOMPUTED_SAMPLES, 1.0f);
 			g.Generate((float *)samples2);
@@ -845,6 +843,5 @@
 
 	//if (mRegenerateSamples)
-	if (//mUseTemporalCoherence || 
-		mRegenerateSamples)
+	if (1)//mUseTemporalCoherence || mRegenerateSamples)
 	{
 		mRegenerateSamples = false;
@@ -861,5 +858,5 @@
 		else
 		{
-			UpdateSampleTex(samples2, NUM_PRECOMPUTED_SAMPLES);
+			//UpdateSampleTex(samples2, NUM_PRECOMPUTED_SAMPLES);
 		}
 
Index: /GTP/trunk/App/Demos/Vis/FriendlyCulling/Converter/ObjConverter.cpp
===================================================================
--- /GTP/trunk/App/Demos/Vis/FriendlyCulling/Converter/ObjConverter.cpp	(revision 3371)
+++ /GTP/trunk/App/Demos/Vis/FriendlyCulling/Converter/ObjConverter.cpp	(revision 3372)
@@ -168,6 +168,4 @@
 	geom->mMaterial = mat;
 
-	static int count = 0;
-	if (count ++ < 10)
 	cout << "creating new geometry with " << numElements << " vertices" << endl;
 
@@ -206,6 +204,5 @@
 
 
-bool ObjConverter::Convert(const string &filename, 
-						   const std::string &outputFilename)
+bool ObjConverter::Convert(const string &filename, const std::string &outputFilename)
 {
 	mNumShapes = 0;
@@ -361,4 +358,45 @@
 		str.write(reinterpret_cast<char *>(geom->mTexcoords), sizeof(float) * texCoordCount * 2);
 	
+
+	///////
+	//-- texture
+/*
+#ifdef USE_TEXTURE
+	int texId = 0;
+#else
+	int texId = -1;
+#endif
+
+	str.write(reinterpret_cast<char *>(&texId), sizeof(int));
+
+	bool alphaTestEnabled = false;
+	//bool cullFaceEnabled = false;
+	bool cullFaceEnabled = true;
+
+	str.write(reinterpret_cast<char *>(&alphaTestEnabled), sizeof(bool));
+	str.write(reinterpret_cast<char *>(&cullFaceEnabled), sizeof(bool));
+
+	// material
+	bool hasMaterial = true;
+	//bool hasMaterial = false;
+	str.write(reinterpret_cast<char *>(&hasMaterial), sizeof(bool));
+	
+	if (hasMaterial)
+	{
+		SimpleVec ambient, diffuse, spec, emm;
+
+		ambient.x = ambient.y = ambient.z = 0.2f;
+		//diffuse.x = diffuse.y = diffuse.z = 1.0f;
+		diffuse.x = 0.7f; diffuse.y = 0.5f; diffuse.z = 0.2f;
+		spec.x    = spec.y    = spec.z    =  .0f;
+		emm = spec;
+
+		// only write rgb part of the material
+		str.write(reinterpret_cast<char *>(&ambient), sizeof(SimpleVec));
+		str.write(reinterpret_cast<char *>(&diffuse), sizeof(SimpleVec));
+		str.write(reinterpret_cast<char *>(&spec), sizeof(SimpleVec));
+		str.write(reinterpret_cast<char *>(&emm), sizeof(SimpleVec));
+	}
+*/
 }
 
@@ -369,5 +407,6 @@
 	ogzstream ofile(filename.c_str());
 
-	if (!ofile.is_open()) return false;
+	if (!ofile.is_open())
+		return false;
 	
 
@@ -409,35 +448,33 @@
 	{
 		WriteGeometry(ofile, *it);
-
-		int texId = 0;
-		ofile.write(reinterpret_cast<char *>(&texId), sizeof(int));
-
-		bool alphaTestEnabled = false;
-		//bool cullFaceEnabled = false;
-		bool cullFaceEnabled = true;
-
-		ofile.write(reinterpret_cast<char *>(&alphaTestEnabled), sizeof(bool));
-		ofile.write(reinterpret_cast<char *>(&cullFaceEnabled), sizeof(bool));
-
-		// material
-		bool hasMaterial = true;
-		ofile.write(reinterpret_cast<char *>(&hasMaterial), sizeof(bool));
-
-		if (hasMaterial)
-		{
-			SimpleVec ambient, diffuse, spec, emm;
-
-			ambient.x = ambient.y = ambient.z =  .2f;
-			diffuse.x = diffuse.y = diffuse.z = 1.0f;
-			spec.x    = spec.y    = spec.z    =  .0f;
-			emm = spec;
-
-			// only write rgb part of the material
-			ofile.write(reinterpret_cast<char *>(&ambient), sizeof(SimpleVec));
-			ofile.write(reinterpret_cast<char *>(&diffuse), sizeof(SimpleVec));
-			ofile.write(reinterpret_cast<char *>(&spec), sizeof(SimpleVec));
-			ofile.write(reinterpret_cast<char *>(&emm), sizeof(SimpleVec));
-		}
-	}
+	}
+
+	int texId = 0;
+	ofile.write(reinterpret_cast<char *>(&texId), sizeof(int));
+
+	bool alphaTestEnabled = false;
+	//bool cullFaceEnabled = false;
+	bool cullFaceEnabled = true;
+		
+	ofile.write(reinterpret_cast<char *>(&alphaTestEnabled), sizeof(bool));
+	ofile.write(reinterpret_cast<char *>(&cullFaceEnabled), sizeof(bool));
+
+	// material
+	bool hasMaterial = true;
+	ofile.write(reinterpret_cast<char *>(&hasMaterial), sizeof(bool));
+	
+	SimpleVec ambient, diffuse, spec, emm;
+
+	ambient.x = ambient.y = ambient.z = 0.2f;
+	diffuse.x = diffuse.y = diffuse.z = 1.0f;
+	spec.x = spec.y = spec.z = .0f;
+	emm = spec;
+
+	// only write rgb part of the material
+	ofile.write(reinterpret_cast<char *>(&ambient), sizeof(SimpleVec));
+	ofile.write(reinterpret_cast<char *>(&diffuse), sizeof(SimpleVec));
+	ofile.write(reinterpret_cast<char *>(&spec), sizeof(SimpleVec));
+	ofile.write(reinterpret_cast<char *>(&emm), sizeof(SimpleVec));
+
 
 	int entityCount = 1;
Index: /GTP/trunk/App/Demos/Vis/FriendlyCulling/Converter/ObjConverter2.cpp
===================================================================
--- /GTP/trunk/App/Demos/Vis/FriendlyCulling/Converter/ObjConverter2.cpp	(revision 3371)
+++ /GTP/trunk/App/Demos/Vis/FriendlyCulling/Converter/ObjConverter2.cpp	(revision 3372)
@@ -129,5 +129,8 @@
 				for (int j = 0; j < 3; ++ j)
 				{
+					//if (tIndices[idx[j]] >= (int)texcoords.size())
+						//cerr << "error: texcoord indices exceed array size " << texcoords.size() << " " << tIndices[idx[j]] << endl;
 					const int tidx = min((int)texcoords.size() - 1, tIndices[idx[j]]);
+
 					faceTexcoords.push_back(texcoords[tidx]);
 				}
Index: /GTP/trunk/App/Demos/Vis/FriendlyCulling/Converter/main.cpp
===================================================================
--- /GTP/trunk/App/Demos/Vis/FriendlyCulling/Converter/main.cpp	(revision 3371)
+++ /GTP/trunk/App/Demos/Vis/FriendlyCulling/Converter/main.cpp	(revision 3372)
@@ -1,4 +1,4 @@
-#include "ObjConverter.h"
-//#include "PlyConverter.h"
+//#include "ObjConverter.h"
+#include "PlyConverter.h"
 #include <iostream>
 #include <time.h>
@@ -12,6 +12,6 @@
 
 	//ObjConverter2 converter;
-	ObjConverter converter;
-	//PlyConverter converter;
+	//ObjConverter converter;
+	PlyConverter converter;
 
 	cout << "converting obj to dem format" << endl;
@@ -60,5 +60,5 @@
 
 	cout << "conversion successful" << endl;
-	//cout << "press any key" << std::cin.get();
+	cout << "press any key" << std::cin.get();
 
 	return 0;
Index: /GTP/trunk/App/Demos/Vis/FriendlyCulling/sibenik.env
===================================================================
--- /GTP/trunk/App/Demos/Vis/FriendlyCulling/sibenik.env	(revision 3362)
+++ /GTP/trunk/App/Demos/Vis/FriendlyCulling/sibenik.env	(revision 3372)
@@ -30,5 +30,5 @@
 visibilitySolutionInitialState=500000000
 # renderMode: Frustum Culling, Stop And Wait, CHC, CHC ++
-renderMode=3
+renderMode=0
 
 ############
@@ -71,6 +71,6 @@
 
 # the used render method (forward, forward + depth pass, deferred, deferred + depth pass
-#renderMethod=2
-renderMethod=0
+renderMethod=2
+#renderMethod=0
 
 #modelPath=data/city/model/
