Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg	(revision 2868)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg	(revision 2873)
@@ -42,32 +42,4 @@
 
 
-/** The mrt shader for standard rendering
-*/
-pixel main2(fragment IN, 
-		   uniform sampler2D colors,
-		   uniform sampler2D positions,
-		   uniform sampler2D normals
-		   )
-{
-	pixel OUT;
-
-	float4 norm = tex2D(normals, IN.texCoord.xy);
-	float4 color = tex2D(colors, IN.texCoord.xy);
-	float4 position = tex2D(positions, IN.texCoord.xy);
-
-	// an ambient color term
-	float amb = norm.w;
-
-	// expand normal
-	float3 normal = normalize(norm.xyz);// * 2.0f - float4(1.0f));
-
-	float4 col = shade(IN, color, position, normal, amb);
-	
-	//OUT.color = float4(1.0f);
-	OUT.color = col;
-	OUT.color.w = color.w;
-
-	return OUT;
-}
 
 /** The mrt shader for standard rendering
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/mrt.cg
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/mrt.cg	(revision 2867)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/mrt.cg	(revision 2873)
@@ -101,7 +101,8 @@
 
 pixel frag(fragin IN, 
-	   uniform float maxDepth, 
-	   uniform float4 ambient, 
-	   uniform float4 diffuse)
+		   uniform float maxDepth, 
+		   uniform float4 ambient, 
+		   uniform float4 diffuse
+		   )
 {
 	pixel pix;
@@ -109,9 +110,13 @@
 	pix.col = diffuse;
 	pix.pos = IN.worldPos * maxDepth;
+
 	//pix.norm.xyz = IN.normal * 0.5f + float3(0.5f);
 	pix.norm.xyz = IN.normal;
+	
 	// hack: squeeze some information about the ambient term into the target
 	pix.norm.w = ambient.x;
 	pix.pos.w = IN.mypos.w;
+	
+	// the projected depth
 	pix.col.w = IN.mypos.z / IN.mypos.w;
 
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg	(revision 2872)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg	(revision 2873)
@@ -3,10 +3,10 @@
 // based on shader of Alexander Kusternig
 
-//#define NUM_SAMPLES 8
-#define NUM_SAMPLES 16
+#define NUM_SAMPLES 10
+//#define NUM_SAMPLES 16
 
 // rule of thumb: approx 1 / NUM_SAMPLES
-#define SAMPLE_INTENSITY 0.15
-//#define SAMPLE_INTENSITY 0.125f
+//#define SAMPLE_INTENSITY 0.15f
+#define SAMPLE_INTENSITY 0.2f
 
 #define AREA_SIZE 7e-1f
@@ -43,13 +43,4 @@
 
 
-/*float2 rotate(float2 pt, float2 n)
-{
-	float2 ptTransformed;
-	ptTransformed.x = n.r * pt.x - n.g * pt.y;
-	ptTransformed.y = n.g * pt.x + n.r * pt.y;
-
-	return ptTransformed;
-}*/
-
 
 /** The ssao shader returning the an intensity value between 0 and 1
@@ -74,17 +65,14 @@
 	float total_ao = 0.0;
 
-	const float areaSize = 5e-1f;
-
 	for (int i = 0; i < NUM_SAMPLES; i ++) 
 	{
 		float2 offset = samples[i];
 
-		//sample noisetex; r stores costheta, g stores sintheta
+		////////////////////
+		// add random noise: r stores costheta, g stores sintheta
+
 		//float2 mynoise = tex2D(noiseTexture, IN.texCoord.xy * noiseMultiplier).xy * 2.0f - 1.0f;
 		float2 mynoise = tex2D(noiseTexture, IN.texCoord.xy * noiseMultiplier).xy;
 
-		// rotation
-		//float2 offsetTransformed = offset;
-		//float2 offsetTransformed = rotate(offset, mynoise);
 		float2 offsetTransformed = reflect(offset, mynoise);
 
@@ -117,70 +105,4 @@
 	return max(0.0f, 1.0f - total_ao);
 	//return dot(currentViewDir, currentNormal);
-}
-
-
-/** Computes ambient occlusion + diffuse reflections
-*/
-float4 globIllum(fragment IN,
-				 uniform sampler2D colors,
-				 uniform sampler2D positions,
-				 uniform sampler2D noiseTexture,
-				 uniform float2 samples[NUM_SAMPLES],
-				 uniform float3 currentNormal,
-				 uniform float3 currentViewDir,
-				 uniform float noiseMultiplier,
-				 uniform float4 centerPosition
-				 )
-{
-	// the w coordinate from the persp. projection
-	float w = centerPosition.w;
-
-	// Check in a circular area around the current position.
-	// Shoot vectors to the positions there, and check the angle to these positions.
-	// Summing up these angles gives an estimation of the occlusion at the current position.
-
-	// ao is in stored in the w
-	float4 total_color = float4(0, 0, 0, 1);
-
-	const float areaSize = 5e-1f;
-
-	for (int i = 0; i < NUM_SAMPLES; i ++) 
-	{
-		float2 offset = samples[i];
-
-		//sample noisetex; r stores costheta, g stores sintheta
-		float2 mynoise = tex2D(noiseTexture, IN.texCoord.xy * noiseMultiplier).xy;
-
-		// rotation
-		float2 offsetTransformed = reflect(offset, mynoise);
-
-		// weight with projected coordinate to reach similar kernel size for near and far
-		float2 texcoord = IN.texCoord.xy + offsetTransformed * AREA_SIZE * w;
-
-		float3 sample_position = tex2Dlod(positions, float4(texcoord, 0, 1)).xyz;
-		float3 sample_color = tex2Dlod(colors, float4(texcoord, 0, 1)).xyz;
-
-		float3 vector_to_sample = sample_position - centerPosition.xyz;
-		float length_to_sample = length(vector_to_sample);
-		float3 direction_to_sample = vector_to_sample / length_to_sample;
-
-		// Angle between current normal and direction to sample controls AO intensity.
-		float cos_angle = dot(direction_to_sample, currentNormal);
-		cos_angle = max(cos_angle, 0.0f);
-
-		// distance between current position and sample position controls AO intensity.
-		float distance_intensity = 
-			(SAMPLE_INTENSITY * DISTANCE_SCALE) / (DISTANCE_SCALE + length_to_sample * length_to_sample);
-
-		// if normal perpenticular to view dir, only half of the samples count
-		float view_correction = 1.0f + VIEW_CORRECTION_SCALE * (1.0f - dot(currentViewDir, currentNormal));
-
-		total_color.w -= cos_angle * distance_intensity * view_correction;
-
-		const float scale_factor = 0.3f;
-		total_color.xyz += cos_angle * distance_intensity * view_correction * sample_color * scale_factor;
-	}
-
-	return saturate(total_color);
 }
 
@@ -220,10 +142,9 @@
 	const float currentDepth = currentCol.w;
 
-	//float4 new_col = (float4)ssao(IN, positions, noiseTexture, samples, normal, viewDir, noiseMultiplier, centerPosition);
-	float4 new_col = globIllum(IN, colors, positions, noiseTexture, samples, normal, viewDir, noiseMultiplier, centerPosition); 
-	
+	const float ao = ssao(IN, positions, noiseTexture, samples, normal, viewDir, noiseMultiplier, centerPosition);
+		
 
 	/////////////////
-	//-- compute temporally smoothed value
+	//-- compute temporally smoothing
 
 	float4 realPos = centerPosition * maxDepth;
@@ -240,40 +161,21 @@
 	const 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))
+		(abs(depthDif)  < 1e-3f))
 	{
-		OUT.illum_col = new_col * expFactor + oldCol * float4(1.0f - expFactor);
+		OUT.illum_col.x = ao * expFactor + oldCol.x * (1.0f - expFactor);
 	}
 	else
 	{
-		OUT.illum_col = new_col;
+		OUT.illum_col.x = ao;
 	}
 
-	//const float ao = OUT.illum_col.x;
-	const float ao = OUT.illum_col.w;
+	OUT.combined_col = currentCol * OUT.illum_col.x;
+	OUT.illum_col.w = currentDepth;
 
-	//OUT.combined_col = (currentCol + OUT.illum_col) * ao;
-	OUT.combined_col = currentCol * ao;
-
-	OUT.illum_col.w = currentDepth;
+	
 
 	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);
-	//float4 illum = tex2D(ssaoTex, IN.texCoord.xy);
-
-	OUT.illum_col = col * ao;
-
-	return OUT;
-}*/
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SampleGenerator.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SampleGenerator.cpp	(revision 2865)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SampleGenerator.cpp	(revision 2873)
@@ -19,9 +19,18 @@
 void PoissonDiscSampleGenerator::Generate(Sample2 *samples) const
 {
+	// this is a hacky poisson sampling generator which does random dart-throwing
+	// until it is not able to place any dart for a number of tries
+	// in this case, the required min distance is reduced
+	// the solution is a possion sampling with respect to the adjusted min distance
+	// better solutions have been proposed, i.e., using hierarchical sampling
+
+	const float maxTries = 1000;
+	const float f_reduction = 0.9f;
+
 	static HaltonSequence halton;
 	float r[2];
 
 	// generates poisson distribution on disc
-	float minDist = 4.0f / sqrt((float)mNumSamples);
+	float minDist = 2.0f / sqrt((float)mNumSamples);
 
 	//cout << "minDist before= " << minDist << endl;
@@ -66,7 +75,7 @@
 			}
 
-			if (tries > 2000)
+			if (tries > maxTries)
 			{
-				minDist *= 0.9f;
+				minDist *= f_reduction;
 				tries = 0;
 			}
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SsaoShader.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SsaoShader.cpp	(revision 2871)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SsaoShader.cpp	(revision 2873)
@@ -15,9 +15,11 @@
 
 // number of ssao samples
-#define NUM_SAMPLES 16
+#define NUM_SAMPLES 10
 
 
 static CGprogram sCgSsaoProgram = NULL;
-static CGprogram sCgDeferredProgram2 = NULL;
+static CGprogram sCgGiProgram = NULL;
+
+static CGprogram sCgDeferredProgram = NULL;
 static CGprogram sCgAntiAliasingProgram = NULL;
 static CGprogram sCgCombineProgram = NULL;
@@ -30,8 +32,11 @@
 static CGparameter sNormalsTexDeferredParam;
 
+
+///////////////////////////////////////7
+
+
 static CGparameter sColorsTexParam;
 static CGparameter sPositionsTexParam;
 static CGparameter sNormalsTexParam;
-
 
 static CGparameter sOldModelViewProjMatrixParam;
@@ -43,4 +48,25 @@
 static CGparameter sExpFactorParam;
 
+
+///////////////////////////////////////
+
+
+static CGparameter sColorsTexGiParam;
+static CGparameter sPositionsTexGiParam;
+static CGparameter sNormalsTexGiParam;
+
+
+static CGparameter sOldModelViewProjMatrixGiParam;
+static CGparameter sMaxDepthGiParam;
+static CGparameter sSamplesGiParam; 
+static CGparameter sOldSsaoTexGiParam;
+static CGparameter sOldIllumTexGiParam;
+static CGparameter sNoiseTexGiParam;
+static CGparameter sNoiseMultiplierGiParam;
+static CGparameter sExpFactorGiParam;
+
+
+////////////
+
 static CGparameter sColorsTexAntiAliasingParam;
 static CGparameter sNormalsTexAntiAliasingParam;
@@ -88,4 +114,5 @@
 	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);
@@ -93,4 +120,5 @@
 	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);
 	
 	mFbo3 = new FrameBufferObject(w, h, FrameBufferObject::DEPTH_NONE);
@@ -98,7 +126,4 @@
 	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
@@ -121,44 +146,24 @@
 void SsaoShader::Init(CGcontext context)
 {	
-	sCgDeferredProgram2 = 
+	sCgDeferredProgram = 
 		cgCreateProgramFromFile(context, 
 								CG_SOURCE,
 								"src/shaders/deferred.cg", 
 								RenderState::sCgFragmentProfile,
-								"main2",
+								"main",
 								NULL);
 
-	if (sCgDeferredProgram2 != NULL)
-	{
-		cgGLLoadProgram(sCgDeferredProgram2);
+	if (sCgDeferredProgram != NULL)
+	{
+		cgGLLoadProgram(sCgDeferredProgram);
 
 		// we need size of texture for scaling
-		sPositionsTexDeferredParam = cgGetNamedParameter(sCgDeferredProgram2, "positions");  
-		sColorsTexDeferredParam = cgGetNamedParameter(sCgDeferredProgram2, "colors");  
-		sNormalsTexDeferredParam = cgGetNamedParameter(sCgDeferredProgram2, "normals"); 
+		sPositionsTexDeferredParam = cgGetNamedParameter(sCgDeferredProgram, "positions");  
+		sColorsTexDeferredParam = cgGetNamedParameter(sCgDeferredProgram, "colors");  
+		sNormalsTexDeferredParam = cgGetNamedParameter(sCgDeferredProgram, "normals"); 
 	}
 	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;
-*/
 
 	///////////////
@@ -189,4 +194,5 @@
 		sSamplesParam = cgGetNamedParameter(sCgSsaoProgram, "samples");
 		sOldTexParam = cgGetNamedParameter(sCgSsaoProgram, "oldTex");  
+		
 
 		// generate samples for ssao kernel
@@ -196,4 +202,39 @@
 	else
 		cerr << "ssao program failed to load" << endl;
+
+	sCgGiProgram = 
+		cgCreateProgramFromFile(context, 
+								CG_SOURCE,
+								"src/shaders/globillum.cg", 
+								RenderState::sCgFragmentProfile,
+								"main",
+								NULL);
+
+	if (sCgGiProgram != NULL)
+	{
+		cgGLLoadProgram(sCgGiProgram);
+
+		// we need size of texture for scaling
+		sPositionsTexGiParam = cgGetNamedParameter(sCgGiProgram, "positions");  
+		sColorsTexGiParam = cgGetNamedParameter(sCgGiProgram, "colors");  
+		sNormalsTexGiParam = cgGetNamedParameter(sCgGiProgram, "normals");  
+		sNoiseTexGiParam = cgGetNamedParameter(sCgGiProgram, "noiseTexture");
+		sNoiseMultiplierGiParam = cgGetNamedParameter(sCgGiProgram, "noiseMultiplier");
+		
+		sOldModelViewProjMatrixParam = cgGetNamedParameter(sCgGiProgram, "oldModelViewProj");
+		sMaxDepthGiParam = cgGetNamedParameter(sCgGiProgram, "maxDepth");
+		sExpFactorGiParam = cgGetNamedParameter(sCgGiProgram, "expFactor");
+
+		sSamplesGiParam = cgGetNamedParameter(sCgGiProgram, "samples");
+		
+		sOldSsaoTexGiParam = cgGetNamedParameter(sCgGiProgram, "oldSsaoTex");  
+		sOldIllumTexGiParam = cgGetNamedParameter(sCgGiProgram, "oldIllumTex");  
+
+		// generate samples for ssao kernel
+		GenerateSamples(); 
+		cgGLSetParameterArray2f(sSamplesGiParam, 0, NUM_SAMPLES, (const float *)samples);
+	}
+	else
+		cerr << "globillum program failed to load" << endl;
 
 	sCgAntiAliasingProgram = 
@@ -258,5 +299,8 @@
 
 	FirstPass(fbo);
+	
 	ComputeSsao(fbo, expFactor);
+	//ComputeGlobIllum(fbo, expFactor);
+
 	//Combine(fbo);
 	AntiAliasing(fbo);
@@ -323,5 +367,8 @@
 
 
-	//GenerateSamples(); 
+	// q: should we generate new samples or only rotate the old ones?
+	// in the first case, the sample patterns look nicer, but the kernel
+	// needs longer to converge
+	GenerateSamples(); 
 	cgGLSetParameterArray2f(sSamplesParam, 0, NUM_SAMPLES, (const float *)samples);
 
@@ -499,5 +546,5 @@
 	cgGLEnableProfile(RenderState::sCgFragmentProfile);
 
-	cgGLBindProgram(sCgDeferredProgram2);
+	cgGLBindProgram(sCgDeferredProgram);
 
 	cgGLSetTextureParameter(sColorsTexDeferredParam, colorsTex);
@@ -535,47 +582,92 @@
 
 
-void SsaoShader::Combine(FrameBufferObject *fbo)
+void SsaoShader::ComputeGlobIllum(FrameBufferObject *fbo, float expFactor)
 {
 	GLuint colorsTex = mFbo3->GetColorBuffer(0)->GetTexture();
-	GLuint ssaoTex = mNewFbo->GetColorBuffer(0)->GetTexture();
-
-	mFbo4->Bind();
-	//mNewFbo->Bind();
+	GLuint positionsTex = fbo->GetColorBuffer(1)->GetTexture();
+	GLuint normalsTex = fbo->GetColorBuffer(2)->GetTexture();
+
+	if (1)
+	{
+		// generate mip map levels for position texture
+		glBindTexture(GL_TEXTURE_2D, positionsTex);
+		glGenerateMipmapEXT(GL_TEXTURE_2D);
+
+		// generate mip map levels for position texture
+		glBindTexture(GL_TEXTURE_2D, colorsTex);
+		glGenerateMipmapEXT(GL_TEXTURE_2D);
+	}
+
+
+	// read the second buffer, write to the first buffer
+	mNewFbo->Bind();
+	glDrawBuffers(3, mymrt);
+
+	GLuint oldSsaoTex = mOldFbo->GetColorBuffer(0)->GetTexture();
+	GLuint oldIllumTex = mOldFbo->GetColorBuffer(2)->GetTexture();
 
 	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);
+	cgGLBindProgram(sCgGiProgram);
+
+	cgGLSetTextureParameter(sPositionsTexGiParam, positionsTex);
+	cgGLEnableTextureParameter(sPositionsTexGiParam);
+
+	cgGLSetTextureParameter(sColorsTexGiParam, colorsTex);
+	cgGLEnableTextureParameter(sColorsTexGiParam);
+
+	cgGLSetTextureParameter(sNormalsTexGiParam, normalsTex);
+	cgGLEnableTextureParameter(sNormalsTexGiParam);
+
+	cgGLSetTextureParameter(sNoiseTexGiParam, noiseTex);
+	cgGLEnableTextureParameter(sNoiseTexGiParam);
+
+	cgGLSetTextureParameter(sOldSsaoTexGiParam, oldSsaoTex);
+	cgGLEnableTextureParameter(sOldSsaoTexGiParam);
+
+	cgGLSetTextureParameter(sOldIllumTexGiParam, oldIllumTex);
+	cgGLEnableTextureParameter(sOldIllumTexGiParam);
+
+	cgGLSetParameter1f(sNoiseMultiplierGiParam, RandomValue(3.0f, 17.0f));
+	
+	cgGLSetParameter1f(sMaxDepthGiParam, mScaleFactor);
+	cgGLSetParameter1f(sExpFactorGiParam, expFactor);
+
+
+	// q: should we generate new samples or only rotate the old ones?
+	// in the first case, the sample patterns look nicer, but the kernel
+	// needs longer to converge
+	GenerateSamples(); 
+	cgGLSetParameterArray2f(sSamplesGiParam, 0, NUM_SAMPLES, (const float *)samples);
+
+	Vector3 tl, tr, bl, br;
+	ComputeViewVectors(tl, tr, bl, br);
 
 	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);
+	// note: slightly larger texture hides ambient occlusion error on border but costs resolution
+	//const float new_offs = 0.55f;
+	const float new_offs = 0.5f;
+	
+	glColor3f(bl.x, bl.y, bl.z); glTexCoord2f(0, 0); glVertex3f(-new_offs, -new_offs, -0.5f);
+	glColor3f(br.x, br.y, br.z); glTexCoord2f(1, 0); glVertex3f( new_offs, -new_offs, -0.5f);
+	glColor3f(tr.x, tr.y, tr.z); glTexCoord2f(1, 1); glVertex3f( new_offs,  new_offs, -0.5f);
+	glColor3f(tl.x, tl.y, tl.z); glTexCoord2f(0, 1); glVertex3f(-new_offs,  new_offs, -0.5f);
 
 	glEnd();
 
-	cgGLDisableTextureParameter(sColorsTexCombineParam);
-	cgGLDisableTextureParameter(sSsaoTexCombineParam);
-
-	cgGLDisableProfile(RenderState::sCgFragmentProfile);
+	cgGLDisableTextureParameter(sColorsTexGiParam);
+	cgGLDisableTextureParameter(sPositionsTexGiParam);
+	cgGLDisableTextureParameter(sNormalsTexGiParam);
+	cgGLDisableTextureParameter(sNoiseTexGiParam);
+	cgGLDisableTextureParameter(sOldSsaoTexGiParam);
+	cgGLDisableTextureParameter(sOldIllumTexGiParam);
 
 	FrameBufferObject::Release();
 
-	PrintGLerror("deferred shading");
+	PrintGLerror("globillum first pass");
 }
 
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SsaoShader.h
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SsaoShader.h	(revision 2869)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SsaoShader.h	(revision 2873)
@@ -50,8 +50,9 @@
 	void ComputeSsao(FrameBufferObject *fbo, float expFactor);
 
+	void ComputeGlobIllum(FrameBufferObject *fbo, float expFactor);
+
 	void FirstPass(FrameBufferObject *fbo);
 
 	void AntiAliasing(FrameBufferObject *fbo);
-	void Combine(FrameBufferObject *fbo);
 
 	void CreateNoiseTex2D();
@@ -72,5 +73,4 @@
 	FrameBufferObject *mNewFbo;
 	FrameBufferObject *mFbo3;
-	FrameBufferObject *mFbo4;
 };
 
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp	(revision 2868)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp	(revision 2873)
@@ -274,5 +274,5 @@
 	Vector3 camDir(.0f, 1.0f, .0f);
 
-	cout << "=== reading environment file === " << endl;
+	cout << "=== reading environment file ===" << endl << endl;
 
 	string envFileName = "default.env";
@@ -303,6 +303,4 @@
 		//env.GetIntParam(string("numSssaoSamples"), numSsaoSamples);
 
-
-		cout << "*********** parameters ***************" << endl;
 
 		cout << "assumedVisibleFrames: " << assumedVisibleFrames << endl; 
@@ -318,5 +316,8 @@
 		cout << "camPosition: " << camPos << endl;
 		cout << "expFactor: " << ssaoExpFactor << endl;
+
 		//cout << "model path: " << model_path << endl;
+
+		cout << "**** end parameters ****" << endl;
 	}
 
@@ -538,9 +539,10 @@
 
 	// the diffuse color buffer
+	//fbo->AddColorBuffer(ColorBufferObject::BUFFER_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_MIPMAP_LINEAR, true);
 	fbo->AddColorBuffer(ColorBufferObject::BUFFER_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_NEAREST, false);
 
 	// the positions buffer
 	fbo->AddColorBuffer(ColorBufferObject::BUFFER_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_MIPMAP_LINEAR, true);
-	//fbo->AddColorBuffer(ColorBufferObject::BUFFER_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_NEAREST, true);
+	//fbo->AddColorBuffer(ColorBufferObject::BUFFER_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_NEAREST, false);
 	
 	// the normals buffer
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/FriendlyCulling.vcproj
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/FriendlyCulling.vcproj	(revision 2869)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/FriendlyCulling.vcproj	(revision 2873)
@@ -792,4 +792,8 @@
 			</File>
 			<File
+				RelativePath=".\src\shaders\globillum.cg"
+				>
+			</File>
+			<File
 				RelativePath=".\src\shaders\mrt.cg"
 				>
