Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaderenv.h
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaderenv.h	(revision 2968)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaderenv.h	(revision 2970)
@@ -33,14 +33,4 @@
 
 /////////
-//-- tone mapping
-
-//#define MIDDLE_GRAY 0.5f
-//#define MIDDLE_GRAY 0.72f
-#define MIDDLE_GRAY 0.36f
-//#define MIDDLE_GRAY 0.18f
-//#define MIDDLE_GRAY 0.18f
-
-
-/////////
 //-- shadowing
 
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/antialiasing.cg
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/antialiasing.cg	(revision 2969)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/antialiasing.cg	(revision 2970)
@@ -21,5 +21,5 @@
 
 
-float3 ToneMap(float imageKey, float whiteLum, float3 color)
+float3 ToneMap(float imageKey, float whiteLum, float middleGrey, float3 color)
 {
 	float3 outCol;
@@ -27,5 +27,5 @@
 	
 	// adjust to middle gray
-	const float lum = MIDDLE_GRAY * pixLum / imageKey;
+	const float lum = middleGrey * pixLum / imageKey;
 	 
 	// map to range and calc burnout
@@ -51,5 +51,6 @@
 			uniform sampler2D normals,
 			uniform float imageKey,
-			uniform float whiteLum
+			uniform float whiteLum,
+			uniform float middleGrey
 			): COLOR
 {
@@ -121,5 +122,5 @@
 
 	//return float4(w);
-	col.xyz = ToneMap(imageKey, whiteLum, col.xyz);
+	col.xyz = ToneMap(imageKey, whiteLum, middleGrey, col.xyz);
 
 	return col;
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ToneMapper.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ToneMapper.cpp	(revision 2968)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ToneMapper.cpp	(revision 2970)
@@ -36,10 +36,16 @@
 
 	static float previousKey = key;
-	const float factor = 1.0f;
+	const float factor = 0.5f;
 
-	const float imageKey = key;// * factor + previousKey * (1.0f - factor);
+	float imageKey;
+
+	if (key > 0)
+		imageKey = key * factor + previousKey * (1.0f - factor);
+	else 
+		imageKey = previousKey;
+
 	previousKey = imageKey;
 	
-	cout << "key: " << key << endl;
+	//cout << "key: " << key << endl;
 
 	return imageKey;
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SkyPreetham.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SkyPreetham.cpp	(revision 2968)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SkyPreetham.cpp	(revision 2970)
@@ -284,8 +284,8 @@
 	// downscale ambient color
 	//ambient *= 5e-5f;
-	//ambient *= 2e-3f;
+	ambient *= 1e-1f;
 
 	// simulate the sun intensity by modulating the ambient term.
-	//ambient *= (1.0f - 0.9f * DotProd(sunDir, Vector3::UNIT_Z()));
+	ambient *= (10.0f - 9.0f * DotProd(sunDir, Vector3::UNIT_Z()));
 	//ambient += Vector3(0.2f);
 
@@ -321,6 +321,8 @@
 
 	// Calculate final sun diffuse color.
-	//diffuse = color * 2e-3f;
-	diffuse = color;
+	diffuse = color * 3e-1f;
+	//diffuse *= (3.0f - 2.0f * DotProd(sunDir, Vector3::UNIT_Z()));
+	//diffuse = color;
+	
 
 	//cout << "diffuse: " << Magnitude(diffuse) << " ambient: " << Magnitude(ambient) << endl;
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.h
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.h	(revision 2965)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.h	(revision 2970)
@@ -78,5 +78,5 @@
 	void CombineIllum(FrameBufferObject *fbo);
 
-	void AntiAliasing(FrameBufferObject *fbo);
+	void AntiAliasing(FrameBufferObject *fbo, DirectionalLight *light);
 	/** Helper method that computes the view vectors in the corners of the current view frustum.
 	*/
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.cpp	(revision 2968)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.cpp	(revision 2970)
@@ -98,4 +98,5 @@
 static CGparameter sLightDirShadowParam;
 static CGparameter sImageKeyParam;
+static CGparameter sMiddleGreyParam;
 static CGparameter sWhiteLumParam;
 
@@ -408,4 +409,5 @@
 
 		sImageKeyParam = cgGetNamedParameter(sCgAntiAliasingProgram, "imageKey");
+		sMiddleGreyParam = cgGetNamedParameter(sCgAntiAliasingProgram, "middleGrey");
 		sWhiteLumParam = cgGetNamedParameter(sCgAntiAliasingProgram, "whiteLum");
 
@@ -513,5 +515,5 @@
 	}
 
-	AntiAliasing(fbo);
+	AntiAliasing(fbo, light);
 
 	glEnable(GL_LIGHTING);
@@ -668,5 +670,5 @@
 
 
-void DeferredRenderer::AntiAliasing(FrameBufferObject *fbo)
+void DeferredRenderer::AntiAliasing(FrameBufferObject *fbo, DirectionalLight *light)
 {
 	ColorBufferObject *colorBuffer = fbo->GetColorBuffer(colorBufferIdx);
@@ -679,6 +681,17 @@
 
 	const float imageKey = ToneMapper().CalcImageKey(pixels, w, h);
-	const float whiteLum = 0.5f * ToneMapper().CalcMaxLuminance(pixels, w, h);
-
+	const float whiteLum = 1.0f * ToneMapper().CalcMaxLuminance(pixels, w, h);
+
+	//const float minKey = 0.18f;
+	//const float maxKey = 0.72f;
+
+	//const float minKey = 0.0045f;
+	const float minKey = 0.09f;
+	const float maxKey = 0.5f;
+
+	const float lightIntensity = DotProd(-light->GetDirection(), Vector3::UNIT_Z());
+	const float middleGrey = lightIntensity * maxKey + (1.0f - lightIntensity) * minKey;
+
+	cout << "middlegrey: " << middleGrey << endl;
 	delete [] pixels;
 
@@ -699,4 +712,5 @@
 	cgGLSetParameter1f(sImageKeyParam, imageKey);
 	cgGLSetParameter1f(sWhiteLumParam, whiteLum);
+	cgGLSetParameter1f(sMiddleGreyParam, middleGrey);
 
 
@@ -889,6 +903,4 @@
 	GLuint colorsTex = fbo->GetColorBuffer(3)->GetTexture();
 
-	//GLuint ssaoTex = mNewFbo->GetColorBuffer(0)->GetTexture();
-	//GLuint illumTex = mNewFbo->GetColorBuffer(1)->GetTexture();
 	GLuint ssaoTex = mFbo->GetColorBuffer(mFboIndex)->GetTexture();
 	GLuint illumTex = mFbo->GetColorBuffer(mFboIndex + 1)->GetTexture();
