Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaderenv.h
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaderenv.h	(revision 3309)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaderenv.h	(revision 3311)
@@ -5,5 +5,5 @@
 ////////////
 //-- ssao + gi parameters
-#define NUM_PRECOMPUTED_SAMPLES 200
+#define NUM_PRECOMPUTED_SAMPLES 1024
 //#define NUM_SAMPLES 8
 //#define NUM_SAMPLES 16
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg	(revision 3310)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg	(revision 3311)
@@ -224,5 +224,5 @@
 			sampler2D colors,
 			sampler2D noiseTex,
-			float2 samples[NUM_PRECOMPUTED_SAMPLES],
+			sampler2D samples,
 			float3 normal,
 			float3 centerPosition,
@@ -236,5 +236,5 @@
 			float sampleIntensity,
 			bool isMovingObject,
-			int idx
+			float idx
 			)
 {
@@ -251,15 +251,18 @@
 		//-- (affects performance for some reason!)
 
-		if (1)//convergence < SSAO_CONVERGENCE_THRESHOLD)
+		const float2 ssaoOffset = tex2Dlod(samples, float4((0.5f + i + idx) / NUM_PRECOMPUTED_SAMPLES, 0.5f, .0f, .0f)).xy;
+
+		if (convergence < SSAO_CONVERGENCE_THRESHOLD)
 		{
-			float2 mynoise = tex2Dlod(noiseTex, float4(IN.texCoord * 4.0f, 0, 0)).xy;
+			float2 mynoise = tex2Dlod(noiseTex, float4(IN.texCoord.x * 4.0f + idx * 0.01f, IN.texCoord.y * 4.0f, 0, 0)).xy;
 			//offset = myreflect(samples[i], mynoise);
-			offset = myrotate(samples[i], mynoise.x);
-			//offset = myrotate(samples[i + idx], mynoise.x);
+			//offset = myrotate(samples[i], mynoise.x);
+
+			offset = myrotate(ssaoOffset, mynoise.x);
 		}
 		else
 		{
-			//offset = samples[i + idx];
-			offset = samples[i];
+			offset = ssaoOffset;
+			//offset = samples[i];
 		}
 		
@@ -312,6 +315,6 @@
 			// if the pixel belongs to a static object and all the samples stay valid in the current frame
 			if (!isMovingObject && (validSamples < 1.0f)) break;
-			// if the pixel belongs to a dynamic object but the #accumulated samples for this pixel is sufficiently high 
-			// (=> there was no discontinuity recently)
+			// if the pixel belongs to a dynamic object but the #accumulated samples
+			// for this pixel is sufficiently high (=> there was no discontinuity recently)
 			else if (isMovingObject && (convergence > NUM_SAMPLES * 5)) break;
 		}
@@ -341,5 +344,5 @@
 		   uniform sampler2D normals,
 		   uniform sampler2D noiseTex,
-		   uniform float2 samples[NUM_PRECOMPUTED_SAMPLES],
+		   uniform sampler2D samples,
 		   uniform sampler2D oldTex,
 		   uniform float4x4 modelViewProj,
@@ -400,6 +403,7 @@
 	float oldWeight = temporalVals.y;
 
-	int idx = (int)temporalVals.z;
-		//min(0, (int)oldWeight % max((int)temporalCoherence, 1));
+	float idx = (int)temporalVals.z;
+
+	if (idx >= NUM_PRECOMPUTED_SAMPLES) idx = 0;
 
 	float3 ao;
@@ -425,4 +429,6 @@
 	// the weight equals the number of sampled shot in this pass
 	const float newWeight = ao.z;
+
+	idx += newWeight;
 
 	// completely reset the ao in this pixel
@@ -442,9 +448,6 @@
 		{
 			oldWeight = min(oldWeight, 4.0f * newWeight);
-			idx = oldWeight;
 		}
 	}
-
-	float usedWeight = min(temporalCoherence, oldWeight);
 
 
@@ -452,18 +455,14 @@
 	//-- blend ao between old and new samples (and avoid division by zero)
 
-	OUT.illum_col.x = ao.x * newWeight;// + oldSsao * usedWeight;
-	OUT.illum_col.x /= max(newWeight + usedWeight, 1);
-
-	//if (oldWeight >= 10000) oldWeight = 1000;
+	OUT.illum_col.x = ao.x * newWeight + oldSsao * oldWeight;
+	OUT.illum_col.x /= (newWeight + oldWeight);
 
 	// the new weight for the next frame
-	//const float combinedWeight = clamp(newWeight + oldWeight, .0f, temporalCoherence);
-	float combinedWeight = newWeight + oldWeight;
-
-	clamp(combinedWeight, 0, 1000);
-
+	const float combinedWeight = clamp(newWeight + oldWeight, .0f, temporalCoherence);
+	
 	OUT.illum_col.y = combinedWeight;
 	// can be used to check if this pixel belongs to a moving object
-	OUT.illum_col.z = SqrLen(diffVec);
+	//OUT.illum_col.z = SqrLen(diffVec);
+	OUT.illum_col.z = idx;
 	OUT.illum_col.w = eyeSpaceDepth;
 
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/combineSsaoSep.cg
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/combineSsaoSep.cg	(revision 3310)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/combineSsaoSep.cg	(revision 3311)
@@ -145,5 +145,5 @@
 	{
 		// the filtered ssao value
-		//OUT.illum_col.x = FilterXY(IN.texCoord, ssaoTex, colorsTex, bl, br, tl, tr, xyStep, convergence);
+		OUT.illum_col.x = FilterXY(IN.texCoord, ssaoTex, colorsTex, bl, br, tl, tr, xyStep, convergence);
 	}
 
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg	(revision 3309)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg	(revision 3311)
@@ -263,6 +263,6 @@
 
 	// check if the pixel belonged to a dyanmic object in the last frame
-	const bool oldDynamic = (squaredLen > DYNAMIC_OBJECTS_THRESHOLD);
-	const bool newDynamic = (oldPixel.z > DYNAMIC_OBJECTS_THRESHOLD);
+	const bool newDynamic = false;//(squaredLen > DYNAMIC_OBJECTS_THRESHOLD);
+	const bool oldDynamic = false;//(oldPixel.z > DYNAMIC_OBJECTS_THRESHOLD);
 
 	// actually 0 means pixel is valid
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SampleGenerator.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SampleGenerator.cpp	(revision 3247)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SampleGenerator.cpp	(revision 3311)
@@ -51,5 +51,5 @@
 	int tries = 0;
 
-	//cout << "minDist before= " << minDist << endl;
+	cout << "minDist before= " << minDist << endl;
 	Sample2 *s = (Sample2 *)samples;
 
@@ -109,5 +109,5 @@
 	}
 
-	//cout << "minDist after= " << (float)minDist / mNumSamples<< " #tries: " << tries << endl;
+	cout << "minDist after= " << (float)minDist / mNumSamples<< " #tries: " << tries << endl;
 }
 
@@ -172,6 +172,6 @@
 
 QuadraticDiscSampleGenerator2D::QuadraticDiscSampleGenerator2D(int numSamples, float radius):
-//PoissonDiscSampleGenerator2D(numSamples, radius)
-RandomSampleGenerator2D(numSamples, radius)
+PoissonDiscSampleGenerator2D(numSamples, radius)
+//RandomSampleGenerator2D(numSamples, radius)
 {}
 
@@ -194,6 +194,6 @@
 #else
 
-	//PoissonDiscSampleGenerator2D::Generate(samples);
-	RandomSampleGenerator2D::Generate(samples);
+	PoissonDiscSampleGenerator2D::Generate(samples);
+	//RandomSampleGenerator2D::Generate(samples);
 
 	Sample2 *s = (Sample2 *)samples;
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SampleGenerator.h
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SampleGenerator.h	(revision 3247)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SampleGenerator.h	(revision 3311)
@@ -78,6 +78,6 @@
 	with the distance
 */
-//class QuadraticDiscSampleGenerator2D: public PoissonDiscSampleGenerator2D
-class QuadraticDiscSampleGenerator2D: public RandomSampleGenerator2D
+class QuadraticDiscSampleGenerator2D: public PoissonDiscSampleGenerator2D
+//class QuadraticDiscSampleGenerator2D: public RandomSampleGenerator2D
 {
 public:
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp	(revision 3306)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp	(revision 3311)
@@ -1211,10 +1211,6 @@
 	if ((!shadowMap || !shadowTraverser) && (showShadowMap || renderLightView))
 	{
-		if (!shadowMap)
-			shadowMap = new ShadowMap(light, shadowSize, bvh->GetBox(), camera);
-
-		if (!shadowTraverser)
-			shadowTraverser = CreateTraverser(shadowMap->GetShadowCamera());
-
+		if (!shadowMap)	shadowMap = new ShadowMap(light, shadowSize, bvh->GetBox(), camera);
+		if (!shadowTraverser) shadowTraverser = CreateTraverser(shadowMap->GetShadowCamera());
 	}
 	
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.cpp	(revision 3310)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.cpp	(revision 3311)
@@ -71,5 +71,5 @@
 static GLuint noiseTex2D = 0;
 static GLuint noiseTex1D = 0;
-
+static GLuint sampleTex2D = 0;
 
 
@@ -92,5 +92,9 @@
 /** Helper method that computes the view vectors in the corners of the current view frustum.
 */
-static void ComputeViewVectors(PerspectiveCamera *cam, Vector3 &bl, Vector3 &br, Vector3 &tl, Vector3 &tr)
+static void ComputeViewVectors(PerspectiveCamera *cam, 
+							   Vector3 &bl,
+							   Vector3 &br, 
+							   Vector3 &tl,
+							   Vector3 &tr)
 {
 	Vector3 ftl, ftr, fbl, fbr, ntl, ntr, nbl, nbr;
@@ -258,4 +262,41 @@
 
 	cout << "created noise texture" << endl;
+
+	PrintGLerror("noisetexture");
+}
+
+
+static void CreateSampleTex(Sample2 *samples, int numSamples)
+{
+	glEnable(GL_TEXTURE_2D);
+	glGenTextures(1, &sampleTex2D);
+	glBindTexture(GL_TEXTURE_2D, sampleTex2D);
+		
+	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
+	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
+	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
+	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
+
+	int w = numSamples;
+	int h = 1;
+
+	float *tempBuffer = new float[numSamples * 3];
+
+	for (int i = 0; i < numSamples; ++ i)
+	{
+		tempBuffer[i * 3 + 0] = samples[i].x;
+		tempBuffer[i * 3 + 1] = samples[i].y;
+		tempBuffer[i * 3 + 2] = 0;
+		
+	}
+
+	glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F_ARB, w, h, 0, GL_RGB, GL_FLOAT, (float *)tempBuffer);
+
+	glBindTexture(GL_TEXTURE_2D, 0);
+	glDisable(GL_TEXTURE_2D);
+
+	cout << "created sample texture" << endl;
+
+	delete [] tempBuffer;
 
 	PrintGLerror("noisetexture");
@@ -428,8 +469,9 @@
 
 	string ssaoParams[] = 
-		{"colors", "normals", "oldTex", "noiseTex", "temporalCoherence", 
+	    {"colors", "normals", "oldTex", "noiseTex", "temporalCoherence", 
 		 "samples", "bl", "br", "tl", "tr", 
 		 "modelViewProj", "oldModelViewProj", "oldEyePos", "oldbl", "oldbr", 
 		 "oldtl", "oldtr", "attribsTex", "kernelRadius", "sampleIntensity"};
+	
 	sCgSsaoProgram->AddParameters(ssaoParams, 0, 20);
 	
@@ -751,8 +793,9 @@
 		// needs longer to converge
 		GenerateSamples(mSamplingMethod);
-
+		CreateSampleTex(samples2, NUM_PRECOMPUTED_SAMPLES);
 		//if (mSortSamples) { SortSamples(); }
 		//sCgSsaoProgram->SetArray2f(i, (float *)samples2, NUM_SAMPLES);
-		sCgSsaoProgram->SetArray2f(i, (float *)samples2, NUM_PRECOMPUTED_SAMPLES);
+		//sCgSsaoProgram->SetArray2f(i, (float *)samples2, NUM_PRECOMPUTED_SAMPLES);
+		sCgSsaoProgram->SetTexture(i, sampleTex2D);
 	}
 	
@@ -772,4 +815,5 @@
 	de.y = mOldEyePos.y - mEyePos.y; 
 	de.z = mOldEyePos.z - mEyePos.z;
+
 
 	sCgSsaoProgram->SetValue3f(i ++, de.x, de.y, de.z);
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/sibenik.env
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/sibenik.env	(revision 3310)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/sibenik.env	(revision 3311)
@@ -106,5 +106,5 @@
 ssaoSampleIntensity=0.8f
 # ssao temporal coherence factor
-tempCohFactor=100.0f
+tempCohFactor=1024.0f
 # ssao filter radius
 ssaoFilterRadius=12.0f
