Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ShaderProgram.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ShaderProgram.cpp	(revision 3046)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ShaderProgram.cpp	(revision 3104)
@@ -363,4 +363,15 @@
 
 
+void ShaderProgram::AddParameters(std::string params[], 
+								  int startIdx, 
+								  int numElements)
+{
+	for (int i = 0; i < numElements; ++ i)
+	{
+		AddParameter(params[i], startIdx + i);
+	}
+}
+
+
 CGparameter ShaderProgram::GetOrCreateParameter(const string &name)
 {
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg	(revision 3099)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg	(revision 3104)
@@ -231,5 +231,5 @@
 	const float currentDepth = currentPos.z * precisionScale;
 
-	const float2 ao = ssao(IN, colors, noise, samples, normal, 
+	const float2 ao = ssao(IN, colors, noiseTex, samples, normal, 
 		                   eyeSpacePos, w, bl, br, tl, tr, normalize(viewDir));
 
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg	(revision 3103)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg	(revision 3104)
@@ -354,2 +354,46 @@
 	return OUT;
 }
+
+float Filter(float2 texCoord, 
+			 uniform sampler2D ssaoTex,
+			 uniform float2 filterOffs[NUM_SSAO_FILTERSAMPLES],
+			 uniform float filterWeights[NUM_SSAO_FILTERSAMPLES])
+{
+	float average = .0f;
+	float w = .0f;
+
+	for (int i = 0; i < NUM_SSAO_FILTERSAMPLES; ++ i)
+	{
+		average += filterWeights[i] * tex2Dlod(ssaoTex, float4(texCoord + filterOffs[i], 0, 0)).x;
+		w += filterWeights[i];
+	}
+
+	average *= 1.0f / (float)w;
+
+	return average;
+}
+
+
+pixel combine(fragment IN, 
+			  uniform sampler2D colorsTex,
+			  uniform sampler2D ssaoTex,
+			  uniform float2 filterOffs[NUM_SSAO_FILTERSAMPLES],
+			  uniform float filterWeights[NUM_SSAO_FILTERSAMPLES]
+			  )
+{
+	pixel OUT;
+
+	float4 col = tex2Dlod(colorsTex, float4(IN.texCoord, 0, 0));
+	float4 ao = tex2Dlod(ssaoTex, float4(IN.texCoord, 0, 0));
+
+	//if (ao.y < 10.0f) ao.x = Filter(IN.texCoord, ssaoTex, filterOffs, filterWeights);
+
+	//OUT.illum_col = col * ao.x;
+	//OUT.illum_col = float4(ao.y, ao.y, ao.y, col.w);
+	//OUT.illum_col = float4(ao.x, ao.x, ao.x, col.w);
+	OUT.illum_col.xyz = float3(1.0f - ao.x, 1.0f - ao.y * 1e-2f, 1);
+	//OUT.illum_col.xyz = float3(1.0f - ao.x, ao.y, 0);
+	OUT.illum_col.w = col.w;
+
+	return OUT;
+}
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/globillum.cg
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/globillum.cg	(revision 3103)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/globillum.cg	(revision 3104)
@@ -254,5 +254,5 @@
 
 pixel combine(fragment IN, 
-			  uniform sampler2D colors,
+			  uniform sampler2D colorsTex,
 			  uniform sampler2D ssaoTex,
 			  uniform sampler2D illumTex
@@ -261,5 +261,5 @@
 	pixel OUT;
 
-	float4 col = tex2Dlod(colors, float4(IN.texCoord, 0, 0));
+	float4 col = tex2Dlod(colorsTex, float4(IN.texCoord, 0, 0));
 	float ao = tex2Dlod(ssaoTex, float4(IN.texCoord, 0, 0)).x;
 
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ShaderProgram.h
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ShaderProgram.h	(revision 3046)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ShaderProgram.h	(revision 3104)
@@ -199,5 +199,8 @@
 	*/
 	CGparameter AddParameter(const std::string &name, int idx);
-
+	/** Comvenience method that adds an array of parameters beginning with
+		index i of size numElements
+	*/
+	void AddParameters(std::string params[], int startIdx, int numElements);
 
 	//////////////
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.cpp	(revision 3103)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.cpp	(revision 3104)
@@ -321,5 +321,6 @@
 	sCgGiProgram = sm->CreateFragmentProgram("globillum", "main", "giFrag");
 	sCgCombineIllumProgram = sm->CreateFragmentProgram("globillum", "combine", "combineGi");
-	sCgCombineSsaoProgram = sm->CreateFragmentProgram("combineSsao", "combine", "combineSsao");
+	//sCgCombineSsaoProgram = sm->CreateFragmentProgram("combineSsao", "combine", "combineSsao");
+	sCgCombineSsaoProgram = sm->CreateFragmentProgram("ssao", "combine", "combineSsao");
 	sCgAntiAliasingProgram = sm->CreateFragmentProgram("antialiasing", "main", "antiAliasing");
 	sCgToneProgram = sm->CreateFragmentProgram("tonemap", "ToneMap", "toneMap");
@@ -327,78 +328,64 @@
 	sCgLogLumProgram = sm->CreateFragmentProgram("tonemap", "CalcAvgLogLum", "avgLogLum");
 
-	int i;
-
-	i = 0;
-	sCgSsaoProgram->AddParameter("colors", i ++);
-	sCgSsaoProgram->AddParameter("normals", i ++);
-	sCgSsaoProgram->AddParameter("oldTex", i ++);
-	sCgSsaoProgram->AddParameter("noiseTex", i ++);
-	sCgSsaoProgram->AddParameter("temporalCoherence", i ++);
-	sCgSsaoProgram->AddParameter("samples", i ++);
-	sCgSsaoProgram->AddParameter("bl", i ++);
-	sCgSsaoProgram->AddParameter("br", i ++);
-	sCgSsaoProgram->AddParameter("tl", i ++);
-	sCgSsaoProgram->AddParameter("tr", i ++);
-	sCgSsaoProgram->AddParameter("modelViewProj", i ++);
-	sCgSsaoProgram->AddParameter("oldModelViewProj", i ++);
-
-	sCgSsaoProgram->AddParameter("oldEyePos", i ++);
-	sCgSsaoProgram->AddParameter("oldbl", i ++);
-	sCgSsaoProgram->AddParameter("oldbr", i ++);
-	sCgSsaoProgram->AddParameter("oldtl", i ++);
-	sCgSsaoProgram->AddParameter("oldtr", i ++);
-	
-	i = 0;
-	sCgGiProgram->AddParameter("colors", i ++);
-	sCgGiProgram->AddParameter("normals", i ++);
-	sCgGiProgram->AddParameter("noiseTex", i ++);
-	sCgGiProgram->AddParameter("oldSsaoTex", i ++);
-	sCgGiProgram->AddParameter("oldIllumTex", i ++);
-	sCgGiProgram->AddParameter("temporalCoherence", i ++);
-	sCgGiProgram->AddParameter("samples", i ++);
-	sCgGiProgram->AddParameter("bl", i ++);
-	sCgGiProgram->AddParameter("br", i ++);
-	sCgGiProgram->AddParameter("tl", i ++);
-	sCgGiProgram->AddParameter("tr", i ++);
-	sCgGiProgram->AddParameter("oldModelViewProj", i ++);
-	sCgGiProgram->AddParameter("modelViewProj", i ++);
-
-	sCgAntiAliasingProgram->AddParameter("colors", 0);
-	sCgAntiAliasingProgram->AddParameter("normals", 1);
-
-	sCgDeferredProgram->AddParameter("colors", 0);
-	sCgDeferredProgram->AddParameter("normals", 1);
-	sCgDeferredProgram->AddParameter("lightDir", 2);
+
+	///////////////////
+	//-- initialize program parameters
+
+	string ssaoParams[] = 
+		{"colors", "normals", "oldTex", "noiseTex", "temporalCoherence", 
+		 "samples", "bl", "br", "tl", "tr", "modelViewProj", "oldModelViewProj",
+		 "oldEyePos", "oldbl", "oldbr", "oldtl", "oldtr"};
+	sCgSsaoProgram->AddParameters(ssaoParams, 0, 17);
+	
+	string giParams[] = 
+		{"colors", "normals", "noiseTex", "oldSsaoTex", "oldIllumTex", 
+		 "temporalCoherence", "samples", "bl", "br", "tl", "tr", "oldModelViewProj", "modelViewProj"};
+	sCgGiProgram->AddParameters(giParams, 0, 13);
+
+	string toneParams[] = {"colors", "imageKey", "whiteLum", "middleGrey"};
+	sCgToneProgram->AddParameters(toneParams, 0, 4);
+
+
+	////////////////
+
+	string deferredShadowParams[] = 
+		{"colors", "normals", "shadowMap", "noiseTex", "shadowMatrix", 
+		 "sampleWidth", "lightDir", "eyePos", "samples", "weights"};
+	
+	sCgDeferredShadowProgram->AddParameters(deferredShadowParams, 0, 10);
+	
+	////////////////
+
+	string combineIllumParams[] = {"colorsTex", "ssaoTex", "illumTex"};
+	sCgCombineIllumProgram->AddParameters(combineIllumParams, 0, 3);
+
+	////////////////
+
+	string combineSsaoParams[] = {"colorsTex", "ssaoTex", "filterOffs", "filterWeights"};
+	sCgCombineSsaoProgram->AddParameters(combineSsaoParams, 0, 4);
+
+	//////////////
+
+	string deferredParams[] = {"colors", "normals", "lightDir"};
+	sCgDeferredProgram->AddParameters(deferredParams, 0, 3);
+
+	///////////////////
+
+	string aaParams[] = {"colors", "normals"};
+	sCgAntiAliasingProgram->AddParameters(aaParams, 0, 2);
+
+	/////////////////////
+
+	string downSampleParams[] = {"colors", "downSampleOffs"};
+	sCgDownSampleProgram->AddParameters(downSampleParams, 0, 2);
+
+	////////////
 
 	sCgLogLumProgram->AddParameter("colors", 0);
 	
-	sCgToneProgram->AddParameter("colors", 0);
-	sCgToneProgram->AddParameter("imageKey", 1);
-	sCgToneProgram->AddParameter("whiteLum", 2);
-	sCgToneProgram->AddParameter("middleGrey", 3);
-
-	sCgDownSampleProgram->AddParameter("colors", 0);
-	sCgDownSampleProgram->AddParameter("downSampleOffs", 1);
-
-	sCgDeferredShadowProgram->AddParameter("colors", 0);
-	sCgDeferredShadowProgram->AddParameter("normals", 1);
-  	sCgDeferredShadowProgram->AddParameter("shadowMap", 2);
-  	sCgDeferredShadowProgram->AddParameter("noise", 3);
- 	sCgDeferredShadowProgram->AddParameter("shadowMatrix", 4);
-  	sCgDeferredShadowProgram->AddParameter("sampleWidth", 5);
-	sCgDeferredShadowProgram->AddParameter("lightDir", 6);
- 	sCgDeferredShadowProgram->AddParameter("eyePos", 7);
-	sCgDeferredShadowProgram->AddParameter("samples", 8);
-	sCgDeferredShadowProgram->AddParameter("weights", 9);
-
-	sCgCombineIllumProgram->AddParameter("colors", 0);
-	sCgCombineIllumProgram->AddParameter("ssaoTex", 1);
-	sCgCombineIllumProgram->AddParameter("illumTex", 2);
-
-	sCgCombineSsaoProgram->AddParameter("colorsTex", 0);
-	sCgCombineSsaoProgram->AddParameter("normalsTex", 1);
-	sCgCombineSsaoProgram->AddParameter("ssaoTex", 2);
-	sCgCombineSsaoProgram->AddParameter("filterOffs", 3);
-	sCgCombineSsaoProgram->AddParameter("filterWeights", 4);
+	
+	
+	///////////
+
 
 	PoissonDiscSampleGenerator2 poisson(NUM_SSAO_FILTERSAMPLES, 1.0f);
@@ -744,10 +731,11 @@
 	glDrawBuffers(1, mrt + colorBufferIdx);
 
-	sCgCombineSsaoProgram->SetTexture(0, colorsTex);
-	sCgCombineSsaoProgram->SetTexture(1, normalsTex);
-	sCgCombineSsaoProgram->SetTexture(2, ssaoTex);
-
-	sCgCombineSsaoProgram->SetArray2f(3, (float *)ssaoFilterOffsets, NUM_SSAO_FILTERSAMPLES);
-	sCgCombineSsaoProgram->SetArray1f(4, (float *)ssaoFilterWeights, NUM_SSAO_FILTERSAMPLES);
+	int i = 0;
+	sCgCombineSsaoProgram->SetTexture(i ++, colorsTex);
+	//sCgCombineSsaoProgram->SetTexture(i ++, normalsTex);
+	sCgCombineSsaoProgram->SetTexture(i ++, ssaoTex);
+
+	sCgCombineSsaoProgram->SetArray2f(i ++, (float *)ssaoFilterOffsets, NUM_SSAO_FILTERSAMPLES);
+	sCgCombineSsaoProgram->SetArray1f(i ++, (float *)ssaoFilterWeights, NUM_SSAO_FILTERSAMPLES);
 	
 	DrawQuad(sCgCombineSsaoProgram);
@@ -976,4 +964,10 @@
 	Matrix4x4 matViewing, matProjection;
 
+	// hack: temporarily change far to improve precision
+	const float oldFar = mCamera->GetFar();
+	mCamera->SetFar(1e3f);
+	//mCamera->SetFar(1e2f);
+
+
 	//mCamera->GetModelViewMatrix(matViewing);
 	mCamera->GetViewOrientationMatrix(matViewing);
@@ -1017,4 +1011,6 @@
 	glPushAttrib(GL_VIEWPORT_BIT);
 	glViewport(0, 0, mWidth, mHeight);
+	// revert to old far plane
+	mCamera->SetFar(oldFar);
 }
 
