Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaderenv.h
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaderenv.h	(revision 3159)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaderenv.h	(revision 3160)
@@ -51,5 +51,5 @@
 
 #define MAX_LOD_LEVEL 10
-// burnout (really bright regions will be saturated to white)
+/// burnout (really bright regions will be saturated to white)
 #define WHITE_LUMINANCE 3e4f
 
@@ -64,5 +64,5 @@
 
 
-#define DYNAMIC_OBJECTS_THRESHOLD 1e-7f
+#define DYNAMIC_OBJECTS_THRESHOLD 1e-8f
 
 
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg	(revision 3159)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg	(revision 3160)
@@ -290,14 +290,11 @@
 	float validPixel;
 
-	if (((squaredLen <= DYNAMIC_OBJECTS_THRESHOLD) && (oldPixel.z <= DYNAMIC_OBJECTS_THRESHOLD)) ||
-		(1 
+	if ((((squaredLen <= DYNAMIC_OBJECTS_THRESHOLD) && (oldPixel.z <= DYNAMIC_OBJECTS_THRESHOLD)) || 
+		(depthDif <= 1e-2))
 		&& (oldTexCoords.x >= 0.0f) && (oldTexCoords.x < 1.0f)
 		&& (oldTexCoords.y >= 0.0f) && (oldTexCoords.y < 1.0f)
-		&& (depthDif <= MIN_DEPTH_DIFF)
-		)
-		//&& (depthDif <= 9e-1f) 
 		)
 	{
-		validPixel = 0.0f;//5f;
+		validPixel = 0.0f;
 	}
 	else
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/combineSsao.cg
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/combineSsao.cg	(revision 3159)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/combineSsao.cg	(revision 3160)
@@ -89,7 +89,7 @@
 			  uniform sampler2D ssaoTex,
 			  uniform sampler2D normalsTex,
-			  uniform sampler2D offsetTex,
 			  uniform float2 filterOffs[NUM_SSAO_FILTERSAMPLES],
-			  uniform float filterWeights[NUM_SSAO_FILTERSAMPLES]
+			  uniform float filterWeights[NUM_SSAO_FILTERSAMPLES],
+			  uniform float4x4 modelViewProj
 			  )
 {
@@ -99,12 +99,21 @@
 	float4 ao = tex2Dlod(ssaoTex, float4(IN.texCoord, 0, 0));
 
-	if ((ao.y < 70.0f) && (col.w < 1e10f))
+	// reconstruct position from the eye space depth
+	const float eyeSpaceDepth = col.w;
+	const float4 worldPos = float4(-IN.view * eyeSpaceDepth, 1.0f);
+	// compute w factor from projection in order to control filter size
+	const float4 projPos = mul(modelViewProj, worldPos);
+	const float distanceScale = 1.0f / projPos.w;
+
+	const float convergence = ao.y;
+
+	if ((ao.y < 100.0f) && (col.w < 1e10f))
 	//if (col.w < 1e10f)
 	{
 		const float scaleFactor = 1.0f;
-		const float adaptFactor = 10.0f;
-		const float scale =	adaptFactor * scaleFactor * ao.z  / (adaptFactor + ao.y);
+		const float adaptFactor = 5.0f;
+		const float scale =	adaptFactor * scaleFactor * distanceScale / (adaptFactor + convergence);
 
-		//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/DeferredRenderer.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.cpp	(revision 3156)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.cpp	(revision 3160)
@@ -414,6 +414,6 @@
 	string combineSsaoParams[] = 
 		{"colorsTex", "normalsTex", "ssaoTex", "filterOffs", 
-		 "filterWeights", "bl", "br", "tl", "tr"};
-	sCgCombineSsaoProgram->AddParameters(combineSsaoParams, 0, 9);
+		 "filterWeights", "modelViewProj"};
+	sCgCombineSsaoProgram->AddParameters(combineSsaoParams, 0, 6);
 
 	//////////////
@@ -455,4 +455,5 @@
 
 	const float filterWidth = 100.0f;
+	//const float filterWidth = 200.0f;
 
 	PoissonDiscSampleGenerator2 poisson(NUM_SSAO_FILTERSAMPLES, 1.0f);
@@ -740,11 +741,13 @@
 	GLuint oldIllumTex = mIllumFbo->GetColorBuffer(2 - mIllumFboIndex + 1)->GetTexture();
 
-	sCgGiProgram->SetTexture(0, colorsTex);
-	sCgGiProgram->SetTexture(1, normalsTex);
-	sCgGiProgram->SetTexture(2, noiseTex2D);
-	sCgGiProgram->SetTexture(3, oldSsaoTex);
-	sCgGiProgram->SetTexture(4, oldIllumTex);
-
-	sCgGiProgram->SetValue1f(5, 
+	int i = 0;
+
+	sCgGiProgram->SetTexture(i ++, colorsTex);
+	sCgGiProgram->SetTexture(i ++, normalsTex);
+	sCgGiProgram->SetTexture(i ++, noiseTex2D);
+	sCgGiProgram->SetTexture(i ++, oldSsaoTex);
+	sCgGiProgram->SetTexture(i ++, oldIllumTex);
+
+	sCgGiProgram->SetValue1f(i ++, 
 		(mUseTemporalCoherence && !mRegenerateSamples) ? tempCohFactor : 0);
 
@@ -758,5 +761,5 @@
 		GenerateSamples(mSamplingMethod); 
 
-		sCgGiProgram->SetArray2f(6, (float *)samples2, NUM_SAMPLES);
+		sCgGiProgram->SetArray2f(i ++, (float *)samples2, NUM_SAMPLES);
 	}
 
@@ -766,11 +769,11 @@
 	Vector3 tr = mCornersView[3];
 
-	sCgGiProgram->SetValue3f(7, bl.x, bl.y, bl.z);
-	sCgGiProgram->SetValue3f(8, br.x, br.y, br.z);
-	sCgGiProgram->SetValue3f(9, tl.x, tl.y, tl.z);
-	sCgGiProgram->SetValue3f(10, tr.x, tr.y, tr.z);
-
-	sCgGiProgram->SetMatrix(11, mOldProjViewMatrix);
-	sCgGiProgram->SetMatrix(12, mProjViewMatrix);
+	sCgGiProgram->SetValue3f(i ++, bl.x, bl.y, bl.z);
+	sCgGiProgram->SetValue3f(i ++, br.x, br.y, br.z);
+	sCgGiProgram->SetValue3f(i ++, tl.x, tl.y, tl.z);
+	sCgGiProgram->SetValue3f(i ++, tr.x, tr.y, tr.z);
+
+	sCgGiProgram->SetMatrix(i ++, mOldProjViewMatrix);
+	sCgGiProgram->SetMatrix(i ++, mProjViewMatrix);
 
 
@@ -819,8 +822,5 @@
 	sCgCombineSsaoProgram->SetArray1f(i ++, (float *)ssaoFilterWeights, NUM_SSAO_FILTERSAMPLES);
 	
-	Vector3 bl = mCornersView[0];
-	Vector3 br = mCornersView[1];
-	Vector3 tl = mCornersView[2];
-	Vector3 tr = mCornersView[3];
+	sCgCombineSsaoProgram->SetMatrix(i++, mProjViewMatrix);
 
 
