Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg	(revision 2991)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg	(revision 2992)
@@ -76,12 +76,10 @@
 	// an ambient color term
 	float amb = color.w;
-
 	float3 normal = normalize(norm.xyz);
-
 	float4 col = shade(IN, color, position, normal, amb, lightDir);
 	
 	OUT.color = col;
 	
-#if 0
+#if 1
 
 	OUT.color.w = color.w;
@@ -217,8 +215,6 @@
 	//-- write out logaritmic luminance for tone mapping
 
-#if 0
-
+#if 1
 	OUT.color.w = color.w;
-
 #else
 
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/tonemap.cg
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/tonemap.cg	(revision 2991)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/tonemap.cg	(revision 2992)
@@ -114,6 +114,9 @@
 	pixel OUT;
 
+	float4 color = tex2Dlod(colors, float4(IN.texCoord.xy, 0, 0));
+
+	OUT.col = color;
+
 	// the old loglum is stored in the hightest mipmap-level
-	float4 color = tex2Dlod(colors, float4(IN.texCoord.xy, 0, 0));
 	float oldLogLum = tex2Dlod(colors, float4(IN.texCoord.xy, 0, MAX_LOD_LEVEL)).w;
 
@@ -127,9 +130,9 @@
 	float logLumScaled = logLum * INV_LOGLUM_RANGE - logLumOffset;
 
-	OUT.color = color;
+	if (oldLogLum > 0)
+		OUT.col.w = lerp(oldLogLum, logLumScaled, 0.1f);
+	else
+		OUT.col.w = logLumScaled;
 
-	if (oldLogLum > 0)
-		OUT.color.w = lerp(oldLogLum, logLumScaled, 0.1f);
-	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 2991)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg	(revision 2992)
@@ -42,4 +42,5 @@
 
 
+// reconstruct world space position
 inline float3 ReconstructSamplePosition(float3 eyePos, 
 										uniform sampler2D colors,
@@ -47,10 +48,9 @@
 										float3 bl, float3 br, float3 tl, float3 tr)
 {
-	/*float eyeSpaceDepth = tex2Dlod(colors, float4(texcoord, 0, SSAO_MIPMAP_LEVEL)).w;
-		
-	// reconstruct world space position
+	float eyeSpaceDepth = tex2Dlod(colors, float4(texcoord, 0, SSAO_MIPMAP_LEVEL)).w;
 	float3 rotView = normalize(Interpol(texcoord, bl, br, tl, tr));
-	float3 sample_position = eyePos - rotView * eyeSpaceDepth;*/
-	float3 sample_position = tex2Dlod(colors, float4(texcoord, 0, SSAO_MIPMAP_LEVEL)).xyz;
+	
+	float3 sample_position = eyePos - rotView * eyeSpaceDepth;
+	//float3 sample_position = tex2Dlod(colors, float4(texcoord, 0, SSAO_MIPMAP_LEVEL)).xyz;
 
 	return sample_position;
@@ -174,5 +174,5 @@
 
 	//const float2 ao = ssao(IN, positions, noiseTexture, samples, normal, centerPosition, w, viewDir, eyePos);
-	const float2 ao = ssao(IN, positions, noiseTexture, samples, normal, centerPosition, w, eyePos, bl, br, tl, tr);
+	const float2 ao = ssao(IN, colors, noiseTexture, samples, normal, centerPosition, w, eyePos, bl, br, tl, tr);
 		
 
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp	(revision 2991)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp	(revision 2992)
@@ -215,5 +215,5 @@
 bool altKeyPressed = false;
 
-#define USE_TONE_MAPPING 1
+#define USE_TONE_MAPPING 0
 
 
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.cpp	(revision 2991)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.cpp	(revision 2992)
@@ -34,8 +34,13 @@
 static CGprogram sCgCombinedIllumProgram = NULL;
 
+static CGparameter sColorsTexLogLumParam;
+
+
 
 static CGprogram sCgInitialIntensityProgram;
 static CGprogram sCgDownSampleProgram;
 static CGprogram sCgToneProgram;
+static CGprogram sCgLogLumProgram;
+
 
 
@@ -143,4 +148,5 @@
 int DeferredRenderer::colorBufferIdx = 0;
 
+
 static void PrintGLerror(char *msg)
 {
@@ -153,16 +159,4 @@
 		fprintf(stderr,"OpenGL ERROR: %s: %s\n", errStr, msg);
 	}
-}
-
-static int computeSize(int level)
-{
-	// Compute total image size.
-	float w = 1024;
-	float h = 768;
-
-	int mipmapSize = max(1, w / (1 << level) ) * 
-		             max(1, h / (1 << level) ) * sizeof(float) * 4;
-
-	return mipmapSize;
 }
 
@@ -323,5 +317,4 @@
 		sPositionsTexDeferredParam = cgGetNamedParameter(sCgDeferredProgram, "positions");  
 		sColorsTexDeferredParam = cgGetNamedParameter(sCgDeferredProgram, "colors");  
-		//sOldColorsTexDeferredParam = cgGetNamedParameter(sCgDeferredProgram, "oldColors");
 		sNormalsTexDeferredParam = cgGetNamedParameter(sCgDeferredProgram, "normals");
 		
@@ -492,6 +485,4 @@
 		sSamplesShadowParam = cgGetNamedParameter(sCgDeferredShadowProgram, "samples");
 		sLightDirShadowParam = cgGetNamedParameter(sCgDeferredShadowProgram, "lightDir");
-		//sOldColorsTexShadowParam = cgGetNamedParameter(sCgDeferredShadowProgram, "oldColors");
-
 
 		PoissonDiscSampleGenerator2 poisson(NUM_PCF_TABS, 1.0f);
@@ -502,4 +493,21 @@
 	else
 		cerr << "deferred program failed to load" << endl;
+
+	sCgLogLumProgram = 
+		cgCreateProgramFromFile(context, 
+								CG_SOURCE,
+								"src/shaders/tonemap.cg", 
+								RenderState::sCgFragmentProfile,
+								"CalcAvgLogLum",
+								NULL);
+
+	if (sCgLogLumProgram != NULL)
+	{
+		cgGLLoadProgram(sCgLogLumProgram);
+		sColorsTexLogLumParam = cgGetNamedParameter(sCgLogLumProgram, "colors");  
+	}
+	else
+		cerr << "avg loglum program failed to load" << endl;
+
 
 	sCgToneProgram = 
@@ -524,4 +532,5 @@
 		cerr << "tone program failed to load" << endl;
 
+/*
 	sCgInitialIntensityProgram = 
 		cgCreateProgramFromFile(context, 
@@ -542,5 +551,5 @@
 		cerr << "intensity program failed to load" << endl;
 
-
+*/
 
 	PrintGLerror("init");
@@ -655,9 +664,7 @@
 	GLuint normalsTex = fbo->GetColorBuffer(2)->GetTexture();
 
-	// generate mip map levels of position texture
-	glBindTexture(GL_TEXTURE_2D, positionsTex);
-	glGenerateMipmapEXT(GL_TEXTURE_2D);
-	
-
+	// generate mip map levels of position in order to improve texture lookup performance
+	//glBindTexture(GL_TEXTURE_2D, positionsTex); glGenerateMipmapEXT(GL_TEXTURE_2D);
+	
 	// read the second buffer, write to the first buffer
 	mFbo->Bind();
@@ -743,16 +750,4 @@
 
 
-Vector3 Interpol(float wx, float wy, Vector3 bl, Vector3 br, Vector3 tl, Vector3 tr)
-{
-	//float3 x1 = lerp(oldColor.w, logLumScaled, 0.1f);
-	Vector3 x1 = bl * (1.0f - wx) + br * wx;
-	Vector3 x2 = tl * (1.0f - wx) + tr * wx;
-
-	Vector3 v = x1 * (1.0f - wy) + x2 * wy;
-
-	return v;
-}
-
-
 void DeferredRenderer::ComputeViewVectors(Vector3 &tl, Vector3 &tr, Vector3 &bl, Vector3 &br)
 {
@@ -830,6 +825,4 @@
 	GLuint normalsTex = fbo->GetColorBuffer(2)->GetTexture();
 
-	//GLuint oldColorsTex = fbo->GetColorBuffer(3 - colorBufferIdx)->GetTexture();
-
 	fbo->Bind();
 
@@ -845,7 +838,4 @@
 	cgGLSetTextureParameter(sColorsTexDeferredParam, colorsTex);
 	cgGLEnableTextureParameter(sColorsTexDeferredParam);
-
-	//cgGLSetTextureParameter(sOldColorsTexDeferredParam, oldColorsTex);
-	//cgGLEnableTextureParameter(sOldColorsTexDeferredParam);
 
 	cgGLSetTextureParameter(sPositionsTexDeferredParam, positionsTex);
@@ -873,5 +863,4 @@
 
 	cgGLDisableTextureParameter(sColorsTexDeferredParam);
-	//cgGLDisableTextureParameter(sOldColorsTexDeferredParam);
 	cgGLDisableTextureParameter(sPositionsTexDeferredParam);
 	cgGLDisableTextureParameter(sNormalsTexDeferredParam);
@@ -1111,6 +1100,4 @@
 	GLuint shadowTex = shadowMap->GetDepthTexture();
 
-	//GLuint oldColorsTex = fbo->GetColorBuffer(3 - colorBufferIdx)->GetTexture();
-
 	Matrix4x4 shadowMatrix;
 	shadowMap->GetTextureMatrix(shadowMatrix);
@@ -1136,10 +1123,6 @@
 	cgGLEnableTextureParameter(sShadowMapParam);
 
-	//cgGLSetTextureParameter(sOldColorsTexShadowParam, oldColorsTex);
-	//cgGLEnableTextureParameter(sOldColorsTexShadowParam);
-
 	cgGLSetParameter1f(sMaxDepthShadowParam, mScaleFactor);
 
-	//cgGLSetParameter1f(sSampleWidthParam, 10.0f / shadowMap->GetSize());
 	cgGLSetParameter1f(sSampleWidthParam, 2.0f / shadowMap->GetSize());
 	
@@ -1172,5 +1155,4 @@
 	cgGLDisableTextureParameter(sShadowMapParam);
 	cgGLDisableTextureParameter(sNoiseTexShadowParam);
-	//cgGLDisableTextureParameter(sOldColorsTexShadowParam);
 
 	FrameBufferObject::Release();
@@ -1218,4 +1200,5 @@
 	middleGrey = lightIntensity * maxKey + (1.0f - lightIntensity) * minKey;
 
+#if 1
 
 	//////////
@@ -1223,4 +1206,5 @@
 
 	ColorBufferObject *colorBuffer = fbo->GetColorBuffer(colorBufferIdx);
+	GLuint colorsTex = colorBuffer->GetTexture();
 
 	fbo->Bind();
@@ -1228,20 +1212,14 @@
 	colorBufferIdx = 3 - colorBufferIdx;
 	glDrawBuffers(1, mrt + colorBufferIdx);
-
-	GLuint colorsTex = colorBuffer->GetTexture();
-	
+	
+
 	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
 
 	cgGLEnableProfile(RenderState::sCgFragmentProfile);
-	cgGLBindProgram(sCgToneProgram);
+	cgGLBindProgram(sCgLogLumProgram);
 	
 	cgGLSetTextureParameter(sColorsTexLogLumParam, colorsTex);
-	
-	glColor3f(1.0f, 1.0f, 1.0f);
-
-	glBegin(GL_QUADS);
-
-	glColor3f(1.0f, 1.0f, 1.0f);
-
+	cgGLEnableTextureParameter(sColorsTexLogLumParam);
+	
 	const float offs = 0.5f;
 
@@ -1261,4 +1239,5 @@
 	PrintGLerror("ToneMapParams");
 
+#endif
 
 	///////////////////
