Index: /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg
===================================================================
--- /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg	(revision 3314)
+++ /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg	(revision 3316)
@@ -48,5 +48,5 @@
 	weight of the pixel in the new frame.
 */
-inline float2 temporalSmoothing(float4 worldPos,
+inline float2 Reproject(float4 worldPos,
 								float eyeSpaceDepth,
 								float2 texcoord0,
@@ -107,5 +107,11 @@
 	{
 		// pixel valid => retrieve the convergence weight
-		w = oldPixel.y;
+		float w1 = tex2Dlod(oldTex, float4(oldTexCoords + float2(0.5f / 1024.0f, 0), .0f, .0f)).y;
+		float w2 = tex2Dlod(oldTex, float4(oldTexCoords - float2(0.5f / 1024.0f, 0), .0f, .0f)).y;
+		float w3 = tex2Dlod(oldTex, float4(oldTexCoords + float2(0, 0.5f / 768.0f), .0f, .0f)).y;
+		float w4 = tex2Dlod(oldTex, float4(oldTexCoords - float2(0, 0.5f / 768.0f), .0f, .0f)).y;
+
+		w = min(min(w1, w2), min(w3, w4));
+		//w = oldPixel.y;
 	}
 	else
@@ -385,12 +391,12 @@
 	//-- compute temporal reprojection
 
-	float2 temporalVals = temporalSmoothing(eyeSpacePos, eyeSpaceDepth, IN.texCoord, oldEyePos,
-	                                        oldTex, oldModelViewProj, 
-											colors, 
-											projPos.xyz, 
-											invw, 
-											oldbl, oldbr, oldtl, oldtr,
-											diffVec
-											);
+	float2 temporalVals = Reproject(eyeSpacePos, eyeSpaceDepth, IN.texCoord, oldEyePos,
+	                                oldTex, oldModelViewProj, 
+									colors, 
+									projPos.xyz, 
+									invw, 
+									oldbl, oldbr, oldtl, oldtr,
+									diffVec
+									);
 
 	const float oldSsao = temporalVals.x;
Index: /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/combineSsaoSep.cg
===================================================================
--- /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/combineSsaoSep.cg	(revision 3314)
+++ /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/combineSsaoSep.cg	(revision 3316)
@@ -58,5 +58,6 @@
 					float3 br,
 					float3 tl,
-					float3 tr)
+					float3 tr,
+					float maxConvergence)
 {
 	float2 aoSample = tex2Dlod(ssaoTex, sampleTexCoord);
@@ -72,8 +73,8 @@
 	float spatialFactor = 1.0f / max(len, 1e-3f);
 
-	float convergenceFactor = aoSample.y + 1.0f;
+	float convergenceFactor = min(aoSample.y + 1.0f, maxConvergence);
+	convergenceFactor *= convergenceFactor;
 
 	// combine the weights
-	//float w = convergenceFactor * convergenceFactor * spatialFactor;
 	float w = convergenceFactor * spatialFactor;
 	//float w = spatialFactor;
@@ -96,5 +97,7 @@
 			   float3 tr,
 			   float2 xyStep,
-			   float convergence)
+			   float convergence,
+			   float maxConvergence
+			   )
 {
 	float2 result = float2(0.0f, 0.0f);
@@ -109,5 +112,5 @@
 	{
 		float4 sampleTexCoord = float4(texCoord + i * xyStep * scale, .0f, .0f);
-		result += FilterSample(sampleTexCoord, ssaoTex, colorsTex, centerPos, bl, br, tl, tr);
+		result += FilterSample(sampleTexCoord, ssaoTex, colorsTex, centerPos, bl, br, tl, tr, maxConvergence);
 	}
 
@@ -148,5 +151,5 @@
 	{
 		// the filtered ssao value
-		OUT.illum_col.x = FilterXY(IN.texCoord, ssaoTex, colorsTex, bl, br, tl, tr, xyStep, convergence);
+		OUT.illum_col.x = FilterXY(IN.texCoord, ssaoTex, colorsTex, bl, br, tl, tr, xyStep, convergence, maxConvergence);
 	}
 
@@ -163,5 +166,6 @@
 						uniform float3 tl,
 						uniform float3 tr,
-						uniform float2 res
+						uniform float2 res,
+						uniform float maxConvergence
 						)
 {
@@ -183,5 +187,5 @@
 	{
 		// the filtered ssao value
-		OUT.illum_col.x = FilterXY(IN.texCoord, ssaoTex, colorsTex, bl, br, tl, tr, xyStep, convergence);
+		OUT.illum_col.x = FilterXY(IN.texCoord, ssaoTex, colorsTex, bl, br, tl, tr, xyStep, convergence, maxConvergence);
 	}
 
@@ -200,5 +204,6 @@
 				  uniform float3 tl,
 				  uniform float3 tr,
-				  uniform float2 res
+				  uniform float2 res,
+				  uniform float maxConvergence
 				  )
 {
@@ -221,5 +226,5 @@
 	{
 		// the filtered ssao value
-		ao.x = FilterXY(IN.texCoord, ssaoTex, colorsTex, bl, br, tl, tr, xyStep, convergence);
+		ao.x = FilterXY(IN.texCoord, ssaoTex, colorsTex, bl, br, tl, tr, xyStep, convergence, maxConvergence);
 	}
 
Index: /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.h
===================================================================
--- /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.h	(revision 3305)
+++ /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.h	(revision 3316)
@@ -95,4 +95,8 @@
 	void SetTemporalCoherenceFactorForSsao(float factor);
 
+	/** Sets the maxinal convergence factor for ssao filter
+	*/
+	void SetMaxConvergence(float c);
+
 
 	// hack: store the color buffer idx for the currently used flip flop-MRT here
@@ -222,4 +226,6 @@
 
 	bool mSsaoUseFullResolution;
+
+	float mMaxConvergence;
 };
 
Index: /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp
===================================================================
--- /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp	(revision 3315)
+++ /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp	(revision 3316)
@@ -286,4 +286,7 @@
 float viewCellsScaleFactor = 1.0f;
 
+float maxConvergence = 2000.0f;
+
+
 
 //////////////
@@ -377,5 +380,5 @@
 inline float KeyShift() { return keyForwardMotion * elapsedTime * 1e-3f; }
 
-void CreateAnimation();
+void CreateAnimation(const Vector3 &pos);
 
 SceneQuery *GetOrCreateSceneQuery();
@@ -390,4 +393,9 @@
 
 void LoadOrUpdatePVSs(const Vector3 &pos);
+
+void CreateNewInstance(SceneEntity *parent, const Vector3 &pos);
+
+
+/////////////
 
 string envFileName = "default.env";
@@ -626,7 +634,25 @@
 
 #if 1
-	const Vector3 sceneCenter(470.398f, 240.364f, 181.7f);
+
+#if 0
+	VertexArray positions;
+	positions.push_back(Vector3(478.398f, 268.0f, 181.3));
+	positions.push_back(Vector3(470.461, 268.543, 181.7));
+	positions.push_back(Vector3(499.648, 264.358, 181.7));
+	positions.push_back(Vector3(487.913, 285.162, 181.7));
+
+#else
+
+	VertexArray positions;
+	//positions.push_back(Vector3(6.07307, 8.20723, 6.7));
+	positions.push_back(Vector3(6.07307, 8.20723, 6.62));
+	positions.push_back(Vector3(-17.1935, 11.1687, 8.8781));
+	//positions.push_back(Vector3(499.648, 264.358, 181.7));
+	//positions.push_back(Vector3(487.913, 285.162, 181.7));
+
+#endif
+
 	//const Vector3 sceneCenter(470.398f, 240.364f, 180.3);
-	Matrix4x4 transl = TranslationMatrix(sceneCenter);
+	Matrix4x4 transl = TranslationMatrix(positions[0]);
 	
 	LoadModel("hbuddha.dem", dynamicObjects);
@@ -635,22 +661,10 @@
 	buddha->GetTransform()->SetMatrix(transl);
 
-	for (int i = 0; i < 10; ++ i)
-	{
-		SceneEntity *ent = new SceneEntity(*buddha);
-		resourceManager->AddSceneEntity(ent);
-
-		Vector3 offs = Vector3::ZERO();
-
-		offs.x = RandomValue(.0f, 50.0f);
-		offs.y = RandomValue(.0f, 50.0f);
-
-		Vector3 newPos = sceneCenter + offs;
-
-		transl = TranslationMatrix(newPos);
-		Transform3 *transform = resourceManager->CreateTransform(transl);
-
-		ent->SetTransform(transform);
-		dynamicObjects.push_back(ent);
-	}
+	
+	for (size_t i = 1; i < positions.size(); ++ i)
+	{
+		CreateNewInstance(buddha, positions[i]);
+	}
+
 #endif
 
@@ -706,5 +720,5 @@
 	preetham = new SkyPreetham(turbitity, skyDome);
 
-	CreateAnimation();
+	CreateAnimation(positions[0]);
 
 
@@ -1151,11 +1165,13 @@
 
 		//const float rotAngle = M_PI * 1e-3f;
-		const float rotAngle = 0.3f * M_PI / 180.0f;
-		//const float rotAngle = 1.0f * M_PI / 180.0f;
+		//const float rotAngle = 0.3f * M_PI / 180.0f;
+		const float rotAngle = 0.6f * M_PI / 180.0f;
 
 		Matrix4x4 rotMatrix = RotationZMatrix(rotAngle);
+		// hack: second buddha
 		dynamicObjects[1]->GetTransform()->MultMatrix(rotMatrix);
 
-		const float moveSpeed = 5e-3f;
+		//const float moveSpeed = 5e-3f;
+		const float moveSpeed = 1e-1f;
 		motionPath->Move(moveSpeed);
 	}
@@ -1412,4 +1428,5 @@
 		deferredShader->SetUseToneMapping(useHDR);
 		deferredShader->SetUseAntiAliasing(useAntiAliasing);
+		deferredShader->SetMaxConvergence(maxConvergence);
 
 
@@ -1582,4 +1599,14 @@
 		traverser->SetUseOptimization(useOptimization);
 		break;*/
+	case 'o':
+	case 'O':
+		if (maxConvergence > 100.0f)
+			maxConvergence = 1.0f;
+		else 
+			maxConvergence = 5000.0f;
+
+		cout << "max convergence: " << maxConvergence << endl;
+
+		break;
 	case 'l':
 	case 'L':
@@ -2595,35 +2622,34 @@
 
 
-void CreateAnimation()
-{
-	const float radius = 5.0f;
-	//const Vector3 center(480.398f, 268.364f, 181.3);
-	const Vector3 center(480.398f, 269.364f, 181.3);
+void CreateAnimation(const Vector3 &pos)
+{
+	//const float b = 5.0f; const float a = 1.5f;
+	const float a = 5.0f; const float b = 1.5f;
 
 	VertexArray vertices;
 
-	/*for (int i = 0; i < 360; ++ i)
-	{
-		float angle = (float)i * M_PI / 180.0f;
-
-		Vector3 offs = Vector3(cos(angle) * radius, sin(angle) * radius, 0);
+	for (int i = 0; i < 360; ++ i)
+	{
+		const float angle = (float)i * M_PI / 180.0f;
+
+		Vector3 offs = Vector3(cos(angle) * a, sin(angle) * b, 0);
+		vertices.push_back(pos + offs);
+	}
+
+	/*for (int i = 0; i < 5; ++ i)
+	{
+		Vector3 offs = Vector3(i, 0, 0);
+		vertices.push_back(center + offs);
+	}
+	
+	for (int i = 0; i < 5; ++ i)
+	{
+		Vector3 offs = Vector3(4 - i, 0, 0);
 		vertices.push_back(center + offs);
 	}*/
 
-	for (int i = 0; i < 5; ++ i)
-	{
-		Vector3 offs = Vector3(i, 0, 0);
-		vertices.push_back(center + offs);
-	}
-
-	
-	for (int i = 0; i < 5; ++ i)
-	{
-		Vector3 offs = Vector3(4 -i, 0, 0);
-		vertices.push_back(center + offs);
-	}
-
 	motionPath = new MotionPath(vertices);
 }
+
 
 /** This function returns the number of visible pixels of a
@@ -2805,2 +2831,16 @@
 	if (viewCellsTree) UpdatePvs(pos);
 }
+
+
+void CreateNewInstance(SceneEntity *parent, const Vector3 &pos)
+{
+	SceneEntity *ent = new SceneEntity(*parent);
+	resourceManager->AddSceneEntity(ent);
+
+	Matrix4x4 transl = TranslationMatrix(pos);
+	Transform3 *transform = resourceManager->CreateTransform(transl);
+
+	ent->SetTransform(transform);
+	dynamicObjects.push_back(ent);
+	//Debug << "positions: " << newPos << endl;
+}
Index: /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.cpp
===================================================================
--- /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.cpp	(revision 3313)
+++ /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.cpp	(revision 3316)
@@ -91,5 +91,9 @@
 /** Helper method that computes the view vectors in the corners of the current view frustum.
 */
-static void ComputeViewVectors(PerspectiveCamera *cam, Vector3 &bl, Vector3 &br, Vector3 &tl, Vector3 &tr)
+static void ComputeViewVectors(PerspectiveCamera *cam, 
+							   Vector3 &bl, 
+							   Vector3 &br, 
+							   Vector3 &tl, 
+							   Vector3 &tr)
 {
 	Vector3 ftl, ftr, fbl, fbr, ntl, ntr, nbl, nbr;
@@ -304,5 +308,6 @@
 mUseAntiAliasing(false),
 mUseDepthOfField(false),
-mSsaoUseFullResolution(ssaoUseFullResolution)
+mSsaoUseFullResolution(ssaoUseFullResolution),
+mMaxConvergence(2000.0f)
 {
 	///////////
@@ -460,8 +465,8 @@
 
 	string combineSsaoParams[] = 
-	{"colorsTex", "ssaoTex", "bl", "br", "tl", "tr", "res"};
+		{"colorsTex", "ssaoTex", "bl", "br", "tl", "tr", "res", "maxConvergence"};
 
 	//sCgCombineSsaoProgram->AddParameters(combineSsaoParams, 0, 13);
-	sCgCombineSsaoProgram->AddParameters(combineSsaoParams, 0, 7);
+	sCgCombineSsaoProgram->AddParameters(combineSsaoParams, 0, 8);
 
 	
@@ -469,7 +474,7 @@
 
 	string filterSsaoParams[] = 
-		{"colorsTex", "ssaoTex", "bl", "br", "tl", "tr", "res"};
-
-	sCgFilterSsaoProgram->AddParameters(filterSsaoParams, 0, 7);
+		{"colorsTex", "ssaoTex", "bl", "br", "tl", "tr", "res", "maxConvergence"};
+
+	sCgFilterSsaoProgram->AddParameters(filterSsaoParams, 0, 8);
 
 
@@ -980,4 +985,5 @@
 
 	sCgFilterSsaoProgram->SetValue2f(i ++, (float)mWidth, (float)mHeight);
+	sCgFilterSsaoProgram->SetValue1f(i ++, (float)mMaxConvergence);
 
 	DrawQuad(sCgFilterSsaoProgram);
@@ -1006,4 +1012,5 @@
 
 	sCgCombineSsaoProgram->SetValue2f(i ++, mWidth, mHeight);
+	sCgCombineSsaoProgram->SetValue1f(i ++, (float)mMaxConvergence);
 
 	DrawQuad(sCgCombineSsaoProgram);
@@ -1506,3 +1513,9 @@
 
 
+void DeferredRenderer::SetMaxConvergence(float c)
+{
+	mMaxConvergence = c;
+}
+
+
 } // namespace
