Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg	(revision 2876)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg	(revision 2880)
@@ -29,5 +29,4 @@
 {
 	float4 illum_col: COLOR0;
-	float4 combined_col: COLOR1;
 };
 
@@ -173,7 +172,22 @@
 	}
 
-	OUT.combined_col = currentCol * OUT.illum_col.x;
 	OUT.illum_col.w = currentDepth;
 
 	return OUT;
 }
+
+
+
+pixel combine(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.illum_col = col * ao.x;
+
+	return OUT;
+}
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/globillum.cg
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/globillum.cg	(revision 2876)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/globillum.cg	(revision 2880)
@@ -32,6 +32,5 @@
 {
 	float4 ssao_col: COLOR0;
-	float4 combined_col: COLOR1;
-	float4 illum_col: COLOR2;
+	float4 illum_col: COLOR1;
 };
 
@@ -185,9 +184,24 @@
 	}
 
-	OUT.combined_col = (currentCol + OUT.illum_col) * OUT.ssao_col.x;
-	//OUT.combined_col = float4(newDepth, oldDepth, 1, 1) ;
-
 	OUT.ssao_col.w = currentDepth;
 
 	return OUT;
 }
+
+
+pixel combine(fragment IN, 
+			  uniform sampler2D colors,
+			  uniform sampler2D ssaoTex,
+			  uniform sampler2D illumTex
+		   )
+{
+	pixel OUT;
+
+	float4 col = tex2D(colors, IN.texCoord.xy);
+	float ao = tex2D(ssaoTex, IN.texCoord.xy).x;
+	float4 illum = tex2D(illumTex, IN.texCoord.xy);
+	
+	OUT.illum_col = (col + illum) * ao;
+
+	return OUT;
+}
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SsaoShader.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SsaoShader.cpp	(revision 2879)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SsaoShader.cpp	(revision 2880)
@@ -23,5 +23,4 @@
 static CGprogram sCgDeferredProgram = NULL;
 static CGprogram sCgAntiAliasingProgram = NULL;
-static CGprogram sCgCombineProgram = NULL;
 
 static CGparameter sColorsTexCombineParam;
@@ -32,4 +31,7 @@
 static CGparameter sNormalsTexDeferredParam;
 
+
+static CGprogram sCgCombinedSsaoProgram = NULL;
+static CGprogram sCgCombinedIllumProgram = NULL;
 
 ///////////////////////////////////////7
@@ -67,4 +69,12 @@
 
 
+static CGparameter sColorsTexCombinedIllumParam;
+static CGparameter sSsaoTexCombinedIllumParam;
+static CGparameter sIllumTexCombinedIllumParam;
+
+static CGparameter sColorsTexCombinedSsaoParam;
+static CGparameter sSsaoTexCombinedSsaoParam;
+
+
 ////////////
 
@@ -157,11 +167,12 @@
 	//-- the flip-flop fbos
 
+	w = 256; h = 256;
 	mNewFbo = new FrameBufferObject(w, h, FrameBufferObject::DEPTH_NONE);
+	
 	mNewFbo->AddColorBuffer(ColorBufferObject::BUFFER_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_LINEAR, false);
 	mNewFbo->AddColorBuffer(ColorBufferObject::BUFFER_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_LINEAR, false);
-	mNewFbo->AddColorBuffer(ColorBufferObject::BUFFER_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_LINEAR, false);
 	
 	mOldFbo = new FrameBufferObject(w, h, FrameBufferObject::DEPTH_NONE);
-	mOldFbo->AddColorBuffer(ColorBufferObject::BUFFER_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_LINEAR, false);
+	
 	mOldFbo->AddColorBuffer(ColorBufferObject::BUFFER_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_LINEAR, false);
 	mOldFbo->AddColorBuffer(ColorBufferObject::BUFFER_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_LINEAR, false);
@@ -299,4 +310,43 @@
 		cerr << "globillum program failed to load" << endl;
 
+	sCgCombinedIllumProgram = 
+		cgCreateProgramFromFile(context, 
+								CG_SOURCE,
+								"src/shaders/globillum.cg", 
+								RenderState::sCgFragmentProfile,
+								"combine",
+								NULL);
+
+	if (sCgCombinedIllumProgram != NULL)
+	{
+		cgGLLoadProgram(sCgCombinedIllumProgram);
+
+		sColorsTexCombinedIllumParam = cgGetNamedParameter(sCgCombinedIllumProgram, "colors");  
+		sSsaoTexCombinedIllumParam = cgGetNamedParameter(sCgCombinedIllumProgram, "ssaoTex");
+		sIllumTexCombinedIllumParam = cgGetNamedParameter(sCgCombinedIllumProgram, "illumTex");
+	}
+	else
+		cerr << "combined illum program failed to load" << endl;
+
+
+	sCgCombinedSsaoProgram = 
+		cgCreateProgramFromFile(context, 
+								CG_SOURCE,
+								"src/shaders/ssao.cg", 
+								RenderState::sCgFragmentProfile,
+								"combine",
+								NULL);
+
+	if (sCgCombinedSsaoProgram != NULL)
+	{
+		cgGLLoadProgram(sCgCombinedSsaoProgram);
+
+		sColorsTexCombinedSsaoParam = cgGetNamedParameter(sCgCombinedSsaoProgram, "colors");  
+		sSsaoTexCombinedSsaoParam = cgGetNamedParameter(sCgCombinedSsaoProgram, "ssaoTex");
+	}
+	else
+		cerr << "combied illum program failed to load" << endl;
+
+	
 	sCgAntiAliasingProgram = 
 		cgCreateProgramFromFile(context, 
@@ -317,5 +367,4 @@
 		cerr << "antialiasing program failed to load" << endl;
 
-
 	PrintGLerror("init");
 }
@@ -333,8 +382,4 @@
 	swap(mNewFbo, mOldFbo);	
 
-
-	glPushAttrib(GL_VIEWPORT_BIT);
-	glViewport(0, 0, mWidth, mHeight);
-
 	FrameBufferObject::Release();
 
@@ -345,4 +390,7 @@
 	glDisable(GL_LIGHTING);
 
+	glPushAttrib(GL_VIEWPORT_BIT);
+	glViewport(0, 0, mWidth, mHeight);
+
 	glMatrixMode(GL_PROJECTION);
 	glPushMatrix();
@@ -359,8 +407,13 @@
 	
 	if (!mUseGlobIllum)
+	{
 		ComputeSsao(fbo, expFactor, oldProjViewMatrix);
+		CombineSsao(fbo);
+	}
 	else
+	{
 		ComputeGlobIllum(fbo, expFactor, oldProjViewMatrix);
-
+		CombineIllum(fbo);
+	}
 	AntiAliasing(fbo);
 
@@ -402,5 +455,20 @@
 	// read the second buffer, write to the first buffer
 	mNewFbo->Bind();
-	glDrawBuffers(2, mymrt);
+	glDrawBuffers(1, mymrt);
+
+	glPushAttrib(GL_VIEWPORT_BIT);
+	glViewport(0, 0, 256, 256);
+
+	glMatrixMode(GL_PROJECTION);
+	glPushMatrix();
+	glLoadIdentity();
+
+	glMatrixMode(GL_MODELVIEW);
+	glPushMatrix();
+	glLoadIdentity();
+
+	const float offs = 0.5f;
+	glOrtho(-offs, offs, -offs, offs, 0, 1);
+
 
 	GLuint oldTex = mOldFbo->GetColorBuffer(0)->GetTexture();
@@ -469,4 +537,12 @@
 	cgGLDisableTextureParameter(sOldTexParam);
 
+	glMatrixMode(GL_PROJECTION);
+	glPopMatrix();
+
+	glMatrixMode(GL_MODELVIEW);
+	glPopMatrix();
+
+	glPopAttrib();
+
 	FrameBufferObject::Release();
 
@@ -523,5 +599,6 @@
 void SsaoShader::AntiAliasing(FrameBufferObject *fbo)
 {
-	GLuint colorsTex = mNewFbo->GetColorBuffer(1)->GetTexture();
+	//GLuint colorsTex = mNewFbo->GetColorBuffer(1)->GetTexture();
+	GLuint colorsTex = fbo->GetColorBuffer(0)->GetTexture();
 	GLuint normalsTex = fbo->GetColorBuffer(2)->GetTexture();
 	
@@ -637,8 +714,8 @@
 	// read the second buffer, write to the first buffer
 	mNewFbo->Bind();
-	glDrawBuffers(3, mymrt);
+	glDrawBuffers(2, mymrt);
 
 	GLuint oldSsaoTex = mOldFbo->GetColorBuffer(0)->GetTexture();
-	GLuint oldIllumTex = mOldFbo->GetColorBuffer(2)->GetTexture();
+	GLuint oldIllumTex = mOldFbo->GetColorBuffer(1)->GetTexture();
 
 	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
@@ -716,3 +793,104 @@
 
 
+void SsaoShader::CombineIllum(FrameBufferObject *fbo)
+{
+	GLuint colorsTex = fbo->GetColorBuffer(3)->GetTexture();
+	GLuint ssaoTex = mNewFbo->GetColorBuffer(0)->GetTexture();
+	GLuint illumTex = mNewFbo->GetColorBuffer(1)->GetTexture();
+
+	//
+	fbo->Bind();
+
+	// write into old color texture (not needed anymore)
+	glDrawBuffers(1, mymrt);
+
+	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+	
+	cgGLEnableProfile(RenderState::sCgFragmentProfile);
+
+	cgGLBindProgram(sCgCombinedIllumProgram);
+
+	cgGLSetTextureParameter(sColorsTexCombinedIllumParam, colorsTex);
+	cgGLEnableTextureParameter(sColorsTexCombinedIllumParam);
+
+	cgGLSetTextureParameter(sSsaoTexCombinedIllumParam, ssaoTex);
+	cgGLEnableTextureParameter(sSsaoTexCombinedIllumParam);
+
+	cgGLSetTextureParameter(sIllumTexCombinedIllumParam, illumTex);
+	cgGLEnableTextureParameter(sIllumTexCombinedIllumParam);
+	
+	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(sColorsTexCombinedIllumParam);
+	cgGLDisableTextureParameter(sSsaoTexCombinedIllumParam);
+	cgGLDisableTextureParameter(sIllumTexCombinedIllumParam);
+
+	cgGLDisableProfile(RenderState::sCgFragmentProfile);
+
+	FrameBufferObject::Release();
+
+	PrintGLerror("combine");
+}
+
+
+void SsaoShader::CombineSsao(FrameBufferObject *fbo)
+{
+	GLuint colorsTex = fbo->GetColorBuffer(3)->GetTexture();
+	GLuint ssaoTex = mNewFbo->GetColorBuffer(0)->GetTexture();
+
+	//
+	fbo->Bind();
+
+	// write into old color texture (not needed anymore)
+	glDrawBuffers(1, mymrt);
+
+	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+	
+	cgGLEnableProfile(RenderState::sCgFragmentProfile);
+
+	cgGLBindProgram(sCgCombinedSsaoProgram);
+
+	cgGLSetTextureParameter(sColorsTexCombinedSsaoParam, colorsTex);
+	cgGLEnableTextureParameter(sColorsTexCombinedSsaoParam);
+
+	cgGLSetTextureParameter(sSsaoTexCombinedSsaoParam, ssaoTex);
+	cgGLEnableTextureParameter(sSsaoTexCombinedSsaoParam);
+
+	
+	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(sColorsTexCombinedSsaoParam);
+	cgGLDisableTextureParameter(sSsaoTexCombinedSsaoParam);
+
+	cgGLDisableProfile(RenderState::sCgFragmentProfile);
+
+	FrameBufferObject::Release();
+
+	PrintGLerror("combine ssao");
+}
+
+
+
 } // namespace
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SsaoShader.h
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SsaoShader.h	(revision 2879)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SsaoShader.h	(revision 2880)
@@ -56,4 +56,7 @@
 	void FirstPass(FrameBufferObject *fbo);
 
+	void CombineSsao(FrameBufferObject *fbo);
+	void CombineIllum(FrameBufferObject *fbo);
+
 	void AntiAliasing(FrameBufferObject *fbo);
 
