Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaderenv.h
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaderenv.h	(revision 3167)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaderenv.h	(revision 3189)
@@ -6,16 +6,18 @@
 //-- ssao + gi parameters
 
-#define NUM_SAMPLES 8
+//#define NUM_SAMPLES 8
+#define NUM_SAMPLES 16
 //#define NUM_SAMPLES 24
 
 // for quadratic falloff
 //#define SAMPLE_INTENSITY 0.2f
-#define SAMPLE_INTENSITY 0.07f
-//#define SAMPLE_INTENSITY 0.01f
+//#define SAMPLE_INTENSITY 0.07f
+#define SAMPLE_INTENSITY 0.008f
 
 //#define SAMPLE_INTENSITY 0.075f
 //#define SAMPLE_INTENSITY 0.2f
 
-#define SAMPLE_RADIUS 8e-1f
+//#define SAMPLE_RADIUS 8e-1f
+#define SAMPLE_RADIUS 4e-1f
 
 //#define DISTANCE_SCALE 1e-1f
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg	(revision 3168)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg	(revision 3189)
@@ -290,6 +290,9 @@
 	float validPixel;
 
-	if ((((squaredLen <= DYNAMIC_OBJECTS_THRESHOLD) && (oldPixel.z <= DYNAMIC_OBJECTS_THRESHOLD)) || 
-		(depthDif <= MIN_DEPTH_DIFF))
+	const bool oldDynamic = (squaredLen <= DYNAMIC_OBJECTS_THRESHOLD);
+	const bool newDynamic = (oldPixel.z <= DYNAMIC_OBJECTS_THRESHOLD);
+
+	if (!(oldDynamic && !newDynamic) && !(!oldDynamic && newDynamic) &&
+		!(oldDynamic && newDynamic && (depthDif > MIN_DEPTH_DIFF))
 		&& (oldTexCoords.x >= 0.0f) && (oldTexCoords.x < 1.0f)
 		&& (oldTexCoords.y >= 0.0f) && (oldTexCoords.y < 1.0f)
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/combineSsao.cg
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/combineSsao.cg	(revision 3168)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/combineSsao.cg	(revision 3189)
@@ -130,6 +130,6 @@
 		spatialFactor = 1.0f / max(len, 1e-3f);
 
-		//normalFactor = max(step(0.6f, dot(sampleNorm, centerNormal)), 1e-3f);
-		normalFactor = max(dot(sampleNorm, samplePos), 1e-3f);
+		normalFactor = max(step(.0f, dot(sampleNorm, centerNormal)), 1e-3f);
+		//normalFactor = max(dot(sampleNorm, samplePos), 1e-3f);
 		//convergenceFactor = min(100.0f, aoSample.y);
 		convergenceFactor = aoSample.y;
@@ -137,4 +137,5 @@
 		// combine the weights
 		w = convergenceFactor * spatialFactor * normalFactor;
+		//w = convergenceFactor * spatialFactor;
 
 		average += aoSample.x * w;
@@ -169,11 +170,4 @@
 	float4 ao = tex2Dlod(ssaoTex, float4(IN.texCoord, 0, 0));
 
-	// reconstruct position from the eye space depth
-	/*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;
-*/
-
 	// filter up to a certain convergance value and leave out background (sky) by checking depth
 	if ((ao.y < 100.0f) && (col.w < 1e10f))
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/antialiasing.cg
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/antialiasing.cg	(revision 3175)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/antialiasing.cg	(revision 3189)
@@ -76,5 +76,5 @@
 
 	//const float de = saturate(dot(dd, weights.y));
-	const float de = weights.y * dd.x + dd.y + dd.z + dd.w;
+	const float de = weights.y * dd.x * dd.y * dd.z * dd.w;
 
 
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SkyPreetham.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SkyPreetham.cpp	(revision 3123)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SkyPreetham.cpp	(revision 3189)
@@ -293,5 +293,5 @@
 	// downscale ambient color
 	if (scaleToRange)
-		ambient *= 5e-6f;
+		ambient *= 8e-6f;
 	else
 		ambient *= 1e-1f;
@@ -333,5 +333,5 @@
 	// calculate final sun diffuse color.
 	if (scaleToRange)
-		diffuse = color * 1e-5f;
+		diffuse = color * 3e-5f;
 	else
 		diffuse = color * 3e-1f;
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.h
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.h	(revision 3175)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.h	(revision 3189)
@@ -56,4 +56,6 @@
 	*/
 	void SetShadingMethod(SHADING_METHOD s);
+
+	void SetSortSamples(bool sortSamples) { mSortSamples = sortSamples; }
 
 	// hack: store the color buffer idx for the currently used flip flop-MRT here
@@ -146,4 +148,6 @@
 	Vector3 mEyePos;
 	Vector3 mOldEyePos;
+
+	bool mSortSamples;
 };
 
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp	(revision 3175)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp	(revision 3189)
@@ -106,5 +106,5 @@
 
 MotionPath *motionPath = NULL;
-
+/// max depth where candidates for tighter bounds are searched
 int maxDepthForTestingChildren = 3;
 
@@ -213,6 +213,7 @@
 PerformanceGraph *perfGraph = NULL;
 
-static float ssaoTempCohFactor = 255.0;
-static int sCurrentMrtSet = 0;
+float ssaoTempCohFactor = 255.0;
+bool sortSamples = true;
+int sCurrentMrtSet = 0;
 
 static Matrix4x4 invTrafo = IdentityMatrix();
@@ -1138,4 +1139,5 @@
 		deferredShader->SetSamplingMethod(samplingMethod);
 		deferredShader->SetUseTemporalCoherence(useTemporalCoherence);
+		deferredShader->SetSortSamples(sortSamples);
 
 		ShadowMap *sm = showShadowMap ? shadowMap : NULL;
@@ -1311,5 +1313,4 @@
 		useRenderQueue = !useRenderQueue;
 		traverser->SetUseRenderQueue(useRenderQueue);
-		
 		break;
 	case 'b':
@@ -1329,4 +1330,7 @@
 	case 'I':
 		useAntiAliasing = !useAntiAliasing;
+		break;
+	case '9':
+		sortSamples = !sortSamples;
 		break;
 	default:
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.cpp	(revision 3175)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.cpp	(revision 3189)
@@ -287,11 +287,12 @@
 mSamplingMethod(SAMPLING_POISSON),
 mShadingMethod(DEFAULT),
-mIllumFboIndex(0)
+mIllumFboIndex(0),
+mSortSamples(true)
 {
 	///////////
 	//-- the flip-flop fbos
 
-	const int dsw = w / 2; const int dsh = h / 2;
-	//const int dsw = w; const int dsh = h;
+	//const int dsw = w / 2; const int dsh = h / 2;
+	const int dsw = w; const int dsh = h;
 
 	mIllumFbo = new FrameBufferObject(dsw, dsh, FrameBufferObject::DEPTH_NONE);
@@ -515,6 +516,7 @@
 	}
 
-	// antialiasing of the color buffer
-	//AntiAliasing(fbo, light);
+	// multisampling is difficult / costly with deferred shading
+	// at least do some edge blurring 
+	if (useAntiAliasing) AntiAliasing(fbo, light);
 
 	switch (mShadingMethod)
@@ -543,9 +545,6 @@
 	// multisampling is difficult / costly with deferred shading
 	// at least do some edge blurring 
-
-	if (useAntiAliasing)
-		AntiAliasing(fbo, light);
-	else
-		Output(fbo); // just output the latest buffer
+	//if (useAntiAliasing) AntiAliasing(fbo, light); else 
+	Output(fbo); // just output the latest buffer
 
 	glEnable(GL_LIGHTING);
@@ -590,15 +589,4 @@
 void DeferredRenderer::SortSamples()
 {
-	//for (int i = 0; i < NUM_SAMPLES; ++ i)cout << SqrDist(samples2[i-1], samples2[i]) << "|";
-	float dist = 0;
-	for (int i = 1; i < NUM_SAMPLES; ++ i)
-		dist += SqrDist(samples2[i-1], samples2[i]);
-		//cout << samples2[i].x << " " << samples2[i].y 
-
-	//cout << "\nbefore: " << dist << endl;
-
-	//sort(samples2, samples2 + sizeof(samples2) / sizeof(Sample2), lt2);
-
-
 	static Sample2 tempSamples[NUM_SAMPLES];
 	static bool checked[NUM_SAMPLES];
@@ -636,11 +624,4 @@
 	for (int i = 0; i < NUM_SAMPLES; ++ i)
 		samples2[i] = tempSamples[i];
-
-	dist = 0;
-	for (int i = 1; i < NUM_SAMPLES; ++ i)
-		dist += SqrDist(samples2[i-1], samples2[i]);
-		//cout << samples2[i].x << " " << samples2[i].y << " " << SqrDist(samples2[i-1], samples2[i]) << "|";
-
-	//cout << "after:  " << dist << endl;
 }
 
@@ -693,5 +674,5 @@
 		GenerateSamples(mSamplingMethod);
 
-		SortSamples();
+		if (mSortSamples) { SortSamples(); }
 		sCgSsaoProgram->SetArray2f(i, (float *)samples2, NUM_SAMPLES);
 	}
@@ -749,7 +730,7 @@
 
 	// read the second buffer, write to the first buffer
-	//FlipFbos(fbo);
+	FlipFbos(fbo);
 	// end of the pipeline => just draw image to screen
-	FrameBufferObject::Release();
+	//FrameBufferObject::Release();
 
 	// the neighbouring texels
