Index: /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaderenv.h
===================================================================
--- /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaderenv.h	(revision 2975)
+++ /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaderenv.h	(revision 2978)
@@ -47,3 +47,5 @@
 #define LOGLUM_RANGE 20.0f
 
+#define MAX_LOD_LEVEL 99
+
 #endif // __SHADERENV_H
Index: /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg
===================================================================
--- /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg	(revision 2977)
+++ /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg	(revision 2978)
@@ -87,5 +87,5 @@
 	//-- write out logaritmic luminance for tone mapping
 
-	float4 oldColor = tex2Dlod(colors, float4(IN.texCoord.xy, 0, 99));
+	float4 oldColor = tex2Dlod(colors, float4(IN.texCoord.xy, 0, MAX_LOD_LEVEL));
 
 	const float3 w = float3(0.299f, 0.587f, 0.114f);
@@ -157,5 +157,6 @@
 				  uniform sampler2D noiseTexture,
 				  uniform float2 samples[NUM_PCF_TABS],
-				  uniform float3 lightDir
+				  uniform float3 lightDir,
+				  uniform sampler2D oldColors
 				  )
 {
@@ -201,7 +202,10 @@
 	OUT.color = (emmisive > 1.5f) ? color: (ambient + diffuse) * color;
 
+
 	////////////
 	//-- write out logaritmic luminance for tone mapping
 
+	float4 oldColor = tex2Dlod(colors, float4(IN.texCoord.xy, 0, MAX_LOD_LEVEL));
+
 	const float3 w = float3(0.299f, 0.587f, 0.114f);
 
@@ -212,5 +216,8 @@
 	float logLumScaled = logLum * INV_LOGLUM_RANGE - logLumOffset;
 
-	OUT.color.w = logLumScaled;
+	if (oldColor.w > 0)
+		OUT.color.w = lerp(oldColor.w, logLumScaled, 0.2f);
+	else
+		OUT.color.w = logLumScaled;
 	
 	return OUT;
Index: /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg
===================================================================
--- /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg	(revision 2975)
+++ /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg	(revision 2978)
@@ -52,4 +52,7 @@
 	float numSamples = 0;
 
+	// avoid singularity of 
+	centerPosition.xyz += currentNormal * 1e-4f;
+
 	for (int i = 0; i < NUM_SAMPLES; ++ i) 
 	{
@@ -82,5 +85,4 @@
 		const float cos_angle = max(dot(direction_to_sample, currentNormal), 0.0f);
 
-		// distance between current position and sample position controls AO intensity.
 		const float distance_intensity = 
 			(SAMPLE_INTENSITY * DISTANCE_SCALE) / (DISTANCE_SCALE + length_to_sample * length_to_sample);
Index: /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp
===================================================================
--- /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp	(revision 2977)
+++ /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp	(revision 2978)
@@ -924,4 +924,18 @@
 	cgGLEnableProfile(RenderState::sCgFragmentProfile);
 	cgGLBindProgram(RenderState::sCgMrtFragmentProgram);
+
+	// draw to 3 color buffers
+	// a color, normal, and positions buffer
+	if (sCurrentMrtSet == 0)
+	{
+		DeferredRenderer::colorBufferIdx = 0;
+		glDrawBuffers(3, mrt);
+	}
+	else 
+	{
+		DeferredRenderer::colorBufferIdx = 3;
+		glDrawBuffers(3, mrt2);
+	}
+	sCurrentMrtSet = 1 - sCurrentMrtSet;
 }
 
@@ -1051,18 +1065,4 @@
 		InitDeferredRendering();
 		
-		// draw to 3 color buffers
-		// a color, normal, and positions buffer
-		if (sCurrentMrtSet == 0)
-		{
-			DeferredRenderer::colorBufferIdx = 0;
-			glDrawBuffers(3, mrt);
-		}
-		else 
-		{
-			DeferredRenderer::colorBufferIdx = 3;
-			glDrawBuffers(3, mrt2);
-		}
-		sCurrentMrtSet = 1 - sCurrentMrtSet;
-
 		glEnableClientState(GL_NORMAL_ARRAY);
 
@@ -2024,6 +2024,4 @@
 		InitDeferredRendering();
 
-		// draw to 3 color buffers
-		glDrawBuffers(3, mrt);
 		glClear(GL_COLOR_BUFFER_BIT);
 	}
Index: /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.cpp
===================================================================
--- /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.cpp	(revision 2977)
+++ /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.cpp	(revision 2978)
@@ -29,4 +29,5 @@
 static CGparameter sColorsTexDeferredParam;
 static CGparameter sOldColorsTexDeferredParam;
+static CGparameter sOldColorsTexShadowParam;
 
 static CGparameter sPositionsTexDeferredParam;
@@ -468,4 +469,6 @@
 		sLightDirShadowParam = cgGetNamedParameter(sCgDeferredShadowProgram, "lightDir");
 
+		sOldColorsTexShadowParam = cgGetNamedParameter(sCgDeferredShadowProgram, "oldColors");
+
 
 		PoissonDiscSampleGenerator2 poisson(NUM_PCF_TABS, 1.0f);
@@ -1056,4 +1059,6 @@
 	GLuint shadowTex = shadowMap->GetDepthTexture();
 
+	GLuint oldColorsTex = fbo->GetColorBuffer(3 - colorBufferIdx)->GetTexture();
+
 	Matrix4x4 shadowMatrix;
 	shadowMap->GetTextureMatrix(shadowMatrix);
@@ -1078,4 +1083,7 @@
 	cgGLSetTextureParameter(sShadowMapParam, shadowTex);
 	cgGLEnableTextureParameter(sShadowMapParam);
+
+	cgGLSetTextureParameter(sOldColorsTexShadowParam, oldColorsTex);
+	cgGLEnableTextureParameter(sOldColorsTexShadowParam);
 
 	cgGLSetParameter1f(sMaxDepthShadowParam, mScaleFactor);
@@ -1111,4 +1119,6 @@
 	cgGLDisableTextureParameter(sNormalsTexShadowParam);
 	cgGLDisableTextureParameter(sShadowMapParam);
+
+	cgGLDisableTextureParameter(sOldColorsTexShadowParam);
 
 	cgGLDisableTextureParameter(sNoiseTexShadowParam);
