Index: /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaderenv.h
===================================================================
--- /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaderenv.h	(revision 3328)
+++ /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaderenv.h	(revision 3329)
@@ -9,5 +9,5 @@
 //#define NUM_SAMPLES 16
 //#define NUM_SAMPLES 24
-#define NUM_SAMPLES 48
+#define NUM_SAMPLES 24
 
 //#define MIN_SAMPLES 48
Index: /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg
===================================================================
--- /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg	(revision 3328)
+++ /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg	(revision 3329)
@@ -203,6 +203,6 @@
 		float2 offset;
 
-		const float2 ssaoOffset = tex2Dlod(samples, float4((0.5f + i + idx) / NUM_PRECOMPUTED_SAMPLES, 0.5f, .0f, .0f)).xy;
-		//const float2 ssaoOffset = samples[i];
+		const float2 ssaoOffset = 
+			tex2Dlod(samples, float4((0.5f + i + idx) / NUM_PRECOMPUTED_SAMPLES, 0.5f, .0f, .0f)).xy;
 
 		////////////////////
@@ -234,26 +234,24 @@
 		float3 dirSample = samplePos - centerPosition;
 
-		//const float minDist = 9e-1f;
-		const float minDist = 1e-2f;
-
-		//const float sqrLen = max(SqrLen(dirSample), minDist);
-		//const float lengthToSample = sqrt(sqrLen);
-		const float lengthToSample =  max(length(dirSample), minDist);
-
-		dirSample /= lengthToSample; // normalize
+		const float minDist = 1e-6f;
+		const float scaleFactor = 1e-3f;
+
+		const float lengthToSample = length(dirSample);
+		const float sampleWeight = 1.0f / (lengthToSample + scaleFactor);
+
+		dirSample /= max(lengthToSample, minDist); // normalize
+
 
 		// angle between current normal and direction to sample controls AO intensity.
-		float cosAngle = dot(dirSample, normal);
+		const float cosAngle = dot(dirSample, normal);
 
 		// the normal of the current sample
-		//const float3 sampleNormal = normalize(tex2Dlod(normalTex, float4(texcoord, 0, 0)).xyz);
-		const float3 sampleNormal = tex2Dlod(normalTex, float4(texcoord, 0, 0)).xyz;
-
+		const float3 sampleNormal = normalize(tex2Dlod(normalTex, float4(texcoord, 0, 0)).xyz);
+		
 		// angle between current normal and direction to sample controls AO intensity.
-		float cosAngle2 = .5f + dot(sampleNormal, -normal) * 0.5f;
-		//float cosAngle2 = dot(-dirSample, sampleNormal);
+		const float cosAngle2 = dot(-dirSample, sampleNormal);
 		
-		//const float aoContrib = sampleIntensity / sqrLen;
-		const float aoContrib = sampleIntensity / lengthToSample;
+		dirSample *= minDist;
+		const float aoContrib = sampleIntensity * sampleWeight;
 
 		//const float aoContrib = (1.0f > lengthToSample) ? occlusionPower(9e-2f, DISTANCE_SCALE + lengthToSample): .0f;
@@ -277,4 +275,5 @@
 
 		const float partlyResetThres = 1.0f;
+
 		if (pixelValid <= partlyResetThres)
 			validSamples = max(validSamples, pixelValid * (1.0f - tooFarAway) * step(-0.1f, cosAngle));
@@ -326,5 +325,5 @@
 			sampler2D colors,
 			sampler2D noiseTex,
-			float2 samples[NUM_SAMPLES],
+			sampler2D samples,
 			float3 normal,
 			float3 centerPosition,
@@ -337,5 +336,6 @@
 			float convergence,
 			float sampleIntensity,
-			bool isMovingObject
+			bool isMovingObject,
+			float oldIdx
 			)
 {
@@ -348,4 +348,7 @@
 		float2 offset;
 
+		const float2 ssaoOffset = 
+			tex2Dlod(samples, float4((0.5f + i + oldIdx) / NUM_PRECOMPUTED_SAMPLES, 0.5f, .0f, .0f)).xy;
+
 		////////////////////
 		//-- add random noise: reflect around random normal vector 
@@ -356,11 +359,13 @@
 			float2 mynoise = tex2Dlod(noiseTex, float4(IN.texCoord * 4.0f, 0, 0)).xy;
 			//offset = myreflect(samples[i], mynoise);
-			offset = myrotate(samples[i], mynoise.x);
+			//offset = myrotate(samples[i], mynoise.x);
+			offset = myrotate(ssaoOffset, mynoise.x);
 		}
 		else
 		{
-			offset = samples[i];
-		}
-		
+			offset = ssaoOffset;
+		}
+
+
 		// weight with projected coordinate to reach similar kernel size for near and far
 		const float2 texcoord = IN.texCoord.xy + offset * scaleFactor;
@@ -375,21 +380,20 @@
 		float3 dirSample = samplePos - centerPosition;
 
-		//const float minDist = 9e-1f;
-		const float minDist = 1e-2f;
-
-		//const float sqrLen = max(SqrLen(dirSample), minDist);
-		//const float lengthToSample = sqrt(sqrLen);
-		const float lengthToSample =  max(length(dirSample), minDist);
-
-		dirSample /= lengthToSample; // normalize
+		const float minDist = 1e-6f;
+		const float scaleFactor = 1e-3f;
+
+		const float lengthToSample = length(dirSample);
+		const float sampleWeight = 1.0f / (lengthToSample + scaleFactor);
+
+		dirSample /= max(length(dirSample), minDist); // normalize
 
 		// angle between current normal and direction to sample controls AO intensity.
-		float cosAngle = dot(dirSample, normal);
+		const float cosAngle = dot(dirSample, normal);
 
 		//const float aoContrib = sampleIntensity / sqrLen;
-		const float aoContrib = sampleIntensity / lengthToSample;
+		const float aoContrib = sampleIntensity * sampleWeight;
 		//const float aoContrib = (1.0f > lengthToSample) ? occlusionPower(9e-2f, DISTANCE_SCALE + lengthToSample): .0f;
 
-		total_ao += max(cosAngle, 0) * aoContrib;
+		total_ao += max(cosAngle, .0f) * aoContrib;
 
 		++ numSamples;
@@ -427,5 +431,5 @@
 			// (=> there was no discontinuity recently)
 			//else if (isMovingObject && (convergence > SSAO_CONVERGENCE_THRESHOLD)) break;
-			//else if (isMovingObject && (convergence > NUM_SAMPLES * 5)) break;
+			else if (isMovingObject && (convergence > NUM_SAMPLES * 5)) break;
 		}
 #endif
@@ -513,6 +517,6 @@
 	
 	float oldWeight = temporalVals.y;
-	float oldIdx = temporalVals.z;
-
+	float oldIdx = temporalCoherence > 1 ? temporalVals.z : 0;
+	
 	float3 ao;
 
@@ -520,13 +524,15 @@
 	if (eyeSpaceDepth < DEPTH_THRESHOLD)
 	{
-		if (0)
-		{
-			ao = ssao(IN, colors, noiseTex, samples, normal, eyeSpacePos.xyz, scaleFactor, bl, br, tl, tr, normalize(viewDir), oldWeight, sampleIntensity, isMovingObject);
+		if (1)
+		{
+			ao = ssao(IN, colors, noiseTex, samples, normal, eyeSpacePos.xyz, 
+				      scaleFactor, bl, br, tl, tr, normalize(viewDir),
+					  oldWeight, sampleIntensity, isMovingObject, oldIdx);
 		}
 		else
 		{
 			ao = ssao2(IN, colors, noiseTex, samples, normal, eyeSpacePos.xyz, scaleFactor, 
-			           bl, br, tl, tr, normalize(viewDir), oldWeight, sampleIntensity, 
-					   isMovingObject, normals, oldIdx);
+			          bl, br, tl, tr, normalize(viewDir), oldWeight, sampleIntensity, 
+					  isMovingObject, normals, oldIdx);
 		}
 	}
Index: /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SampleGenerator.cpp
===================================================================
--- /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SampleGenerator.cpp	(revision 3323)
+++ /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SampleGenerator.cpp	(revision 3329)
@@ -218,33 +218,25 @@
 void QuadraticDiscSampleGenerator2D::Generate(float *samples) const
 {
-#if 0
-	float r[2];
-	Sample2 *s = (Sample2 *)samples;
-
-	for (int i = 0; i < mNumSamples; ++ i)
-	{
-		mHalton->GetNext(r);
-
-		// create samples over disc: the sample density
-		// decreases quadratically with the distance to the origin
-		s[i].x = mRadius * r[1] * sin(2.0f * M_PI * r[0]);
-		s[i].y = mRadius * r[1] * cos(2.0f * M_PI * r[0]);
-	}
-#else
-
-	//PoissonDiscSampleGenerator2D::Generate(samples);
-	RandomSampleGenerator2D::Generate(samples);
-
-	Sample2 *s = (Sample2 *)samples;
-
-	// multiply with lenght to get quadratic dependence on the distance
-	for (int i = 0; i < mNumSamples; ++ i)
-	{
-		Sample2 &spl = s[i];
-
-		float len = sqrt(spl.x * spl.x + spl.y * spl.y);
-		spl.x *= len * mRadius;
-		spl.y *= len * mRadius;
-	}
-#endif
-}
+	Sample2 *s = (Sample2 *)samples;
+
+	int numSamples = 0;
+	float x[2];
+
+	static float total1 = 0;
+	static float total2 = 0;
+	static int totalSamples = 0;
+
+	for (int i = 0; i < mNumSamples; ++ i)
+	{
+		//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;
+
+		s[i].x = rad * cos(a);
+		s[i].y = rad * sin(a);
+	}
+}
