Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaderenv.h
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaderenv.h	(revision 3155)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaderenv.h	(revision 3159)
@@ -64,4 +64,6 @@
 
 
+#define DYNAMIC_OBJECTS_THRESHOLD 1e-7f
+
 
 #endif // __SHADERENV_H
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg	(revision 3156)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg	(revision 3159)
@@ -218,4 +218,12 @@
 
 
+
+inline float SqrLen(float3 v)
+{
+	return v.x * v.x + v.y * v.y + v.z * v.z;
+}
+
+
+
 /** This shader computes the reprojection and checks
 	if the reprojected pixel from last frame is still
@@ -277,14 +285,15 @@
 	const float depthDif = abs(1.0f - oldEyeSpaceDepth / projectedEyeSpaceDepth);
 
-	const float squaredLen = diffVec.x * diffVec.x + diffVec.y * diffVec.y + diffVec.z * diffVec.z;
-	//if (squaredLen < 1e-8f) // object not dynamic
-	//{}
-
+	const float squaredLen = SqrLen(diffVec);
+	
+	// test if this pixel was not valid in the old frame
 	float validPixel;
 
-	if (1
+	if (((squaredLen <= DYNAMIC_OBJECTS_THRESHOLD) && (oldPixel.z <= DYNAMIC_OBJECTS_THRESHOLD)) ||
+		(1 
 		&& (oldTexCoords.x >= 0.0f) && (oldTexCoords.x < 1.0f)
 		&& (oldTexCoords.y >= 0.0f) && (oldTexCoords.y < 1.0f)
-		&& (depthDif <= MIN_DEPTH_DIFF) 
+		&& (depthDif <= MIN_DEPTH_DIFF)
+		)
 		//&& (depthDif <= 9e-1f) 
 		)
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/combineSsao.cg
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/combineSsao.cg	(revision 3156)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/combineSsao.cg	(revision 3159)
@@ -106,5 +106,5 @@
 		const float scale =	adaptFactor * scaleFactor * ao.z  / (adaptFactor + ao.y);
 
-		ao.x = DiscontinuityFilter(IN.texCoord, ao, col, ssaoTex, normalsTex, colorsTex, filterOffs, filterWeights, scale);
+		//ao.x = DiscontinuityFilter(IN.texCoord, ao, col, ssaoTex, normalsTex, colorsTex, filterOffs, filterWeights, scale);
 	}
 
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg	(revision 3158)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg	(revision 3159)
@@ -26,4 +26,10 @@
 {
 	return 6.283185307179586476925286766559f * (1.0f - cos(asin(radius / dist)));
+}
+
+
+inline float SqrLen(float3 v)
+{
+	return v.x * v.x + v.y * v.y + v.z * v.z;
 }
 
@@ -75,13 +81,6 @@
 								float temporalCoherence,
 								sampler2D colors,
-								float3 bl,
-								float3 br,
-								float3 tl,
-								float3 tr, 
 								float3 projPos,
 								float invW,
-								sampler2D noiseTex,
-								float2 samples[NUM_SAMPLES],
-								float scaleFactor,
 								float3 oldbl,
 								float3 oldbr,
@@ -132,5 +131,6 @@
 #endif
 
-	const float squaredLen = diffVec.x * diffVec.x + diffVec.y * diffVec.y + diffVec.z * diffVec.z;
+	const float squaredLen = SqrLen(diffVec);
+
 	const float oldWeight = clamp(oldPixel.y, .0f, temporalCoherence);
 	//const float oldWeight = oldPixel.y;
@@ -149,5 +149,9 @@
 		// increase the weight for convergence
 		newWeight = oldWeight + 1.0f;
-		if ((pixelValid > 1.0f) && (squaredLen < 1e-8f)) newWeight = 4.0f;
+		
+		if ((pixelValid > 1.0f) && (squaredLen < DYNAMIC_OBJECTS_THRESHOLD))
+		{		
+			newWeight = 4.0f;
+		}
 		//if (pixelValid > 1.0f) newWeight = max(15.0f - notValid * 2.0f, 1.0f);
 	}
@@ -208,4 +212,5 @@
 
 		const float3 samplePos = ReconstructSamplePos(sampleColor.w, texcoord, bl, br, tl, tr);
+		// the normal of the current sample
 		const float3 sampleNormal = normalize(tex2Dlod(normalTex, float4(texcoord, 0, 0)).xyz);
 
@@ -391,10 +396,6 @@
 	                                        oldTex, oldModelViewProj, temporalCoherence,
 											colors, 
-											bl, br, tl, tr, 
 											projPos.xyz, 
 											invw, 
-											noiseTex, 
-											samples, 
-											scaleFactor, 
 											oldbl, oldbr, oldtl, oldtr,
 											diffVec,
@@ -408,5 +409,5 @@
 	OUT.illum_col.x = (ao.x + oldSsao * (newWeight - 1.0f)) / newWeight;
 	OUT.illum_col.y = newWeight;
-	OUT.illum_col.z = invw;
+	OUT.illum_col.z = SqrLen(diffVec);//invw;
 	OUT.illum_col.w = eyeSpaceDepth;
 
