Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.h
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.h	(revision 2991)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.h	(revision 2994)
@@ -105,6 +105,4 @@
 	Camera *mCamera;
 
-	FrameBufferObject *mFbo;
-
 	bool mUseTemporalCoherence;
 
@@ -116,4 +114,8 @@
 	bool mRegenerateSamples;
 
+	// the main fbo we are working with
+	FrameBufferObject *mFbo;
+
+	FrameBufferObject *mDownSampleFbo;
 };
 
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp	(revision 2992)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp	(revision 2994)
@@ -97,4 +97,17 @@
 SkyPreetham *preetham = NULL;
 
+/// the used render type for this render pass
+enum RenderMethod
+{
+	RENDER_FIXED,
+	RENDER_DEPTH_PASS,
+	RENDER_DEFERRED,
+	RENDER_DEPTH_PASS_DEFERRED,
+	RENDER_NUM_RENDER_TYPES
+};
+
+/// one of four possible render methods
+int renderMethod = RENDER_FIXED;
+
 
 /// these values get scaled with the frame rate
@@ -133,9 +146,4 @@
 int numBatches = 0;
 
-bool showHelp = false;
-bool showStatistics = false;
-bool showOptions = true;
-bool showBoundingVolumes = false;
-bool visMode = false;
 
 // mouse navigation state
@@ -146,9 +154,4 @@
 int horizontalMotionBegin = 0;
 
-bool useOptimization = false;
-bool useTightBounds = true;
-bool useRenderQueue = true;
-bool useMultiQueries = true;
-bool flyMode = true;
 
 bool leftKeyPressed = false;
@@ -159,12 +162,34 @@
 bool ascendKeyPressed = false;
 
+bool showHelp = false;
+bool showStatistics = false;
+bool showOptions = true;
+bool showBoundingVolumes = false;
+bool visMode = false;
+
+bool useOptimization = false;
+bool useTightBounds = true;
+bool useRenderQueue = true;
+bool useMultiQueries = true;
+bool flyMode = true;
+
 bool useGlobIllum = false;
 bool useTemporalCoherence = true;
+bool showAlgorithmTime = false;
+
+bool useFullScreen = false;
+bool useLODs = true;
+bool moveLight = false;
+
+bool useAdvancedShading = false;
+bool showShadowMap = false;
+bool renderLightView = false;
+
+bool altKeyPressed = false;
+
+bool useHDR = true;
 
 static float ssaoTempCohFactor = 255.0;
 
-bool showAlgorithmTime = false;
-
-GLubyte *randomNormals = NULL;
 
 PerfTimer frameTimer, algTimer;
@@ -172,36 +197,13 @@
 static int sCurrentMrtSet = 0;
 
-/// the used render type for this render pass
-enum RenderMethod
-{
-	RENDER_FIXED,
-	RENDER_DEPTH_PASS,
-	RENDER_DEFERRED,
-	RENDER_DEPTH_PASS_DEFERRED,
-	RENDER_NUM_RENDER_TYPES
-};
-
-/// one of four possible render methods
-int renderMethod = RENDER_FIXED;
-
 PerformanceGraph *perfGraph = NULL;
 
-bool useFullScreen = false;
-
-bool useLODs = true;
-
-bool moveLight = false;
 
 //DeferredRenderer::SAMPLING_METHOD samplingMethod = DeferredRenderer::SAMPLING_POISSON;
 DeferredRenderer::SAMPLING_METHOD samplingMethod = DeferredRenderer::SAMPLING_QUADRATIC;
 
-bool useAdvancedShading = false;
-
-bool showShadowMap = false;
-bool shadowChanged = true;
 
 static Matrix4x4 matProjectionView = IdentityMatrix();
 
-bool renderLightView = false;
 
 ShadowMap *shadowMap = NULL;
@@ -213,7 +215,4 @@
 SceneEntity *skyDome = NULL;
 
-bool altKeyPressed = false;
-
-#define USE_TONE_MAPPING 0
 
 
@@ -345,4 +344,6 @@
 		env.GetBoolParam(string("useLODs"), useLODs);
 		env.GetIntParam(string("shadowSize"), shadowSize);
+
+		env.GetBoolParam(string("useHDR"), useHDR);
 
 		//env.GetStringParam(string("modelPath"), model_path);
@@ -845,5 +846,5 @@
 	
 
-	const bool useToneMapping = ((renderMethod == RENDER_DEPTH_PASS_DEFERRED) || (renderMethod == RENDER_DEFERRED)) && USE_TONE_MAPPING;
+	const bool useToneMapping = ((renderMethod == RENDER_DEPTH_PASS_DEFERRED) || (renderMethod == RENDER_DEFERRED)) && useHDR;
 
 	Vector3 sunAmbient;
@@ -1190,5 +1191,5 @@
 
 		ShadowMap *sm = showShadowMap ? shadowMap : NULL;
-		ssaoShader->Render(fbo, oldViewProjMatrix, matProjectionView, ssaoTempCohFactor, light, USE_TONE_MAPPING, sm);
+		ssaoShader->Render(fbo, oldViewProjMatrix, matProjectionView, ssaoTempCohFactor, light, useHDR, sm);
 	}
 
@@ -1255,8 +1256,4 @@
 
 		break;
-	case 'h':
-	case 'H':
-		showHelp = !showHelp;
-		break;
 	case '+':
 		if (maxBatchSize < 10)
@@ -1364,4 +1361,8 @@
 	case 'L':
 		renderLightView = !renderLightView;
+		break;
+	case 'h':
+	case 'H':
+		useHDR = !useHDR;
 		break;
 	default:
@@ -2027,5 +2028,5 @@
 		state.SetRenderPassType(RenderState::DEFERRED);
 
-	const bool useToneMapping = ((renderMethod == RENDER_DEPTH_PASS_DEFERRED) || (renderMethod == RENDER_DEFERRED)) && USE_TONE_MAPPING;
+	const bool useToneMapping = ((renderMethod == RENDER_DEPTH_PASS_DEFERRED) || (renderMethod == RENDER_DEFERRED)) && useHDR;
 
 	preetham->RenderSkyDome(-light->GetDirection(), camera, &state, !useToneMapping);
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.cpp	(revision 2993)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.cpp	(revision 2994)
@@ -38,5 +38,4 @@
 
 
-static CGprogram sCgInitialIntensityProgram;
 static CGprogram sCgDownSampleProgram;
 static CGprogram sCgToneProgram;
@@ -129,5 +128,6 @@
 static CGparameter sColorsTexInitialParam;
 static CGparameter sColorsTexToneParam;
-static CGparameter sIntensityTexDownSampleParam;
+
+static CGparameter sColorsTexDownSampleParam;
 
 //#define USE_3D_SSAO
@@ -532,6 +532,5 @@
 		cerr << "tone program failed to load" << endl;
 
-/*
-	sCgInitialIntensityProgram = 
+	sCgDownSampleProgram = 
 		cgCreateProgramFromFile(context, 
 								CG_SOURCE,
@@ -541,15 +540,13 @@
 								NULL);
 
-	if (sCgInitialIntensityProgram != NULL)
-	{
-		cgGLLoadProgram(sCgInitialIntensityProgram);
+	if (sCgDownSampleProgram != NULL)
+	{
+		cgGLLoadProgram(sCgDownSampleProgram);
 
 		// we need size of texture for scaling
-		sColorsTexInitialParam = cgGetNamedParameter(sCgInitialIntensityProgram, "colors");  
+		sColorsTexDownSampleParam = cgGetNamedParameter(sCgDownSampleProgram, "colors");  
 	}
 	else
 		cerr << "intensity program failed to load" << endl;
-
-*/
 
 	PrintGLerror("init");
@@ -1236,5 +1233,4 @@
 
 	cgGLDisableTextureParameter(sColorsTexLogLumParam);
-
 	FrameBufferObject::Release();
 
@@ -1253,11 +1249,38 @@
 void DeferredRenderer::DownSample(FrameBufferObject *fbo)
 {
-	GLuint intensityTex=0;
+	ColorBufferObject *colorBuffer = fbo->GetColorBuffer(colorBufferIdx);
+	GLuint colorsTex = colorBuffer->GetTexture();
 	
 	cgGLEnableProfile(RenderState::sCgFragmentProfile);
 	cgGLBindProgram(sCgDownSampleProgram);
 	
-	cgGLSetTextureParameter(sIntensityTexDownSampleParam, intensityTex);
-	cgGLEnableTextureParameter(sIntensityTexDownSampleParam);
+	cgGLSetTextureParameter(sColorsTexDownSampleParam, colorsTex);
+	cgGLEnableTextureParameter(sColorsTexDownSampleParam);
+
+	mDownSampleFbo->Bind();
+
+	glDrawBuffers(1, mrt);
+	
+	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+
+	cgGLEnableProfile(RenderState::sCgFragmentProfile);
+	cgGLBindProgram(sCgDownSampleProgram);
+
+	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(sColorsTexDownSampleParam);
+
+	FrameBufferObject::Release();
+
+	PrintGLerror("ToneMapParams");
 }
 
@@ -1270,4 +1293,5 @@
 {
 	ColorBufferObject *colorBuffer = fbo->GetColorBuffer(colorBufferIdx);
+	GLuint colorsTex = colorBuffer->GetTexture();
 
 	fbo->Bind();
@@ -1275,7 +1299,4 @@
 	colorBufferIdx = 3 - colorBufferIdx;
 	glDrawBuffers(1, mrt + colorBufferIdx);
-
-
-	GLuint colorsTex = colorBuffer->GetTexture();
 	
 	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/default.env
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/default.env	(revision 2986)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/default.env	(revision 2994)
@@ -24,2 +24,4 @@
 # ssao temporal coherence factor
 tempCohFactor=50.0f
+
+useHDR=1
