Index: /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaderenv.h
===================================================================
--- /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaderenv.h	(revision 3198)
+++ /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaderenv.h	(revision 3199)
@@ -6,10 +6,10 @@
 //-- ssao + gi parameters
 
-#define NUM_SAMPLES 8
-//#define NUM_SAMPLES 16
+//#define NUM_SAMPLES 8
+#define NUM_SAMPLES 16
 //#define NUM_SAMPLES 24
 
-#define SAMPLE_INTENSITY 0.5f
-//#define SAMPLE_INTENSITY 1.0f
+//#define SAMPLE_INTENSITY 0.5f
+#define SAMPLE_INTENSITY 1.0f
 
 #define SAMPLE_RADIUS 8e-1f
Index: /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg
===================================================================
--- /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg	(revision 3198)
+++ /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg	(revision 3199)
@@ -280,6 +280,7 @@
 
 
-float4 PrepareSsao(fragment IN,
+pixel PrepareSsao(fragment IN,
 				   uniform sampler2D colorsTex,
+				   uniform sampler2D normalsTex,
 				   uniform sampler2D diffVals,
 				   uniform sampler2D oldTex,
@@ -291,6 +292,7 @@
 				   uniform float3 oldtr,
 				   uniform float3 oldEyePos
-				   ): COLOR0
+				   )
 {   
+	pixel pix;
 	float4 color = tex2Dlod(colorsTex, float4(IN.texCoord, 0, 0));
 	// store scaled view vector so wie don't have to normalize for e.g., ssao
@@ -298,4 +300,5 @@
 
 	const float4 difVec = tex2Dlod(diffVals, float4(IN.texCoord, 0, 0));
+	const float3 normal = normalize(tex2Dlod(normalsTex, float4(IN.texCoord, 0, 0)).xyz);
 
 	// do reprojection and filter out the pixels that are not save
@@ -311,7 +314,9 @@
 							  );
 
-	color.x = pValid;
-
-	return color;
+	pix.color = color;
+	pix.color.x = pValid;
+	pix.normal = normal;
+
+	return pix;
 }
 
Index: /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg
===================================================================
--- /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg	(revision 3198)
+++ /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg	(revision 3199)
@@ -205,5 +205,8 @@
 
 		float3 dirSample = samplePos - centerPosition;
-		const float lengthToSample = max(length(dirSample), 1e-6f);
+
+		const float sqrLen = max(SqrLen(dirSample), 1e-2f);
+		const float lengthToSample = sqrt(sqrLen);
+		//const float lengthToSample = max(length(dirSample), 1e-6f);
 
 		dirSample /= lengthToSample; // normalize
@@ -216,5 +219,6 @@
 		// the distance_scale offset is used to avoid singularity that occurs at global illumination when 
 		// the distance to a sample approaches zero
-		const float aoContrib = SAMPLE_INTENSITY / (DISTANCE_SCALE + lengthToSample * lengthToSample);
+		//const float aoContrib = SAMPLE_INTENSITY / (DISTANCE_SCALE + lengthToSample * lengthToSample);
+		const float aoContrib = SAMPLE_INTENSITY / sqrLen;
 		//const float aoContrib = (1.0f > lengthToSample) ? occlusionPower(9e-2f, DISTANCE_SCALE + lengthToSample): .0f;
 
@@ -397,6 +401,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 3198)
+++ /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.cpp	(revision 3199)
@@ -326,6 +326,11 @@
 	mDownSampleFbo = new FrameBufferObject(dsw, dsh, FrameBufferObject::DEPTH_NONE);
 	mDownSampleFbo->AddColorBuffer(ColorBufferObject::RGBA_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_LINEAR);
-
-	FrameBufferObject::InitBuffer(mDownSampleFbo, 0);
+// downsample buffer for the normal texture
+mDownSampleFbo->AddColorBuffer(ColorBufferObject::RGB_FLOAT_16, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_NEAREST);
+
+	for (int i = 0; i < 2; ++ i)
+	{
+		FrameBufferObject::InitBuffer(mDownSampleFbo, i);
+	}
 
 	mFBOs.push_back(mDownSampleFbo);
@@ -459,9 +464,9 @@
 	
 	string prepareSsaoParams[] = 
-		{"colorsTex", "diffVals", "oldTex", 
+		{"colorsTex", "normalsTex", "diffVals", "oldTex", 
 		 "oldEyePos", "modelViewProj", "oldModelViewProj",
 		 "oldbl", "oldbr", "oldtl", "oldtr"};
 
-	sCgPrepareSsaoProgram->AddParameters(prepareSsaoParams, 0, 10);
+	sCgPrepareSsaoProgram->AddParameters(prepareSsaoParams, 0, 11);
 
 
@@ -640,15 +645,19 @@
 
 
-void DeferredRenderer::ComputeSsao(FrameBufferObject *fbo, 
-								   float tempCohFactor)
+void DeferredRenderer::ComputeSsao(FrameBufferObject *fbo, float tempCohFactor)
 {
 	GLuint colorsTex, normalsTex, attribsTex;
 
 	if (0)
+	{
 		colorsTex = fbo->GetColorBuffer(colorBufferIdx)->GetTexture();
+		normalsTex = fbo->GetColorBuffer(1)->GetTexture();
+	}
 	else
+	{
+		normalsTex = mDownSampleFbo->GetColorBuffer(1)->GetTexture();
 		colorsTex = mDownSampleFbo->GetColorBuffer(0)->GetTexture();
-	
-	normalsTex = fbo->GetColorBuffer(1)->GetTexture();
+	}
+
 	attribsTex = fbo->GetColorBuffer(2)->GetTexture();
 
@@ -1024,4 +1033,5 @@
 {
 	GLuint colorsTex = fbo->GetColorBuffer(colorBufferIdx)->GetTexture();
+	GLuint normalsTex = fbo->GetColorBuffer(1)->GetTexture();
 	GLuint diffVals = fbo->GetColorBuffer(2)->GetTexture();
 	// flip flop between illumination buffers
@@ -1031,4 +1041,5 @@
 
 	sCgPrepareSsaoProgram->SetTexture(i ++, colorsTex);
+	sCgPrepareSsaoProgram->SetTexture(i ++, normalsTex);
 	sCgPrepareSsaoProgram->SetTexture(i ++, diffVals);
 	sCgPrepareSsaoProgram->SetTexture(i ++, oldTex);
@@ -1052,5 +1063,6 @@
 	mDownSampleFbo->Bind();
 
-	glDrawBuffers(1, mrt);
+// prepare downsampled color and normal texture for ssao
+	glDrawBuffers(2, mrt);
 
 	DrawQuad(sCgPrepareSsaoProgram);
