Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaderenv.h
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaderenv.h	(revision 3128)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaderenv.h	(revision 3133)
@@ -58,5 +58,5 @@
 #define NUM_DOWNSAMPLES 9
 
-#define NUM_SSAO_FILTERSAMPLES 50
+#define NUM_SSAO_FILTERSAMPLES 49
 //#define NUM_SSAO_FILTERSAMPLES 40
 //#define NUM_SSAO_FILTERSAMPLES 100
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/combineSsao.cg
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/combineSsao.cg	(revision 3132)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/combineSsao.cg	(revision 3133)
@@ -78,4 +78,5 @@
 	float depthFactor;
 	float normalFactor;
+	float converganceFactor;
 
 	for (int i = 0; i < NUM_SSAO_FILTERSAMPLES; ++ i)
@@ -89,6 +90,8 @@
 		depthFactor = max(step(5e-1f, 1.0f - abs(1.0f - eyeSpaceDepth / aoSample.w)), 1e-3f);
 		normalFactor = max(step(0.6f, dot(sampleNorm, norm)), 1e-3f);
-
-		w = filterWeights[i] * normalFactor * depthFactor;
+		converganceFactor = max(step(8.5f, aoSample.y), 1e-3f);
+
+		//w = filterWeights[i] * normalFactor * depthFactor * converganceFactor;
+		w = filterWeights[i];// * normalFactor * converganceFactor;
 		//w = filterWeights[i] * depthFactor;
 
@@ -107,4 +110,5 @@
 			  uniform sampler2D ssaoTex,
 			  uniform sampler2D normalsTex,
+			  uniform sampler2D offsetTex,
 			  uniform float2 filterOffs[NUM_SSAO_FILTERSAMPLES],
 			  uniform float filterWeights[NUM_SSAO_FILTERSAMPLES]
@@ -119,9 +123,18 @@
 	if (col.w < 1e10f)
 	{
-		const float xoffs = 4.0f / 1024.0f;
-		const float yoffs = 4.0f / 768.0f;
-/*
+		const float xoffs = 20.0f / 1024.0f;
+		const float yoffs = 20.0f / 768.0f;
+
+		/*float3 b2 = tex2Dlod(offsetTex, float4(IN.texCoord + float2(xoffs, 0), 0, 0)).xyz;
+		float3 b3 = tex2Dlod(offsetTex, float4(IN.texCoord + float2(0, yoffs), 0, 0)).xyz;
+		float3 b4 = tex2Dlod(offsetTex, float4(IN.texCoord + float2(-xoffs, 0), 0, 0)).xyz;
+		float3 b5 = tex2Dlod(offsetTex, float4(IN.texCoord + float2(0, -yoffs), 0, 0)).xyz;
+
+		float border = step(0.001f,  b2
+
 		//float3 id = tex2Dlod(attribsTex, float4(IN.texCoord, 0, 0)).xyz;
-		float3 x2 = tex2Dlod(ssaoTex, float4(IN.texCoord + float2(xoffs, 0), 0, 0)).xyz;
+*/
+		
+		/*float3 x2 = tex2Dlod(ssaoTex, float4(IN.texCoord + float2(xoffs, 0), 0, 0)).xyz;
 		float3 x3 = tex2Dlod(ssaoTex, float4(IN.texCoord + float2(0, yoffs), 0, 0)).xyz;
 		float3 x4 = tex2Dlod(ssaoTex, float4(IN.texCoord + float2(-xoffs, 0), 0, 0)).xyz;
@@ -129,4 +142,5 @@
 
 		//ao.x = (ao.x + x2 + x3 + x4 + x5) * 0.2f;
+		if (ao.y < 1.5f)
 		ao.x = (x2 + x3 + x4 + x5) * 0.25f;
 
@@ -134,5 +148,5 @@
 		const static float scaleFactor = 1.0f;
 		//const static float scaleFactor = 10.0f;
-		const static float adaptFactor = 50.0f;
+		const static float adaptFactor = 50000.0f;
 
 		//ao.x = Filter(IN.texCoord, ssaoTex, filterOffs, filterWeights);
@@ -140,13 +154,27 @@
 		//ao.x = DiscontinuityFilter(IN.texCoord, ao, ssaoTex, normalsTex, filterOffs, filterWeights, adaptFactor * scaleFactor * ao.z  / (adaptFactor + ao.y), 0);
 		//ao.x = DiscontinuityFilter(IN.texCoord, ao, ssaoTex, normalsTex, filterOffs, filterWeights, adaptFactor * scaleFactor  / (adaptFactor + ao.y), 0);
-	}
-
+
+		if (ao.y < 10.5f) ao.x = DiscontinuityFilter(IN.texCoord, ao, ssaoTex, normalsTex, filterOffs, filterWeights, 1, 0);
+		//ao.x = DiscontinuityFilter(IN.texCoord, ao, ssaoTex, normalsTex, filterOffs, filterWeights, 1, 0);
+	}
+
+	//float dummy = clamp(1.0f - ao.y * 1e-2f, 0, 1);
+	//float dummy2 = ao.y < 1.5f ? 1.0f : .0f;
 	OUT.illum_col.xyz = col.xyz * ao.x;
-	//OUT.illum_col = float4(ao.x, ao.x, ao.x, col.w);
-	//OUT.illum_col.xyz = float3(1.0f - ao.x, clamp(1.0f - ao.y * 1e-2f, 0, 1), 1);
+
+//	if (ao.y < 1.5f) OUT.illum_col.xyz = float3(10000, 10000, 0);
+//	else if (ao.y < 3.5f) OUT.illum_col.xyz = float3(10000, 0, 10000);
+//	else
+	//	if (ao.y < 10.5f) OUT.illum_col.xyz = float3(0, 10000, 0);
+	//OUT.illum_col = float4(dummy3, dummy3, dummy3, col.w);
+	OUT.illum_col = float4(ao.x, ao.x, ao.x, col.w);
+
+	//OUT.illum_col.xyz = float3(1.0f - ao.x, dummy2, 0);//dummy2);
+	//OUT.illum_col.xyz = float3(0, clamp(1.0f - ao.y * 1e-2f, 0, 1), 1);
 	OUT.illum_col.w = col.w;
 
 	return OUT;
 }
+
 
 float DiscontinuityFilter2(float2 texCoord,
@@ -181,8 +209,9 @@
 		//depthFactor = clamp(1.0f - abs(1.0f - eyeSpaceDepth / aoSample.w), 1e-3f, 1.0f);
 		depthFactor = max(step(5e-1f, 1.0f - abs(1.0f - eyeSpaceDepth / aoSample.w)), 1e-3f);
-		normalFactor = max(step(0.6f, dot(sampleNorm, norm)), 1e-3f);
+		//normalFactor = max(step(0.6f, dot(sampleNorm, norm)), 1e-3f);
 
 		//w = filterWeights[i] * normalFactor * depthFactor;
-		w = normalFactor * depthFactor;
+		//w = normalFactor * depthFactor;
+		w = depthFactor;
 
 		average += aoSample.y * w;
@@ -208,5 +237,5 @@
 	//const static float scaleFactor = 20.0f;
 	const static float scaleFactor = 10.0f;
-	ao.y = DiscontinuityFilter2(IN.texCoord, ao, ssaoTex, normalsTex, filterOffs, filterWeights, scaleFactor * ao.z, 1);
+	//ao.y = DiscontinuityFilter2(IN.texCoord, ao, ssaoTex, normalsTex, filterOffs, filterWeights, 0.5f, 1);
 	//ao.y = DiscontinuityFilter2(IN.texCoord, ao, ssaoTex, normalsTex, filterOffs, filterWeights, scaleFactor, 1);
 	
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg	(revision 3132)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg	(revision 3133)
@@ -143,5 +143,5 @@
 {
 	// compute position from old frame for dynamic objects + translational portion
-	const float3 translatedPos = diffVec + worldPos.xyz - oldEyePos;
+	const float3 translatedPos = diffVec - oldEyePos + worldPos.xyz;
 
 
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.cpp	(revision 3132)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.cpp	(revision 3133)
@@ -94,5 +94,5 @@
 {
 	float g = 1.0f / sqrtf(2.0f * M_PI * rho * rho);
-    g *= expf( -(x*x + y*y) / (2.0f * rho * rho));
+    g *= expf( -(x * x + y * y) / (2.0f * rho * rho));
 
     return g;
@@ -139,4 +139,23 @@
 
 			idx += 2;
+		}
+	}
+}
+
+
+static void ComputeSampleOffsets2(float *sampleOffsets, int w, int h, float width, int samples)
+{
+	const float xoffs = width / (float)w;
+	const float yoffs = width / (float)h;
+	
+	const int numSamples = (int)sqrt((float)samples);
+
+	for (int x = 0; x < numSamples; ++ x)
+	{
+		for (int y = 0; y < numSamples; ++ y)
+		{
+			int idx = (y * numSamples + x) * 2;
+			sampleOffsets[idx + 0] = ((float)x - 0.5f * numSamples) * xoffs;
+			sampleOffsets[idx + 1] = ((float)y - 0.5f * numSamples) * yoffs;
 		}
 	}
@@ -445,14 +464,9 @@
 	///////////
 
-
+#if 0
 	PoissonDiscSampleGenerator2 poisson(NUM_SSAO_FILTERSAMPLES, 1.0f);
 	poisson.Generate((float *)ssaoFilterOffsets);
 
-	//const float filterWidth = 10.0f;
-	//const float filterWidth = 6.0f;
-	const float filterWidth = 20.0f;
-
-	//const float xoffs = filterWidth / mDownSampleFbo->GetWidth();
-	//const float yoffs = filterWidth / mDownSampleFbo->GetHeight();
+	const float filterWidth = 10.0f;
 	const float xoffs = (float)filterWidth / mWidth;
 	const float yoffs = (float)filterWidth / mHeight;
@@ -463,11 +477,21 @@
 		float y = ssaoFilterOffsets[2 * i + 1];
 
-		ssaoFilterWeights[i] = GaussianDistribution(x, y, 1.0f);
-		//ssaoFilterWeights[i] = 1.0f;
+		//ssaoFilterWeights[i] = GaussianDistribution(x, y, 1.0f);
+		ssaoFilterWeights[i] = 1.0f;
 
 		ssaoFilterOffsets[2 * i + 0] *= xoffs;
 		ssaoFilterOffsets[2 * i + 1] *= yoffs;
 	}
-
+#else
+	//ComputeSampleOffsets(ssaoFilterOffsets, 1024, 768, sqrt(NUM_SSAO_FILTERSAMPLES), NUM_SSAO_FILTERSAMPLES); 
+	ComputeSampleOffsets2(ssaoFilterOffsets, 1024, 768, 5, NUM_SSAO_FILTERSAMPLES); 
+
+	for (int i = 0; i < NUM_SSAO_FILTERSAMPLES; ++ i)
+		ssaoFilterWeights[i] = 1.0f;
+
+#endif
+
+	///////
+	//-- pcf tabs for shadowing
 
 	float filterWeights[NUM_PCF_TABS];
@@ -501,15 +525,13 @@
 		FirstPass(fbo, light);
 
-
 	if (mShadingMethod != 0)
 	{
-		// downsample fbo buffers for colors
-		DownSample(fbo, colorBufferIdx, mDownSampleFbo, 0);
-		// normals
-		DownSample(fbo, 1, mDownSampleFbo, 1);
-		// offsets
-		DownSample(fbo, 2, mDownSampleFbo, 2);
-	}
-
+		// downsample fbo buffers
+		DownSample(fbo, colorBufferIdx, mDownSampleFbo, 0); // colors
+		DownSample(fbo, 1, mDownSampleFbo, 1); // normals
+		DownSample(fbo, 2, mDownSampleFbo, 2); // offsets
+	}
+
+	// antialiasing of the color buffer
 	AntiAliasing(fbo, light);
 
@@ -518,5 +540,5 @@
 	case SSAO:
 		ComputeSsao(fbo, tempCohFactor);
-		//SmoothSsao(fbo);
+		SmoothSsao(fbo);
 		CombineSsao(fbo);
 		break;
@@ -562,5 +584,5 @@
 	GLuint colorsTex, normalsTex, attribsTex;
 
-	if (1)
+	if (0)
 	{
 		colorsTex = fbo->GetColorBuffer(colorBufferIdx)->GetTexture();
@@ -794,6 +816,6 @@
 	GLuint colorsTex = fbo->GetColorBuffer(colorBufferIdx)->GetTexture();
 	GLuint normalsTex = fbo->GetColorBuffer(1)->GetTexture();
-	//GLuint ssaoTex = mIllumFbo->GetColorBuffer(2 - mIllumFboIndex)->GetTexture();
-	GLuint ssaoTex = mIllumFbo->GetColorBuffer(mIllumFboIndex)->GetTexture();
+	GLuint ssaoTex = mIllumFbo->GetColorBuffer(2 - mIllumFboIndex)->GetTexture();
+	//GLuint ssaoTex = mIllumFbo->GetColorBuffer(mIllumFboIndex)->GetTexture();
 	
 	FlipFbos(fbo);
