Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.cpp	(revision 2974)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.cpp	(revision 2975)
@@ -9,5 +9,4 @@
 #include "ShadowMapping.h"
 #include "Light.h"
-#include "ToneMapper.h"
 
 
@@ -553,9 +552,4 @@
 		FirstPass(fbo, light);
 
-	glEnable(GL_TEXTURE_2D);
-	// generate mip map levels for position texture
-	glBindTexture(GL_TEXTURE_2D, fbo->GetColorBuffer(colorBufferIdx)->GetTexture());
-	glGenerateMipmapEXT(GL_TEXTURE_2D);
-
 
 	switch (mShadingMethod)
@@ -576,4 +570,8 @@
 	float imageKey, whiteLum, middleGrey;
 
+	// generate mip map levels of position texture
+	glBindTexture(GL_TEXTURE_2D, fbo->GetColorBuffer(colorBufferIdx)->GetTexture());
+	glGenerateMipmapEXT(GL_TEXTURE_2D);
+
 	ComputeToneParameters(fbo, light, imageKey, whiteLum, middleGrey);
 	ToneMap(fbo, light, imageKey, whiteLum, middleGrey);
@@ -603,8 +601,9 @@
 {
 #ifdef USE_3D_SSAO
+	// bias from [-1, 1] to [0, 1]
 	static Matrix4x4 biasMatrix(0.5f, 0.0f, 0.0f, 0.5f,
 								0.0f, 0.5f, 0.0f, 0.5f,
 								0.0f, 0.0f, 0.5f, 0.5f,
-								0.0f, 0.0f, 0.0f, 1.0f); //bias from [-1, 1] to [0, 1]
+								0.0f, 0.0f, 0.0f, 1.0f); 
 
 	Matrix4x4 m = projViewMatrix * biasMatrix; 
@@ -615,9 +614,9 @@
 	cgGLSetMatrixParameterfc(sOldModelViewProjMatrixParam, (const float *)oldProjViewMatrix.x);
 
-	GLuint colorsTex = fbo->GetColorBuffer(3)->GetTexture();
+	GLuint colorsTex = fbo->GetColorBuffer(colorBufferIdx)->GetTexture();
 	GLuint positionsTex = fbo->GetColorBuffer(1)->GetTexture();
 	GLuint normalsTex = fbo->GetColorBuffer(2)->GetTexture();
 
-	// generate mip map levels for position texture
+	// generate mip map levels of position texture
 	glBindTexture(GL_TEXTURE_2D, positionsTex);
 	glGenerateMipmapEXT(GL_TEXTURE_2D);
@@ -628,6 +627,4 @@
 	glDrawBuffers(1, mrt + mFboIndex);
 
-
-	//GLuint oldTex = mOldFbo->GetColorBuffer(0)->GetTexture();
 	GLuint oldTex = mFbo->GetColorBuffer(2 - mFboIndex)->GetTexture();
 
@@ -677,12 +674,11 @@
 	glBegin(GL_QUADS);
 
-	// 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;
-	
-	glTexCoord2f(0, 0); glMultiTexCoord3fARB(GL_TEXTURE1_ARB, bl.x, bl.y, bl.z); glVertex3f(-new_offs, -new_offs, -0.5f);
-	glTexCoord2f(1, 0); glMultiTexCoord3fARB(GL_TEXTURE1_ARB, br.x, br.y, br.z); glVertex3f( new_offs, -new_offs, -0.5f);
-	glTexCoord2f(1, 1); glMultiTexCoord3fARB(GL_TEXTURE1_ARB, tr.x, tr.y, tr.z); glVertex3f( new_offs,  new_offs, -0.5f);
-	glTexCoord2f(0, 1); glMultiTexCoord3fARB(GL_TEXTURE1_ARB, tl.x, tl.y, tl.z); glVertex3f(-new_offs,  new_offs, -0.5f);
+	// note: slightly larger texture could hide ambient occlusion error on border but costs resolution
+	const float offs = 0.5f;
+	
+	glTexCoord2f(0, 0); glMultiTexCoord3fARB(GL_TEXTURE1_ARB, bl.x, bl.y, bl.z); glVertex3f(-offs, -offs, -0.5f);
+	glTexCoord2f(1, 0); glMultiTexCoord3fARB(GL_TEXTURE1_ARB, br.x, br.y, br.z); glVertex3f( offs, -offs, -0.5f);
+	glTexCoord2f(1, 1); glMultiTexCoord3fARB(GL_TEXTURE1_ARB, tr.x, tr.y, tr.z); glVertex3f( offs,  offs, -0.5f);
+	glTexCoord2f(0, 1); glMultiTexCoord3fARB(GL_TEXTURE1_ARB, tl.x, tl.y, tl.z); glVertex3f(-offs,  offs, -0.5f);
 
 	glEnd();
@@ -1133,19 +1129,10 @@
 											 float &middleGrey)
 {
-	ColorBufferObject *colorBuffer = fbo->GetColorBuffer(colorBufferIdx);
-
-	// we assume that we have a floating point rgba texture
-	float *pixels = (float *)colorBuffer->ReadTexture();
-	
-	const int w = colorBuffer->GetHeight();
-	const int h = colorBuffer->GetWidth();
-
-	imageKey = ToneMapper().CalcImageKey(pixels, w, h);
-	whiteLum = 1.0f * ToneMapper().CalcMaxLuminance(pixels, w, h);
-
-	//const float minKey = 0.18f;
-	//const float maxKey = 0.72f;
-
-	//const float minKey = 0.0045f;
+	// hack: estimate value where sky burns out
+	whiteLum = log(1e4f);
+	
+	////////////////////
+	//-- linear interpolate brightness key depending on the current sun position
+
 	const float minKey = 0.09f;
 	const float maxKey = 0.5f;
@@ -1153,61 +1140,4 @@
 	const float lightIntensity = DotProd(-light->GetDirection(), Vector3::UNIT_Z());
 	middleGrey = lightIntensity * maxKey + (1.0f - lightIntensity) * minKey;
-
-	//cout << "middlegrey: " << middleGrey << endl;
-	delete [] pixels;
-
-
-	/////////////
-
-	/*GLuint colorsTex = colorBuffer->GetTexture();
-
-	fbo->Bind();
-
-	colorBufferIdx = 3 - colorBufferIdx;
-	glDrawBuffers(1, mrt + colorBufferIdx);
-
-	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
-
-	cgGLEnableProfile(RenderState::sCgFragmentProfile);
-	cgGLBindProgram(sCgInitialIntensityProgram);
-	
-	cgGLSetTextureParameter(sColorsTexInitialParam, colorsTex);
-	cgGLEnableTextureParameter(sColorsTexInitialParam);
-
-	// first pass: create high res intensity texture
-	glColor3f(1.0f, 1.0f, 1.0f);
-
-	float offs2 = 0.5f;
-
-	glBegin(GL_QUADS);
-
-	// the neighbouring texels
-	float x_offs = 0;//1.0f / mWidth;
-	float y_offs = 0;//1.0f / mHeight;
-
-	SetVertex(0, 0, x_offs, y_offs);
-	SetVertex(1, 0, x_offs, y_offs);
-	SetVertex(1, 1, x_offs, y_offs);
-	SetVertex(0, 1, x_offs, y_offs);
-
-	glEnd();
-
-	cgGLDisableTextureParameter(sColorsTexToneParam);
-
-	FrameBufferObject::Release();
-
-	
-	////////////
-	//-- second phase: down sample the texture in order to compute the average
-	
-	// q: required passes for computing 1x1 texture?
-	int passes = 32;
-
-	for (int i = 0; i < 32; ++ i)
-	{
-		//DownSample(fbo);
-	}
-*/
-	PrintGLerror("antialiasing");
 }
 
