Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg	(revision 3365)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg	(revision 3366)
@@ -474,5 +474,6 @@
 			bool isMovingObject,
 			float oldIdx,
-			sampler2D attribsTex
+			sampler2D attribsTex,
+			float3 oldPos
 			)
 {
@@ -481,5 +482,5 @@
 	float numSamples = .0f;
 
-	float3 diffVec = tex2Dlod(attribsTex, float4(IN.texCoord, 0, 0)).xyz;
+	//float3 diffVec = tex2Dlod(attribsTex, float4(IN.texCoord, 0, 0)).xyz;
 
 	for (int i = 0; i < NUM_SAMPLES; ++ i) 
@@ -513,4 +514,5 @@
 
 		const float4 sampleColor = tex2Dlod(colors, float4(texcoord, .0f, .0f));
+		const float3 oldSamplePos = sampleColor.xyz;
 		const float3 samplePos = ReconstructSamplePos(sampleColor.w, texcoord, bl, br, tl, tr);
 		
@@ -549,31 +551,10 @@
 		if (cosAngle >= 0)
 		{
-			float pixelValid = 0;//sampleColor.x;
-
-			if (1)//pixelValid < 0.5f)
-			{
-				const float3 sampleDiffVec = tex2Dlod(attribsTex, float4(texcoord, .0f, .0f)).xyz;
-				//pixelValid = max(pixelValid, length(sampleDiffVec - diffVec) < 5e-3f ? .0f : 100.0f);
-				pixelValid = max(pixelValid, length(sampleDiffVec - diffVec) < 5e-3f ? .0f : 4.0f);
-				//pixelValid = length(sampleDiffVec - diffVec) < 1e-3f ? .0f : 10.0f;
-			}
-
-			// hack:
-			// we check if the sample could have been near enough to the current pixel 
-			// or if the angle is small enough
-			// to have any influence in the current or last frame
-
-			const float changeFactor = sampleColor.y;
-			const float partlyResetThres = 1.0f;
-
-			if (0)//pixelValid <= partlyResetThres)
-			{
-				const float tooFarAway = step(0.5f, lengthToSample - changeFactor);
-				validSamples = max(validSamples, pixelValid * (1.0f - tooFarAway) * step(-0.1f, cosAngle));
-			}
-			else
-			{
-				validSamples = max(validSamples, pixelValid);
-			}
+			const float oldDistance = length(oldSamplePos - oldPos);
+			const float distanceDiff = abs(oldDistance - lengthToSample);
+
+			float pixelValid = (distanceDiff > 1e-3f) ? 100.0f : 0;
+
+			validSamples = max(validSamples, pixelValid);
 		}
 #ifdef USE_GTX
@@ -643,5 +624,6 @@
 	// reconstruct position from the eye space depth
 	const float3 viewDir = IN.view;
-	const float eyeSpaceDepth = tex2Dlod(colors, float4(IN.texCoord, 0, 0)).w;
+	const float4 mycolor = tex2Dlod(colors, float4(IN.texCoord, 0, 0));
+	const float eyeSpaceDepth = mycolor.w;
 	const float4 eyeSpacePos = float4(-viewDir * eyeSpaceDepth, 1.0f);
 
@@ -712,5 +694,5 @@
 					  br, tl, tr, normalize(viewDir), 
 					  oldWeight, sampleIntensity, isMovingObject, oldIdx,
-					  attribsTex);
+					  attribsTex, mycolor.xyz);
 #endif				  
 		}
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg	(revision 3365)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg	(revision 3366)
@@ -221,19 +221,19 @@
 	if the reprojected pixel from last frame is still
 	valid in the current frame
-	*/
-inline float2 PixelValid(sampler2D oldTex,
-						 float4 color,
-						 float3 difVec,
-						 float2 texCoord,
-						 float3 viewDir,
-						 float3 oldEyePos,
-						 float4x4 modelViewProj,
-						 float4x4 oldModelViewProj,
-						 float3 oldbl,
-						 float3 oldbr,
-						 float3 oldtl,
-						 float3 oldtr,
-						 sampler2D myTex
-						 )
+*/
+/*inline float2 ComputeInfo(sampler2D oldTex,
+						  float4 color,
+						  float3 difVec,
+						  float2 texCoord,
+						  float3 viewDir,
+						  float3 oldEyePos,
+						  float4x4 modelViewProj,
+						  float4x4 oldModelViewProj,
+						  float3 oldbl,
+						  float3 oldbr,
+						  float3 oldtl,
+						  float3 oldtr,
+						  sampler2D myTex
+						  )
 {
 	// reconstruct position from the eye space depth
@@ -241,16 +241,6 @@
 	const float4 worldPos = float4(-viewDir * eyeSpaceDepth, 1.0f);
 
-
-	////////////////
-	//-- calculcate the current projected posiion (also used for next frame)
-	
-	float4 projPos = mul(modelViewProj, worldPos);
-	const float invw = 1.0f / projPos.w;
-	projPos *= invw;
-
 	// compute position from old frame for dynamic objects + translational portion
 	const float3 translatedPos = -oldEyePos + worldPos.xyz + difVec;
-	// don't use difVec here: want to detect if the actual pixel has changed => ssao changed
-	//const float3 translatedPos = -oldEyePos + worldPos.xyz;
 
 
@@ -275,27 +265,5 @@
 	const float3 oldViewDir = Interpol(oldTexCoords, oldbl, oldbr, oldtl, oldtr);
 	const float invLen = 1.0f / length(oldViewDir);
-	const float projectedEyeSpaceDepth = invLen * length(translatedPos);
-	
-	const float depthDif = abs(1.0f - oldEyeSpaceDepth / projectedEyeSpaceDepth);
-	const float squaredLen = SqrLen(difVec);
-	
-
-	// test if this pixel was valid in the old frame
-	float isPixelValid;
-
-	// check if the pixel belonged to a dynamic object in the last frame
-	const bool newDynamic = (squaredLen > DYNAMIC_OBJECTS_THRESHOLD);
-	const bool oldDynamic = (oldDiff > DYNAMIC_OBJECTS_THRESHOLD);
-
-
-	// actually 0 means pixel is valid
-	const float pixelIsValid = .0f;
-	// means that we only use slight temporal coherence over some frames
-	// so that there is no noticeable drag
-	//const float pixelCouldBeValid = 4.0f;
-	const float pixelCouldBeValid = 100.0f;
-	// this pixel information has to be discarded in order to not create artifacts
-	const float pixelIsNotValid = 100.0f;
-
+	
 
 	// check if the pixel was outside of the frame buffer
@@ -324,5 +292,27 @@
 	//isPixelValid = depthDif;
 
-	return float2(isPixelValid, abs(oldEyeSpaceDepth - projectedEyeSpaceDepth));
+	return float3(isPixelValid, abs(oldEyeSpaceDepth - projectedEyeSpaceDepth));
+}
+*/
+
+
+/** This shader computes the reprojection and checks
+	if the reprojected pixel from last frame is still
+	valid in the current frame
+*/
+inline float3 ComputeTranslatedPos(
+						 float4 color,
+						 float3 difVec,
+						 float3 viewDir,
+						 float3 oldEyePos
+						 )
+{
+	// reconstruct position from the eye space depth
+	const float eyeSpaceDepth = color.w;
+	const float4 worldPos = float4(-viewDir * eyeSpaceDepth, 1.0f);
+	// compute position from old frame for dynamic objects + translational portion
+	const float3 translatedPos = -oldEyePos + worldPos.xyz + difVec;
+	
+	return translatedPos;
 }
 
@@ -355,7 +345,6 @@
 	const float3 normal = normalize(tex2Dlod(normalsTex, float4(IN.texCoord, 0, 0)).xyz);
 
-#ifdef PERFORMANCE_TEST
 	// do reprojection and filter out the pixels that are not save
-	const float2 pValid = PixelValid(oldTex,
+/*	const float2 pValid = PixelValid(oldTex,
 		                             color, 
 									 difVec.xyz,
@@ -368,12 +357,13 @@
 									 myTex
 									 );
-#else
-	const float2 pValid = float2(0, 0);
-#endif
 
 	pix.color = color;
 	pix.color.xy = pValid.xy;
 	pix.color.z = color.w;
-
+*/
+	const float3 translatedPos = ComputeTranslatedPos(color, difVec.xyz, IN.view, oldEyePos);
+
+	pix.color.xyz = translatedPos;
+	pix.color.w = color.w;
 	pix.normal = normal;
 
@@ -390,2 +380,4 @@
 	return color;
 }
+
+
