Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaderenv.h
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaderenv.h	(revision 3318)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaderenv.h	(revision 3319)
@@ -8,6 +8,6 @@
 //#define NUM_SAMPLES 8
 //#define NUM_SAMPLES 16
-#define NUM_SAMPLES 24
-//#define NUM_SAMPLES 48
+//#define NUM_SAMPLES 24
+#define NUM_SAMPLES 48
 
 //#define MIN_SAMPLES 48
@@ -61,5 +61,5 @@
 #define NUM_DOF_TABS 16
 
-//#define USE_GTX
+#define USE_GTX
 
 #define SSAO_FILTER_RADIUS 5
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg	(revision 3318)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg	(revision 3319)
@@ -50,8 +50,8 @@
 
 	float4 texelCenterConv;
-	const float2 offs(1.0f / res.x, 1.0f / res.y);
+	const float2 invRes = float2(1.0f / res.x, 1.0f / res.y);
 
 	// get position exactly between texel centers
-	float2 center = (floor(texCoord * res) + float2(.5f)) * offs;
+	float2 center = (floor(texCoord * res) + float2(.5f)) * texelCenterConv;
 	//center.x = (floor(texCoord.x * res.x - .5f) + 1.0f) / res.x;
 	//center.y = (floor(texCoord.y * res.y - .5f) + 1.0f) / res.y;
@@ -68,5 +68,6 @@
 	const float convergence = min(m1, m2);*/
 
-	const float convergence = tex2Dlod(tex, float4(center, 0, 0)).y;
+	//const float convergence = tex2Dlod(tex, float4(center, 0, 0)).y;
+	const float convergence = tex2Dlod(tex, float4(texCoord, 0, 0)).y;
 
 	return convergence;
@@ -143,6 +144,6 @@
 		w = min(min(w1, w2), min(w3, w4));*/
 		
-		w = ComputeConvergence(oldTex, oldTexCoords, float2(1024.0f, 768.0f));
-		//w = oldPixel.y;
+		//w = ComputeConvergence(oldTex, oldTexCoords, float2(1024.0f, 768.0f));
+		w = oldPixel.y;
 	}
 	else
@@ -306,7 +307,10 @@
 		float3 dirSample = samplePos - centerPosition;
 
-		//const float sqrLen = max(SqrLen(dirSample), 1e-2f);
+		//const float minDist = 9e-1f;
+		const float minDist = 1e-2f;
+
+		//const float sqrLen = max(SqrLen(dirSample), minDist);
 		//const float lengthToSample = sqrt(sqrLen);
-		const float lengthToSample =  max(length(dirSample), 1e-2f);
+		const float lengthToSample =  max(length(dirSample), minDist);
 
 		dirSample /= lengthToSample; // normalize
@@ -326,12 +330,18 @@
 		// only mark sample as invalid if in the last / current frame
 		// they possibly have any influence on the ao
+
 		const float changeFactor = sampleColor.y;
 		const float pixelValid = sampleColor.x;
 
+		// 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
-#if 0
+#if 1
 		const float tooFarAway = step(0.5f, lengthToSample - changeFactor);
-		validSamples = max(validSamples, (1.0f - tooFarAway) * pixelValid * step(-0.1f, cosAngle));
+		if (pixelValid < 2.0f)
+			validSamples = max(validSamples, pixelValid * (1.0f - tooFarAway) * step(-0.1f, cosAngle));
+		else
+			validSamples = max(validSamples, pixelValid);
 #else
 		validSamples = max(validSamples, pixelValid);
@@ -345,8 +355,9 @@
 			//break;
 			// if the pixel belongs to a static object and all the samples stay valid in the current frame
-			if (!isMovingObject && (validSamples < 1.0f)) break;
+			if (!isMovingObject && (validSamples < 1.0f) && (convergence > NUM_SAMPLES)) break;
 			// if the pixel belongs to a dynamic object but the #accumulated samples for this pixel is sufficiently high 
 			// (=> there was no discontinuity recently)
-			else if (isMovingObject && (convergence > NUM_SAMPLES * 5)) break;
+			//else if (isMovingObject && (convergence > SSAO_CONVERGENCE_THRESHOLD)) break;
+			//else if (isMovingObject && (convergence > NUM_SAMPLES * 5)) break;
 		}
 #endif
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/combineSsaoSep.cg
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/combineSsaoSep.cg	(revision 3318)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/combineSsaoSep.cg	(revision 3319)
@@ -59,5 +59,6 @@
 					float3 tl,
 					float3 tr,
-					float maxConvergence)
+					float maxConvergence,
+					float spatialWeight)
 {
 	float2 aoSample = tex2Dlod(ssaoTex, sampleTexCoord);
@@ -71,10 +72,12 @@
 	//float len = min(SqrLen(centerPos - samplePos), 1e2f);
 	float len = distance(centerPos, samplePos);
-	float spatialFactor = 1.0f / max(len, 1e-3f);
+	//float spatialFactor = 1.0f / max(len, 1e-3f);
+	float spatialFactor = 1.0f / max(spatialWeight + len, 1e-3f);
 
 	float convergenceFactor = min(aoSample.y + 1.0f, maxConvergence);
-	convergenceFactor *= convergenceFactor;
+	//convergenceFactor *= convergenceFactor;
 
 	// combine the weights
+	//float w = convergenceFactor * exp(1.0f + spatialFactor);
 	float w = convergenceFactor * spatialFactor;
 	//float w = spatialFactor;
@@ -98,5 +101,6 @@
 			   float2 xyStep,
 			   float convergence,
-			   float maxConvergence
+			   float maxConvergence,
+			   float spatialWeight
 			   )
 {
@@ -105,5 +109,5 @@
 	const float3 centerPos = ReconstructSamplePos(colorsTex, texCoord, bl, br, tl, tr);
 
-	const float scale = saturate((SSAO_CONVERGENCE_THRESHOLD - convergence) / SSAO_CONVERGENCE_THRESHOLD);
+	const float scale = 1.0f;//saturate((SSAO_CONVERGENCE_THRESHOLD - convergence) / SSAO_CONVERGENCE_THRESHOLD);
 	//const int radius = SSAO_FILTER_RADIUS * saturate((SSAO_CONVERGENCE_THRESHOLD - convergence) / SSAO_CONVERGENCE_THRESHOLD);
 	
@@ -112,5 +116,5 @@
 	{
 		float4 sampleTexCoord = float4(texCoord + i * xyStep * scale, .0f, .0f);
-		result += FilterSample(sampleTexCoord, ssaoTex, colorsTex, centerPos, bl, br, tl, tr, maxConvergence);
+		result += FilterSample(sampleTexCoord, ssaoTex, colorsTex, centerPos, bl, br, tl, tr, maxConvergence, spatialWeight);
 	}
 
@@ -151,5 +155,5 @@
 	{
 		// the filtered ssao value
-		OUT.illum_col.x = FilterXY(IN.texCoord, ssaoTex, colorsTex, bl, br, tl, tr, xyStep, convergence, maxConvergence);
+		OUT.illum_col.x = FilterXY(IN.texCoord, ssaoTex, colorsTex, bl, br, tl, tr, xyStep, convergence, maxConvergence, spatialWeight);
 	}
 
@@ -167,5 +171,6 @@
 						uniform float3 tr,
 						uniform float2 res,
-						uniform float maxConvergence
+						uniform float maxConvergence,
+						uniform float spatialWeight
 						)
 {
@@ -187,5 +192,5 @@
 	{
 		// the filtered ssao value
-		OUT.illum_col.x = FilterXY(IN.texCoord, ssaoTex, colorsTex, bl, br, tl, tr, xyStep, convergence, maxConvergence);
+		OUT.illum_col.x = FilterXY(IN.texCoord, ssaoTex, colorsTex, bl, br, tl, tr, xyStep, convergence, maxConvergence, spatialWeight);
 	}
 
@@ -205,5 +210,6 @@
 				  uniform float3 tr,
 				  uniform float2 res,
-				  uniform float maxConvergence
+				  uniform float maxConvergence,
+				  uniform float spatialWeight
 				  )
 {
@@ -226,12 +232,15 @@
 	{
 		// the filtered ssao value
-		ao.x = FilterXY(IN.texCoord, ssaoTex, colorsTex, bl, br, tl, tr, xyStep, convergence, maxConvergence);
-	}
+		ao.x = FilterXY(IN.texCoord, ssaoTex, colorsTex, bl, br, tl, tr, xyStep, convergence, maxConvergence, spatialWeight);
+	}
+
+	//const float minAO = 2e-2f;
+	const float minAO = 1e-3f;
 
 	// just apply ssao if we are not in the sky
 	if (depth < DEPTH_THRESHOLD)
 	{
-		//OUT.illum_col.xyz = col.xyz * max(1e-3f, 1.0f - ao.x);
-		OUT.illum_col.xyz = max(1e-3f, 1.0f - ao.x);
+		OUT.illum_col.xyz = col.xyz * max(minAO, 1.0f - ao.x);
+		//OUT.illum_col.xyz = max(minAO, 1.0f - ao.x);
 	}
 	else
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.h
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.h	(revision 3316)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.h	(revision 3319)
@@ -99,4 +99,5 @@
 	void SetMaxConvergence(float c);
 
+	void SetSpatialWeight(float w);
 
 	// hack: store the color buffer idx for the currently used flip flop-MRT here
@@ -228,4 +229,5 @@
 
 	float mMaxConvergence;
+	float mSpatialWeight;
 };
 
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp	(revision 3318)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp	(revision 3319)
@@ -287,5 +287,5 @@
 
 float maxConvergence = 2000.0f;
-
+float spatialWeight = 0.0001f;
 
 
@@ -635,5 +635,5 @@
 #if 1
 
-#if 1
+#if 0
 	// vienna positions
 	VertexArray positions;
@@ -1431,4 +1431,5 @@
 		deferredShader->SetUseAntiAliasing(useAntiAliasing);
 		deferredShader->SetMaxConvergence(maxConvergence);
+		deferredShader->SetSpatialWeight(spatialWeight);
 
 
@@ -1602,4 +1603,12 @@
 		break;*/
 	case 'o':
+			spatialWeight /= 2.0f;
+			cout << "spatialWeight: " << spatialWeight << endl;
+			break;
+	case 'O':
+			spatialWeight *= 2.0f;
+			cout << "spatialWeight: " << spatialWeight << endl;
+			break;
+	/*case 'o':
 	case 'O':
 		if (maxConvergence > 100.0f)
@@ -1609,5 +1618,5 @@
 
 		cout << "max convergence: " << maxConvergence << endl;
-
+*/
 		break;
 	case 'l':
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.cpp	(revision 3316)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.cpp	(revision 3319)
@@ -309,5 +309,6 @@
 mUseDepthOfField(false),
 mSsaoUseFullResolution(ssaoUseFullResolution),
-mMaxConvergence(2000.0f)
+mMaxConvergence(2000.0f),
+mSpatialWeight(.0f)
 {
 	///////////
@@ -465,8 +466,9 @@
 
 	string combineSsaoParams[] = 
-		{"colorsTex", "ssaoTex", "bl", "br", "tl", "tr", "res", "maxConvergence"};
+		//{"colorsTex", "ssaoTex", "bl", "br", "tl", "tr", "res", "maxConvergence"};
+		{"colorsTex", "ssaoTex", "bl", "br", "tl", "tr", "res", "maxConvergence", "spatialWeight"};
 
 	//sCgCombineSsaoProgram->AddParameters(combineSsaoParams, 0, 13);
-	sCgCombineSsaoProgram->AddParameters(combineSsaoParams, 0, 8);
+	sCgCombineSsaoProgram->AddParameters(combineSsaoParams, 0, 9);
 
 	
@@ -474,7 +476,7 @@
 
 	string filterSsaoParams[] = 
-		{"colorsTex", "ssaoTex", "bl", "br", "tl", "tr", "res", "maxConvergence"};
-
-	sCgFilterSsaoProgram->AddParameters(filterSsaoParams, 0, 8);
+		{"colorsTex", "ssaoTex", "bl", "br", "tl", "tr", "res", "maxConvergence", "spatialWeight"};
+
+	sCgFilterSsaoProgram->AddParameters(filterSsaoParams, 0, 9);
 
 
@@ -985,5 +987,6 @@
 
 	sCgFilterSsaoProgram->SetValue2f(i ++, (float)mWidth, (float)mHeight);
-	sCgFilterSsaoProgram->SetValue1f(i ++, (float)mMaxConvergence);
+	sCgFilterSsaoProgram->SetValue1f(i ++, mMaxConvergence);
+	sCgFilterSsaoProgram->SetValue1f(i ++, mSpatialWeight);
 
 	DrawQuad(sCgFilterSsaoProgram);
@@ -1012,5 +1015,6 @@
 
 	sCgCombineSsaoProgram->SetValue2f(i ++, mWidth, mHeight);
-	sCgCombineSsaoProgram->SetValue1f(i ++, (float)mMaxConvergence);
+	sCgCombineSsaoProgram->SetValue1f(i ++, mMaxConvergence);
+	sCgCombineSsaoProgram->SetValue1f(i ++, mSpatialWeight);
 
 	DrawQuad(sCgCombineSsaoProgram);
@@ -1519,3 +1523,9 @@
 
 
+void DeferredRenderer::SetSpatialWeight(float w)
+{
+	mSpatialWeight = w;
+}
+
+
 } // namespace
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/Converter/ObjConverter.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/Converter/ObjConverter.cpp	(revision 3305)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/Converter/ObjConverter.cpp	(revision 3319)
@@ -107,5 +107,5 @@
 
 
-			if (!normals.empty())
+			if (0)//!normals.empty())
 			{
 				faceNormals.push_back(normals[nIndices[idx1]]);
@@ -358,8 +358,10 @@
 		str.write(reinterpret_cast<char *>(geom->mTexcoords), sizeof(float) * texCoordCount * 2);
 	
-
+/*
+	//////////////
+	//-- hack: a default material
 	///////
 	//-- texture
-/*
+
 #ifdef USE_TEXTURE
 	int texId = 0;
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/sibenik.env
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/sibenik.env	(revision 3313)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/sibenik.env	(revision 3319)
@@ -101,5 +101,6 @@
 ssaoUseFullResolution=1
 # ssao kernel radius
-ssaoKernelRadius=2.5f
+#ssaoKernelRadius=2.5f
+ssaoKernelRadius=1.28f
 # ssao sample intensity
 #ssaoSampleIntensity=0.2f
