Index: /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaderenv.h
===================================================================
--- /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaderenv.h	(revision 3204)
+++ /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaderenv.h	(revision 3206)
@@ -11,5 +11,5 @@
 //#define NUM_SAMPLES 96
 
-#define SAMPLE_INTENSITY 0.3f
+#define SAMPLE_INTENSITY 0.2f
 //#define SAMPLE_INTENSITY 2.0f
 
@@ -27,6 +27,9 @@
 //#define NUM_SSAO_FILTERSAMPLES 80
 #define NUM_SSAO_FILTER_SAMPLES 16
+
 #define SSAO_FILTER_WIDTH 12.0f
-#define SSAO_CONVERGENCE_WEIGHT 300.0f
+//#define SSAO_FILTER_WIDTH 6.0f
+
+#define SSAO_CONVERGENCE_THRESHOLD 700.0f
 
 
Index: /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg
===================================================================
--- /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg	(revision 3204)
+++ /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg	(revision 3206)
@@ -201,5 +201,5 @@
 	valid in the current frame
 	*/
-inline float PixelValid(sampler2D oldTex,
+inline float2 PixelValid(sampler2D oldTex,
 						float4 color,
 						float3 difVec,
@@ -262,6 +262,6 @@
 	const bool newDynamic = (oldPixel.z > DYNAMIC_OBJECTS_THRESHOLD);
 
-	const float xOffs = 1.0f / 1024.0f;
-	const float yOffs = 1.0f / 768.0f;
+	//const float xOffs = 1.0f / 1024.0f;	const float yOffs = 1.0f / 768.0f;
+	//const float eps = 1e-6f;
 
 	// actually 0 means pixel is valid
@@ -270,21 +270,15 @@
 	const float pixelNotValid = 10.0f;
 
-	const float eps = 1e-6f;
-
-	if (0
-		//&& !(oldDynamic && newDynamic && (depthDif <= MIN_DEPTH_DIFF))
-		//&& (oldTexCoords.x + eps >= xOffs) && (oldTexCoords.x <= (1.0f - xOffs) + eps )
-		//&& (oldTexCoords.y + eps >= yOffs) && (oldTexCoords.y <= (1.0f - yOffs) + eps )
-		|| (oldTexCoords.x < .0f) || (oldTexCoords.x >= 1.0f)
-		|| (oldTexCoords.y < .0f) || (oldTexCoords.y >= 1.0f)
-		)
+	if ((oldTexCoords.x < .0f) || (oldTexCoords.x >= 1.0f) || 
+		(oldTexCoords.y < .0f) || (oldTexCoords.y >= 1.0f))
 	{
 		pixelValid = pixelNotValid;
 	}
-	// check if changed from dynamic to not dynamic object
-	// or there is a depth discontinuity
 	else 
-	if ((oldDynamic && !newDynamic) || (!oldDynamic && newDynamic) ||
-		(oldDynamic && newDynamic && (depthDif <= MIN_DEPTH_DIFF)))
+	if (
+		// check if changed from dynamic to not dynamic object
+		(oldDynamic && !newDynamic) || (!oldDynamic && newDynamic) ||
+		// check if we have a dynamic object and is a depth discontinuity
+		((oldDynamic || newDynamic) && (depthDif <= MIN_DEPTH_DIFF)))
 	{	
 		pixelValid = pixelCouldBeValid; 
@@ -295,5 +289,5 @@
 	}
 
-	return pixelValid;
+	return float2(pixelValid, abs(oldEyeSpaceDepth - projectedEyeSpaceDepth));
 }
 
@@ -325,5 +319,5 @@
 
 	// do reprojection and filter out the pixels that are not save
-	float pValid = PixelValid(oldTex,
+	float2 pValid = PixelValid(oldTex,
                               color, 
 							  difVec.xyz,
@@ -337,5 +331,5 @@
 
 	pix.color = color;
-	pix.color.x = pValid;
+	pix.color.xy = pValid.xy;
 	pix.normal = normal;
 
Index: /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/combineSsao.cg
===================================================================
--- /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/combineSsao.cg	(revision 3205)
+++ /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/combineSsao.cg	(revision 3206)
@@ -166,6 +166,6 @@
 			  uniform float3 tl,
 			  uniform float3 tr,
-			  uniform float3 w,
-			  uniform float3 h
+			  uniform float w,
+			  uniform float h
 			  )
 {
@@ -200,15 +200,14 @@
 	//const float convergence = ao.y;
 
-	// filter reaches size 1 pixel after thres samples: 
+	// filter reaches size 1 pixel when sample size reaches threshold 
 	// afterwards we do not use the filter anymore
-	const float thres = 500.0f; 
 
 	// filter up to a certain convergance value and leave out background (sky) by checking depth
-	if ((convergence < thres) && (col.w < 1e10f))
+	if ((convergence < SSAO_CONVERGENCE_THRESHOLD) && (col.w < 1e10f))
 	{
 		const float distanceScale = 1.0f;
 
 		// descend to zero filter size after reaching thres pixels
-		const float convergenceWeight = thres / (SSAO_FILTER_WIDTH - 1.0f);
+		const float convergenceWeight = SSAO_CONVERGENCE_THRESHOLD / (SSAO_FILTER_WIDTH - 1.0f);
 		const float convergenceScale = convergenceWeight / (convergence + convergenceWeight);
 		const float scale = SSAO_FILTER_WIDTH * convergenceScale * distanceScale;
@@ -235,5 +234,4 @@
 
 
-
 /** Function combining image and indirect illumination buffer using a 
 	depth and normal aware discontinuity filter.
Index: /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg
===================================================================
--- /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg	(revision 3205)
+++ /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg	(revision 3206)
@@ -322,12 +322,17 @@
 #endif
 
+		++ numSamples;
+		
 		// check if the samples have been valid in the last frame
-		// hack: the distance measure can fail in some cases => choose something different
-		const float tooFarAway = step(1.0f, lengthToSample);
-		validSamples = max(validSamples, (1.0f - tooFarAway) * sampleColor.x);
-
+		// only mark sample as invalid if taking it into account can have influence the ssao:
+		// hence we also check if the sample or the same sample in the previous frame
+		// had any chance to be near the current sample
+		const float changeFactor = sampleColor.y;
+		const float pixelValid = sampleColor.x;
+
+		// hack: cedistance measure can fail in some cases => choose something different
+		const float tooFarAway = step(0.5f, lengthToSample - changeFactor);
+		validSamples = max(validSamples, (1.0f - tooFarAway) * pixelValid);
 		//validSamples += sampleColor.x;
-
-		++ numSamples;
 
 		//if ((validSamples < 1.0f) && (newWeight > 200) && (numSamples >= 8)) break;
@@ -417,15 +422,21 @@
 	const float squaredLen = SqrLen(diffVec);
 
-	if (ao.y > 4.0f) oldWeight = 0;
-	else if ((ao.y > 1.0f) && (squaredLen < DYNAMIC_OBJECTS_THRESHOLD))
-		oldWeight = min(oldWeight, 4.0f * NUM_SAMPLES);
-	
+	// check if we have to reset pixel because one of the sample points was invalid
+	if (squaredLen < DYNAMIC_OBJECTS_THRESHOLD)
+	{
+		if (ao.y > 4.0f) 
+			oldWeight = 0; 
+		else if (ao.y > 1.0f)
+			oldWeight = min(oldWeight, 4.0f * NUM_SAMPLES);
+	}
+
 	const float newWeight = ao.z;
-
+	const float combinedWeight = clamp(newWeight + oldWeight, .0f, temporalCoherence);
+
+	
 	// blend between old and new samples (and avoid division by zero)
-	OUT.illum_col.x = (ao.x * newWeight + oldSsao * oldWeight) / max(1e-6f, (newWeight + oldWeight));
-	OUT.illum_col.y = clamp(newWeight + oldWeight, .0f, temporalCoherence);
-
+	OUT.illum_col.x = (ao.x * newWeight + oldSsao * oldWeight) / max(1e-6f, newWeight + oldWeight);
 	OUT.illum_col.z = SqrLen(diffVec);
+	OUT.illum_col.y = combinedWeight;
 	OUT.illum_col.w = eyeSpaceDepth;
 
Index: /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.cpp
===================================================================
--- /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.cpp	(revision 3205)
+++ /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.cpp	(revision 3206)
@@ -116,5 +116,5 @@
 
 
-static Sample2 UnitTest2(float x, float y, int wi, int he)
+static Sample2 UnitTest(float x, float y, int wi, int he)
 {
 	Sample2 s;
@@ -351,13 +351,4 @@
 
 	InitCg();
-
-	float x = 400.5f / w;
-	float y = 100.5f / h;
-	
-	Sample2 res = UnitTest2(x, y, dsw, dsh);
-
-	cout << "input  : " << x << ", " << y << endl;
-	cout << "result : " << res.x << " " << res.y << endl;
-	cout << "result2: " << res.x * w << " " << res.y * h << endl;
 }
 
@@ -366,4 +357,5 @@
 {
 	CLEAR_CONTAINER(mFBOs);
+
 	glDeleteTextures(1, &noiseTex2D);
 	glDeleteTextures(1, &noiseTex1D);
