Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaderenv.h
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaderenv.h	(revision 3194)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaderenv.h	(revision 3195)
@@ -7,16 +7,16 @@
 
 //#define NUM_SAMPLES 8
-#define NUM_SAMPLES 16
-//#define NUM_SAMPLES 24
+//#define NUM_SAMPLES 16
+#define NUM_SAMPLES 24
 
 // for quadratic falloff
-//#define SAMPLE_INTENSITY 0.5f
-#define SAMPLE_INTENSITY 0.5f
+//#define SAMPLE_INTENSITY 0.9f
+#define SAMPLE_INTENSITY 2.0f
 
 //#define SAMPLE_INTENSITY 0.075f
 //#define SAMPLE_INTENSITY 0.2f
 
-//#define SAMPLE_RADIUS 8e-1f
 #define SAMPLE_RADIUS 8e-1f
+//#define SAMPLE_RADIUS 15e-1f
 
 //#define DISTANCE_SCALE 1e-1f
@@ -30,6 +30,6 @@
 //#define NUM_SSAO_FILTERSAMPLES 80
 #define NUM_SSAO_FILTER_SAMPLES 16
-#define NUM_SSAO_FILTER_WIDTH 12.0f
-#define SSAO_CONVERGENCE_WEIGHT 200.0f
+#define SSAO_FILTER_WIDTH 12.0f
+#define SSAO_CONVERGENCE_WEIGHT 300.0f
 
 
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg	(revision 3193)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg	(revision 3195)
@@ -64,6 +64,7 @@
 	OUT.color = col;
 	// store scaled view vector so wie don't have to normalize for e.g., ssao
-	OUT.color.w = color.w;// / length(IN.view);
-	//OUT.color = color;
+	//OUT.color.w = color.w / length(IN.view);
+	OUT.color.w = color.w;
+
 	return OUT;
 }
@@ -164,5 +165,4 @@
 
 		float shadowTerm = CalcShadowTerm(IN, shadowMap, sampleWidth, lightSpacePos.xy, lightSpacePos.z, samples, weights, noiseTex);
-	
 		diffuse *= shadowTerm;
 	}
@@ -296,5 +296,6 @@
 	pixel pix;
 
-	const float3 normal = normalize(tex2Dlod(normalsTex, float4(IN.texCoord, 0 ,0)).xyz);
+	//const float3 normal = normalize(tex2Dlod(normalsTex, float4(IN.texCoord, 0 ,0)).xyz);
+	const float3 normal = tex2Dlod(normalsTex, float4(IN.texCoord, 0 ,0)).xyz;
 	const float3 difVec = tex2Dlod(diffVals, float4(IN.texCoord, 0 ,0)).xyz;
 
@@ -302,7 +303,17 @@
 	float4 color = tex2Dlod(colorsTex, float4(IN.texCoord, 0, 0));
 
+	
+	float4 dummy;
+	const float xoffs = .5f / 1024.0f;
+	const float yoffs = .5f / 768.0f;
+
+	dummy.x = tex2Dlod(colorsTex, float4(IN.texCoord + float2(xoffs, 0), 0, 0)).w;
+	dummy.y = tex2Dlod(colorsTex, float4(IN.texCoord + float2(0, yoffs), 0, 0)).w;
+	dummy.z = tex2Dlod(colorsTex, float4(IN.texCoord + float2(-xoffs, 0), 0, 0)).w;
+	dummy.w = tex2Dlod(colorsTex, float4(IN.texCoord + float2(0, -yoffs), 0, 0)).w;
+	color.w =  max(max(dummy.x, dummy.y), max(dummy.z, dummy.w));
+	
 	// store scaled view vector so wie don't have to normalize for e.g., ssao
 	color.w /= length(IN.view);
-	//color.w = 1;
 
 	// do reprojection and filter out the pixels that are not save
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/combineSsao.cg
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/combineSsao.cg	(revision 3193)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/combineSsao.cg	(revision 3195)
@@ -68,5 +68,5 @@
 		normalFactor = max(dot(sampleNorm, centerNormal), 1e-3f);
 		//convergenceFactor = min(100.0f, aoSample.y);
-		convergenceFactor = aoSample.y;
+		convergenceFactor = aoSample.y + 1.0f;
 
 		// combine the weights
@@ -133,15 +133,16 @@
 		//samplePos = ReconstructSamplePos(ssaoTex, sampleTexCoord.xy, bl, br, tl, tr);
 
-		len = min(SqrLen(centerPos - samplePos), 1e3f);
+		len = min(SqrLen(centerPos - samplePos), 1e2f);
 
 		spatialFactor = 1.0f / max(len, 1e-3f);
 
-		normalFactor = max(step(.01f, dot(sampleNorm, centerNormal)), 1e-3f);
+		//normalFactor = max(step(.0f, dot(sampleNorm, centerNormal)), 1e-2f);
 		//normalFactor = max(dot(sampleNorm, samplePos), 1e-3f);
-		convergenceFactor = min(convergenceThresh, aoSample.y + 1);
+		convergenceFactor = aoSample.y + 1.0f;
+		//convergenceFactor = max(step(0.5f + NUM_SAMPLES, aoSample.y), 1e-2f);
 		//convergenceFactor = aoSample.y;
 
 		// combine the weights
-		w = convergenceFactor * spatialFactor * normalFactor;
+		w = convergenceFactor * convergenceFactor * spatialFactor;// * normalFactor;
 		//w = spatialFactor * normalFactor;
 
@@ -177,6 +178,22 @@
 	float4 ao = tex2Dlod(ssaoTex, float4(IN.texCoord, 0, 0));
 
+	float4 dummy;
+	const float xoffs = .5f / 1024.0f;
+	const float yoffs = .5f / 768.0f;
+
+	dummy.x = tex2Dlod(ssaoTex, float4(IN.texCoord + float2(xoffs, 0), 0, 0)).y;
+	dummy.y = tex2Dlod(ssaoTex, float4(IN.texCoord + float2(0, yoffs), 0, 0)).y;
+	dummy.z = tex2Dlod(ssaoTex, float4(IN.texCoord + float2(-xoffs, 0), 0, 0)).y;
+	dummy.w = tex2Dlod(ssaoTex, float4(IN.texCoord + float2(0, -yoffs), 0, 0)).y;
+
+	const float convergence = min(min(dummy.x, dummy.y), min(dummy.z, dummy.w));
+	//const float convergence = max(max(dummy.x, dummy.y), max(dummy.z, dummy.w));
+	//const float convergence = ao.y;
+
+	// filter reaches size 1 after thres samples
+	const float thres = 500.0f; 
+
 	// filter up to a certain convergance value and leave out background (sky) by checking depth
-	if ((ao.y < 500.0f) && (col.w < 1e10f))
+	if ((convergence < thres) && (col.w < 1e10f))
 	//if (col.w < 1e10f)
 	{
@@ -185,8 +202,8 @@
 		const float distanceScale = 1.0f;
 
-		const float convergence = ao.y + 1;
-		const float convergenceScale = SSAO_CONVERGENCE_WEIGHT / (convergence + SSAO_CONVERGENCE_WEIGHT);
-
-		const float scale = NUM_SSAO_FILTER_WIDTH * convergenceScale * distanceScale;
+		const float convergenceWeight = thres / (SSAO_FILTER_WIDTH - 1.0f);
+		const float convergenceScale = convergenceWeight / (convergence + convergenceWeight);
+
+		const float scale = SSAO_FILTER_WIDTH * convergenceScale * distanceScale;
 
 		// the filtered ssao value
@@ -199,6 +216,7 @@
 		OUT.illum_col.xyz = col.xyz;
 
-	//OUT.illum_col.xyz = float3(ao.x, ao.x, ao.x);
-	//OUT.illum_col.xyz = float3(0, clamp(1.0f - ao.y * 1e-2f, 0, 1), 1);
+	OUT.illum_col.xyz = float3(ao.x, ao.x, ao.x);
+	//OUT.illum_col.xyz = float3(0, clamp(1.0f - ao.y * 1e-3f, 0, 1), 1);
+	//OUT.illum_col.xyz = float3(0, 1.0f - step(0.5f + NUM_SAMPLES, convergence), 1);
 	OUT.illum_col.w = col.w;
 
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/normalMapping.cg
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/normalMapping.cg	(revision 3168)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/normalMapping.cg	(revision 3195)
@@ -125,8 +125,9 @@
 	float3x3 tangToWorldTrafo = transpose(float3x3(tangent, bitangent, normal));
 	
-	const float3 tangentSpaceNorm = tex2Dlod(normalMap, float4(IN.texCoord.xy, 0, 0)).xyz * 2.0f - float3(1.0f);
+	//const float3 tangentSpaceNorm = tex2Dlod(normalMap, float4(IN.texCoord.xy, 0, 0)).xyz * 2.0f - float3(1.0f);
+	const float3 tangentSpaceNorm = tex2Dlod(normalMap, float4(IN.texCoord.xy, 0, 0)).xyz;
+	pix.normal = mul(tangToWorldTrafo, tangentSpaceNorm);
+	//pix.normal = tangentSpaceNorm;
 	
-	pix.normal = normalize(mul(tangToWorldTrafo, tangentSpaceNorm));
-		
 	return pix;
 }
@@ -171,5 +172,6 @@
 	float3x3 tangToWorldTrafo = transpose(float3x3(IN.tangent.xyz, IN.bitangent.xyz, IN.normal.xyz));
 	const float3 tangentSpaceNorm = tex2Dlod(normalMap, float4(IN.texCoord.xy, 0, 0)).xyz;
-	pix.normal = mul(tangToWorldTrafo, tangentSpaceNorm);
+	//pix.normal = mul(tangToWorldTrafo, tangentSpaceNorm);
+	pix.normal = tangentSpaceNorm;
 
 	return pix;
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg	(revision 3193)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg	(revision 3195)
@@ -393,6 +393,6 @@
 	if (eyeSpaceDepth < 1e10f)
 	{
-		//ao = ssao(IN, colors, noiseTex, samples, normal, eyeSpacePos.xyz, scaleFactor, bl, br, tl, tr, normalize(viewDir), oldWeight);
-		ao = ssao2(IN, colors, noiseTex, samples, normal, eyeSpacePos.xyz, scaleFactor, bl, br, tl, tr, normalize(viewDir), normals);
+		ao = ssao(IN, colors, noiseTex, samples, normal, eyeSpacePos.xyz, scaleFactor, bl, br, tl, tr, normalize(viewDir), oldWeight);
+		//ao = ssao2(IN, colors, noiseTex, samples, normal, eyeSpacePos.xyz, scaleFactor, bl, br, tl, tr, normalize(viewDir), normals);
 	}
 	else
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.cpp	(revision 3194)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.cpp	(revision 3195)
@@ -544,5 +544,5 @@
 	// multisampling is difficult / costly with deferred shading
 	// at least do some edge blurring 
-	if (useAntiAliasing) AntiAliasing(fbo, light);// else 
+	if (useAntiAliasing) AntiAliasing(fbo, light); else 
 	Output(fbo); // just output the latest buffer
 
@@ -729,7 +729,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
@@ -954,5 +954,4 @@
 	whiteLum = log(WHITE_LUMINANCE);
 	
-
 	////////////////////
 	//-- linear interpolate brightness key depending on the current sun position
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/VboFormatConverter/VboFormatConverter.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/VboFormatConverter/VboFormatConverter.cpp	(revision 3193)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/VboFormatConverter/VboFormatConverter.cpp	(revision 3195)
@@ -175,5 +175,5 @@
 		ambient.x = ambient.y = ambient.z = 0.2f;
 		//diffuse.x = 0.7f; diffuse.y = 0.4f; diffuse.z = 0.2f;
-		diffuse.x = 0.8f; diffuse.y = 0.8f; diffuse.z = 0.4f;
+		diffuse.x = 0.4f; diffuse.y = 0.6f; diffuse.z = 0.6f;
 		//diffuse.x = diffuse.y = diffuse.z = 1.0f;
 		spec.x = spec.y = spec.z = .0f;
