Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/combineSsao.cg
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/combineSsao.cg	(revision 3109)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/combineSsao.cg	(revision 3120)
@@ -36,4 +36,25 @@
 
 
+float Filter(float2 texCoord, 
+			 uniform sampler2D ssaoTex,
+			 uniform float2 filterOffs[NUM_SSAO_FILTERSAMPLES],
+			 uniform float filterWeights[NUM_SSAO_FILTERSAMPLES],
+			 float scale)
+{
+	float average = .0f;
+	float w = .0f;
+
+	for (int i = 0; i < NUM_SSAO_FILTERSAMPLES; ++ i)
+	{	
+		average += filterWeights[i] * tex2Dlod(ssaoTex, float4(texCoord + filterOffs[i] * scale, 0, 0)).x;
+		w += filterWeights[i];
+	}
+
+	average *= 1.0f / (float)w;
+
+	return average;
+}
+
+
 float BilateralFilter(float2 texCoord,
 					  float4 ao,
@@ -41,10 +62,11 @@
 					  uniform sampler2D normalsTex,
 					  uniform float2 filterOffs[NUM_SSAO_FILTERSAMPLES],
-					  uniform float filterWeights[NUM_SSAO_FILTERSAMPLES])
+					  uniform float filterWeights[NUM_SSAO_FILTERSAMPLES],
+					  float scale)
 {
 	float average = .0f;
 	float total_w = .0f;
 
-	//const float eyeSpaceDepth = ao.w;
+	const float eyeSpaceDepth = ao.w;
 	const float3 norm = normalize(tex2Dlod(normalsTex, float4(texCoord, 0, 0)).xyz);
 
@@ -52,22 +74,23 @@
 	float3 sampleNorm;
 	float w;
+	float4 offs;
+	float depthFactor;
 
 	for (int i = 0; i < NUM_SSAO_FILTERSAMPLES; ++ i)
 	{
-		float4 offs = float4(texCoord + filterOffs[i], 0, 0);
+		offs = float4(texCoord + filterOffs[i] * scale, 0, 0);
 		aoSample = tex2Dlod(ssaoTex, offs);
-		//aoSample = tex2D(ssaoTex, texCoord + filterOffs[i]);
-		//float sampleEyeSpaceDepth = aoSample.w;
-		//factor = abs(eyeSpaceDepth - sampleEyeSpaceDepth) / eyeSpaceDepth;
+		
 		sampleNorm = normalize(tex2Dlod(normalsTex, offs).xyz);
+		depthFactor = clamp(1.0f - abs(1.0f - eyeSpaceDepth / aoSample.w), 1e-3f, 1.0f);
 		//sampleNorm = tex2Dlod(normalsTex, offs).xyz;
 
-		w = filterWeights[i] * max(dot(sampleNorm, norm), .0f);
+		w = filterWeights[i] * max(dot(sampleNorm, norm), .0f) * depthFactor;
 
-		average += w * aoSample.x;
+		average += aoSample.x * w;
 		total_w += w;
 	}
 
-	average *= 1.0f / max(total_w, 1e-5f);
+	average *= 1.0f / max(total_w, 1e-6f);
 
 	return average;
@@ -88,12 +111,17 @@
 	float4 ao = tex2Dlod(ssaoTex, float4(IN.texCoord, 0, 0));
 
-	//if (ao.y < 10.0f) ao.x = Filter(IN.texCoord, ssaoTex, filterOffs, filterWeights);
-	//if (ao.y < 10.0f) ao.x = BilateralFilter(IN.texCoord, ao, ssaoTex, normalsTex, filterOffs, filterWeights);
+	if ((ao.y < 60.0f) && (col.w < 1e10f))
+	{
+		const static float scaleFactor = 10.0f;
 
-	//OUT.illum_col = col * ao.x;
-	//OUT.illum_col = float4(ao.x, ao.y, ao.z, col.w);
-	OUT.illum_col = float4(ao.x, ao.x, ao.x, col.w);
+		//ao.x = Filter(IN.texCoord, ssaoTex, filterOffs, filterWeights);
+		//ao.x = Filter(IN.texCoord, ssaoTex, filterOffs, filterWeights, 1.0f / (1.0f + ao.y));
+		ao.x = BilateralFilter(IN.texCoord, ao, ssaoTex, normalsTex, filterOffs, filterWeights, scaleFactor / (scaleFactor + ao.y));
+		//ao.x = BilateralFilter(IN.texCoord, ao, ssaoTex, normalsTex, filterOffs, filterWeights, 1.0f);
+	}
+
+	OUT.illum_col = col * ao.x;
+	//OUT.illum_col = float4(ao.x, ao.x, ao.x, col.w);
 	//OUT.illum_col.xyz = float3(1.0f - ao.x, 1.0f - ao.y * 1e-2f, 1);
-	//OUT.illum_col.xyz = float3(1.0f - ao.x, ao.y, 0);
 	OUT.illum_col.w = col.w;
 
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg	(revision 3119)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg	(revision 3120)
@@ -189,5 +189,5 @@
 	//float overallDepth = 0;
 	const float squaredLen = diffVec.x * diffVec.x + diffVec.y * diffVec.y + diffVec.z * diffVec.z;
-
+#if 1
 	if (squaredLen < 1e-8f) // object not dynamic
 	{
@@ -210,5 +210,5 @@
 		}
 	}
-
+#endif
 	const float oldWeight = clamp(oldPixel.y, .0f, temporalCoherence);
 	float newWeight;
@@ -220,5 +220,5 @@
 		// if visibility changed in the surrounding area we have to recompute
 		//&& (oldNumSamples > 0.8f * newNumSamples)
-		&& (notValid < 1.0f)
+		//&& (notValid < 1.0f)
 		)
 	{
@@ -226,5 +226,5 @@
 		newWeight = oldWeight + 1.0f;
 		illum_col.x = (ao.x + oldPixel.x * oldWeight) / newWeight;
-		//if (notValid > 1.0f) newWeight = 2.0f;
+		if (notValid > 1.0f) newWeight = 2.0f;
 	}
 	else
@@ -292,4 +292,5 @@
 
 		//if ((texcoord.x <= 1.0f) && (texcoord.x >= 0.0f) && (texcoord.y <= 1.0f) && (texcoord.y >= 0.0f)) ++ numSamples;
+
 		const float3 samplePos = ReconstructSamplePos(colors, texcoord, bl, br, tl, tr);
 
@@ -378,4 +379,5 @@
 	float3 diffVec = tex2Dlod(attribsTex, float4(IN.texCoord, 0, 0)).xyz;
 
+
 	/////////////////
 	//-- compute temporal reprojection
@@ -393,54 +395,4 @@
 									  diffVec);
 
-	//OUT.illum_col.xyz = id;
-	//OUT.illum_col.xyz = normal * 0.5f + 0.5f;
 	return OUT;
 }
-
-
-float Filter(float2 texCoord, 
-			 uniform sampler2D ssaoTex,
-			 uniform float2 filterOffs[NUM_SSAO_FILTERSAMPLES],
-			 uniform float filterWeights[NUM_SSAO_FILTERSAMPLES],
-			 float scale)
-{
-	float average = .0f;
-	float w = .0f;
-
-	for (int i = 0; i < NUM_SSAO_FILTERSAMPLES; ++ i)
-	{	
-		average += filterWeights[i] * tex2Dlod(ssaoTex, float4(texCoord + filterOffs[i] * scale * 2, 0, 0)).x;
-		w += filterWeights[i];
-	}
-
-	average *= 1.0f / (float)w;
-
-	return average;
-}
-
-
-pixel combine(fragment IN, 
-			  uniform sampler2D colorsTex,
-			  uniform sampler2D ssaoTex,
-			  uniform float2 filterOffs[NUM_SSAO_FILTERSAMPLES],
-			  uniform float filterWeights[NUM_SSAO_FILTERSAMPLES]
-			  )
-{
-	pixel OUT;
-
-	const float4 col = tex2Dlod(colorsTex, float4(IN.texCoord, 0, 0));
-	float4 ao = tex2Dlod(ssaoTex, float4(IN.texCoord, 0, 0));
-
-	//if ((ao.y < 10.0f) && (col.w < 1e10f))
-	//	ao.x = Filter(IN.texCoord, ssaoTex, filterOffs, filterWeights, 1.0f / (1.0f + ao.y));//ao.z);
-
-	OUT.illum_col = col * ao.x;
-	//OUT.illum_col = float4(ao.y, ao.y, ao.y, col.w);
-	//OUT.illum_col = float4(ao.x, ao.y, ao.z, col.w);
-	//OUT.illum_col = float4(ao.x, 0, 0, col.w);
-	//OUT.illum_col.xyz = float3(1.0f - ao.x, 1.0f - ao.y * 1e-2f, 1);
-	//OUT.illum_col.xyz = float3(1.0f - ao.x, ao.y, 0);
-	OUT.illum_col.w = col.w;
-
-	return OUT;
-}
