Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg	(revision 2868)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg	(revision 2869)
@@ -181,4 +181,42 @@
 	return float4(total_color, 1.0f - total_ao);
 }
+
+
+float ComputeSmoothedColor(float4 centerPosition, 
+						   uniform sampler2D oldTex,
+						   uniform float maxDepth,  
+						   uniform float expFactor,
+						   const uniform float4x4 oldModelViewProj,
+						   float4 currentCol
+						   )
+{
+	float4 realPos = centerPosition * maxDepth;
+	realPos.w = 1.0f;
+
+	float4 oldPos = mul(oldModelViewProj, realPos);
+
+	float newDepth = oldPos.z / oldPos.w;
+
+	float2 tex = (oldPos.xy / oldPos.w) * 0.5f + 0.5f;
+	float4 oldCol = tex2D(oldTex, tex);
+
+	float oldDepth = oldCol.w;
+	float depthDif = 1.0f - newDepth / oldDepth;
+
+	float4 col;
+
+	if ((tex.x >= 0.0f) && (tex.x < 1.0f) && 
+		(tex.y >= 0.0f) && (tex.y < 1.0f) && 
+		(abs(depthDif)  < 1e-4f))
+	{
+		col = currentCol * expFactor + oldCol * float4(1.0f - expFactor);
+	}
+	else
+	{
+		col = currentCol;
+	}
+
+	return col;
+ }
 
 
@@ -217,5 +255,5 @@
 
 	float ao = ssao(IN, positions, noiseTexture, samples, normal.xyz, viewDir, noiseMultiplier, centerPosition);
-	float4 attenuated_color = ao * col;
+	//float4 attenuated_color = ao * col;
 	//float4 attenuated_color = ao;
 
@@ -223,29 +261,6 @@
 	//float4 attenuated_color = ao * col + new_col;
 	
-	const float x = expFactor;
-
-	float4 dummy = centerPosition * maxDepth;
-	dummy.w = 1.0f;
-
-	float4 oldPos = mul(oldModelViewProj, dummy);
-
-	float newDepth = oldPos.z / oldPos.w;
- 
-	float2 tex = (oldPos.xy / oldPos.w) * 0.5f + 0.5f;
-	float4 col1 = tex2D(oldTex, tex);
-
-	float oldDepth = col1.w;
-	float depthDif = 1.0f - newDepth / oldDepth;
-
-	if ((tex.x >= 0.0f) && (tex.x < 1.0f) && 
-		(tex.y >= 0.0f) && (tex.y < 1.0f) && 
-		(abs(depthDif)  < 1e-4f))
-	{
-		OUT.color = attenuated_color * expFactor + col1 * float4(1.0f - expFactor);
-	}
-	else
-	{
-		OUT.color = attenuated_color;
-	}
+	// compute temporally smoothed color
+	OUT.color = ComputeSmoothedColor(centerPosition, oldTex, maxDepth, expFactor, oldModelViewProj, float4(ao));
 
 	//OUT.color.xyz = viewDir;
@@ -256,2 +271,19 @@
 	return OUT;
 }
+
+
+pixel combined(fragment IN, 
+			   uniform sampler2D colors,
+			   uniform sampler2D ssaoTex
+		   )
+{
+	pixel OUT;
+
+	float4 col = tex2D(colors, IN.texCoord.xy);
+	float4 ao = tex2D(ssaoTex, IN.texCoord.xy);
+
+	OUT.color = float4(1,0,0,0);
+	OUT.color = col * ao;
+
+	return OUT;
+}
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SsaoShader.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SsaoShader.cpp	(revision 2868)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SsaoShader.cpp	(revision 2869)
@@ -21,4 +21,8 @@
 static CGprogram sCgDeferredProgram2 = NULL;
 static CGprogram sCgAntiAliasingProgram = NULL;
+static CGprogram sCgCombineProgram = NULL;
+
+static CGparameter sColorsTexCombineParam;
+static CGparameter sSsaoTexCombineParam;
 
 static CGparameter sColorsTexDeferredParam;
@@ -91,5 +95,8 @@
 	// the diffuse color buffer
 	mFbo3->AddColorBuffer(ColorBufferObject::BUFFER_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_LINEAR, false);
-	
+		
+	mFbo4 = new FrameBufferObject(w, h, FrameBufferObject::DEPTH_NONE);
+	// the diffuse color buffer
+	mFbo4->AddColorBuffer(ColorBufferObject::BUFFER_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_LINEAR, false);
 
 	// create noise texture for ssao
@@ -131,4 +138,24 @@
 	else
 		cerr << "deferred program failed to load" << endl;
+
+
+	sCgCombineProgram = 
+		cgCreateProgramFromFile(context, 
+								CG_SOURCE,
+								"src/shaders/ssao.cg", 
+								RenderState::sCgFragmentProfile,
+								"combined",
+								NULL);
+
+	if (sCgCombineProgram != NULL)
+	{
+		cgGLLoadProgram(sCgCombineProgram);
+
+		// we need size of texture for scaling
+		sColorsTexCombineParam = cgGetNamedParameter(sCgCombineProgram, "colors");  
+		sSsaoTexCombineParam = cgGetNamedParameter(sCgCombineProgram, "ssaoTex"); 
+	}
+	else
+		cerr << "combined program failed to load" << endl;
 
 
@@ -230,4 +257,5 @@
 	FirstPass(fbo);
 	ComputeSsao(fbo, expFactor);
+	Combine(fbo);
 	AntiAliasing(fbo);
 
@@ -415,5 +443,6 @@
 void SsaoShader::AntiAliasing(FrameBufferObject *fbo)
 {
-	GLuint colorsTex = mNewFbo->GetColorBuffer(0)->GetTexture();
+	GLuint colorsTex = mFbo4->GetColorBuffer(0)->GetTexture();
+	//GLuint colorsTex = mNewFbo->GetColorBuffer(0)->GetTexture();
 	GLuint normalsTex = fbo->GetColorBuffer(2)->GetTexture();
 	
@@ -503,3 +532,50 @@
 }
 
+
+void SsaoShader::Combine(FrameBufferObject *fbo)
+{
+	GLuint colorsTex = mFbo3->GetColorBuffer(0)->GetTexture();
+	GLuint ssaoTex = mNewFbo->GetColorBuffer(0)->GetTexture();
+
+	mFbo4->Bind();
+	//mNewFbo->Bind();
+
+	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+	
+	glDrawBuffers(1, mymrt);
+
+	cgGLEnableProfile(RenderState::sCgFragmentProfile);
+
+	cgGLBindProgram(sCgCombineProgram);
+
+	cgGLSetTextureParameter(sColorsTexCombineParam, colorsTex);
+	cgGLEnableTextureParameter(sColorsTexCombineParam);
+
+	cgGLSetTextureParameter(sSsaoTexCombineParam, ssaoTex);
+	cgGLEnableTextureParameter(sSsaoTexCombineParam);
+
+	glColor3f(1.0f, 1.0f, 1.0f);
+
+	const float offs = 0.5f;
+
+	glBegin(GL_QUADS);
+
+	glTexCoord2f(0, 0); glVertex3f(-offs, -offs, -0.5f);
+	glTexCoord2f(1, 0); glVertex3f( offs, -offs, -0.5f);
+	glTexCoord2f(1, 1); glVertex3f( offs,  offs, -0.5f);
+	glTexCoord2f(0, 1); glVertex3f(-offs,  offs, -0.5f);
+
+	glEnd();
+
+	cgGLDisableTextureParameter(sColorsTexCombineParam);
+	cgGLDisableTextureParameter(sSsaoTexCombineParam);
+
+	cgGLDisableProfile(RenderState::sCgFragmentProfile);
+
+	FrameBufferObject::Release();
+
+	PrintGLerror("deferred shading");
+}
+
+
 } // namespace
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SsaoShader.h
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SsaoShader.h	(revision 2868)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SsaoShader.h	(revision 2869)
@@ -53,4 +53,5 @@
 
 	void AntiAliasing(FrameBufferObject *fbo);
+	void Combine(FrameBufferObject *fbo);
 
 	void CreateNoiseTex2D();
@@ -71,4 +72,5 @@
 	FrameBufferObject *mNewFbo;
 	FrameBufferObject *mFbo3;
+	FrameBufferObject *mFbo4;
 };
 
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/FriendlyCulling.vcproj
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/FriendlyCulling.vcproj	(revision 2868)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/FriendlyCulling.vcproj	(revision 2869)
@@ -799,8 +799,4 @@
 				>
 			</File>
-			<File
-				RelativePath=".\src\shaders\temporal.cg"
-				>
-			</File>
 		</Filter>
 		<File
