Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/Converter/ObjConverter.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/Converter/ObjConverter.cpp	(revision 2963)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/Converter/ObjConverter.cpp	(revision 2965)
@@ -32,6 +32,4 @@
 	vector<int> nIndices;
 	vector<int> tIndices;
-
-	//cout << "number of vertices=" << (int)vertices.size() << endl;
 
 	for (size_t i = 0; i < substrings.size(); ++ i)
@@ -142,5 +140,5 @@
 		geom->mNormals[i].z = faceNormals[i].y;
 
-		if (i <= geom->mTexcoordCount)
+		if (i < geom->mTexcoordCount)
 		{
 			geom->mTexcoords[i].first = faceTexcoords[i].first;
@@ -244,5 +242,5 @@
 					        faceVertices, faceNormals, faceTexcoords);
 
-				if (((line % 100) == 99) && 
+				if (((line % 1000) == 999) && 
 					!faceVertices.empty())
 				{
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/FrameBufferObject.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/FrameBufferObject.cpp	(revision 2899)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/FrameBufferObject.cpp	(revision 2965)
@@ -45,23 +45,55 @@
 
 ColorBufferObject::ColorBufferObject(int w, int h, 
+									 int attachment_idx,
 									 FORMAT format, 
 									 WRAP_TYPE wrapType, 
 									 FILTER_TYPE filterType, 
-									 bool useMipMap, 
-									 int attachment_idx)
-{
-	GLuint glformat, internalFormat;
-
+									 FILTER_TYPE filterTypeMipMap 
+									 )
+{
+	Init(w, h, attachment_idx, format, wrapType, filterType, true, filterTypeMipMap);
+}
+
+
+ColorBufferObject::ColorBufferObject(int w, int h, 
+									 int attachment_idx,
+									 FORMAT format, 
+									 WRAP_TYPE wrapType, 
+									 FILTER_TYPE filterType
+									 )
+{
+	Init(w, h, attachment_idx, format, wrapType, filterType, false, FILTER_NEAREST);
+}
+
+
+ColorBufferObject::~ColorBufferObject()
+{
+	glDeleteRenderbuffersEXT(1, &mId);
+	glDeleteTextures(1, &mTexId);
+}
+
+
+void ColorBufferObject::Init(int w, int h, 
+							 int attachment_idx,
+							 FORMAT format, 
+							 WRAP_TYPE wrapType, 
+							 FILTER_TYPE filterType, 
+							 bool useMipMap, 
+							 FILTER_TYPE filterTypeMipMap
+							 )
+{
+	mWidth = w;
+	mHeight = h;
 
 	switch (format)
 	{
 	case BUFFER_UBYTE:
-		glformat = GL_UNSIGNED_BYTE; internalFormat = GL_RGBA8; break;
+		mGlFormat = GL_UNSIGNED_BYTE; mInternalFormat = GL_RGBA8; break;
 	case BUFFER_FLOAT_16:
-		glformat = GL_FLOAT; internalFormat = GL_RGBA16F_ARB; break;
+		mGlFormat = GL_FLOAT; mInternalFormat = GL_RGBA16F_ARB; break;
 	case BUFFER_FLOAT_32: 
-		glformat = GL_FLOAT; internalFormat = GL_RGBA32F_ARB; break;
+		mGlFormat = GL_FLOAT; mInternalFormat = GL_RGBA32F_ARB; break;
 	default:
-		glformat = GL_UNSIGNED_BYTE; internalFormat = GL_RGBA8;
+		mGlFormat = GL_UNSIGNED_BYTE; mInternalFormat = GL_RGBA8;
 		cerr << "should not come here" << endl;
 	}
@@ -71,5 +103,5 @@
 	glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, mId);
 	
-	glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, internalFormat, w, h);
+	glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, mInternalFormat, w, h);
 	glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, mrt[attachment_idx], GL_RENDERBUFFER_EXT, mId);
 
@@ -77,5 +109,5 @@
 	glGenTextures(1, &mTexId);
 	glBindTexture(GL_TEXTURE_2D, mTexId);
-	glTexImage2D(GL_TEXTURE_2D, 0, internalFormat, w, h, 0, GL_RGBA, glformat, NULL);
+	glTexImage2D(GL_TEXTURE_2D, 0, mInternalFormat, w, h, 0, GL_RGBA, mGlFormat, NULL);
 
 	glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, mrt[attachment_idx], GL_TEXTURE_2D, mTexId, 0);
@@ -84,27 +116,34 @@
 	GLuint magfilterParam;
 
-	switch (filterType)
-	{
-	case FILTER_NEAREST:
-		minfilterParam = GL_NEAREST;
-		magfilterParam = GL_NEAREST; break;
-	case FILTER_LINEAR:
-		minfilterParam = GL_LINEAR;
-		magfilterParam = GL_LINEAR; break;
-	case FILTER_MIPMAP_LINEAR: 
-		minfilterParam = GL_NEAREST_MIPMAP_NEAREST;
-		magfilterParam = GL_NEAREST; 
-
-		//minfilterParam = GL_LINEAR_MIPMAP_NEAREST;
-		//magfilterParam = GL_LINEAR; 
-		break;
-	default:
-		minfilterParam = GL_NEAREST;
+	if (filterType == FILTER_NEAREST)
 		magfilterParam = GL_NEAREST;
-
-		cerr << "should not come here" << endl;
-	}
-
-	
+	else // FILTER_LINEAR
+		magfilterParam = GL_LINEAR; 
+
+	if (!useMipMap)
+	{
+		if (filterType == FILTER_NEAREST)
+			minfilterParam = GL_NEAREST;
+		else // FILTER_LINEAR
+			minfilterParam = GL_LINEAR;
+	}
+	else
+	{
+		if (filterType == FILTER_NEAREST)
+		{
+			if (filterTypeMipMap == FILTER_NEAREST)
+				minfilterParam = GL_NEAREST_MIPMAP_NEAREST;
+			else // FILTER_LINEAR
+				minfilterParam = GL_NEAREST_MIPMAP_LINEAR;
+		}
+		else // FILTER_LINEAR
+		{
+			if (filterTypeMipMap == FILTER_NEAREST)
+				minfilterParam = GL_LINEAR_MIPMAP_NEAREST;
+			else // FILTER_LINEAR
+				minfilterParam = GL_LINEAR_MIPMAP_LINEAR;
+		}
+	}
+
 	GLuint wrapParam;
 
@@ -130,9 +169,38 @@
 
 
-ColorBufferObject::~ColorBufferObject()
-{
-	glDeleteRenderbuffersEXT(1, &mId);
-	glDeleteTextures(1, &mTexId);
-}
+
+void *ColorBufferObject::ReadTexture() const
+{
+	int bytes = 0;
+
+	switch (mInternalFormat)
+	{
+	case GL_RGBA8:
+		bytes = 8; break;
+	case GL_RGBA16F_ARB:
+		bytes = 16; break;
+	case GL_RGBA32F_ARB: 
+		bytes = 32; break;
+	default:
+		cerr << "should not come here" << endl;
+	}
+
+	unsigned char *data = new unsigned char[bytes * 4 * mWidth * mHeight];
+
+	glEnable(GL_TEXTURE_2D);
+	glBindTexture(GL_TEXTURE_2D, mTexId);
+
+	glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, mGlFormat, data);
+
+	glBindTexture(GL_TEXTURE_2D, 0);
+	glDisable(GL_TEXTURE_2D);
+
+	return data;
+}
+
+
+/*****************************************************************/
+/*                 FrameBufferObject implementation              */
+/*****************************************************************/
 
 
@@ -143,5 +211,4 @@
 	
 	Bind();
-
 	///////////
 	//-- create depth buffer
@@ -181,4 +248,5 @@
 			glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
 			glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+
 			glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
 
@@ -207,5 +275,5 @@
 									  ColorBufferObject::WRAP_TYPE wrapType, 
 									  ColorBufferObject::FILTER_TYPE filterType, 
-									  bool useMipMap)
+									  ColorBufferObject::FILTER_TYPE filterTypeMipMap)
 {
 	Bind();
@@ -214,5 +282,5 @@
 
 	ColorBufferObject *colorBuf = 
-		new ColorBufferObject(mWidth, mHeight, col, wrapType, filterType, useMipMap, idx);
+		new ColorBufferObject(mWidth, mHeight, idx, col, wrapType, filterType, filterTypeMipMap);
 
 	mColorBuffers.push_back(colorBuf);
@@ -224,4 +292,24 @@
 
 
+
+int FrameBufferObject::AddColorBuffer(ColorBufferObject::FORMAT col, 
+									  ColorBufferObject::WRAP_TYPE wrapType, 
+									  ColorBufferObject::FILTER_TYPE filterType)
+{
+	Bind();
+
+	const int idx = (int)mColorBuffers.size();
+
+	ColorBufferObject *colorBuf = 
+		new ColorBufferObject(mWidth, mHeight, idx, col, wrapType, filterType);
+
+	mColorBuffers.push_back(colorBuf);
+
+	Release();
+
+	return idx;
+}
+
+
 void FrameBufferObject::Bind() const
 {
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg	(revision 2959)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg	(revision 2965)
@@ -186,2 +186,22 @@
 	return OUT;
 }
+
+
+/*float4 FinalPass( SkyboxVS_Output Input ) : COLOR
+{
+	float4 vColor = tex2D( s0, Input.Tex );
+	float3 vBloom = tex2D( s1, Input.Tex );
+
+	float vLum = g_fImageKey;
+	vColor.rgb = vColor; 
+	 
+    // Tone mapping
+    vColor.rgb *= g_fMiddleGray /(vLum + 0.001f);
+    vColor.rgb *= (1.0f + vColor/LUM_WHITE);
+	vColor.rgb /= (1.0f + vColor);
+	
+	vColor.rgb += 0.6f * vBloom;
+	vColor.a = 1.0f;
+	
+	return vColor;
+}*/
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/mrt.cg
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/mrt.cg	(revision 2964)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/mrt.cg	(revision 2965)
@@ -72,10 +72,8 @@
 	pixel pix;
 
-	//float4 dirtTexColor = tex2D(dirtTex, IN.texCoord.xy);
 	float4 texColor = tex2D(tex, IN.texCoord.xy);
 
 	// save color in first render target
 	// hack: use comination of emmisive + diffuse (emmisive used as constant ambient term)
-	//pix.col = (glstate.material.emission + glstate.material.diffuse) * texColor * dirtTexColor; 
 	pix.col = (glstate.material.emission + glstate.material.diffuse) * texColor; 
 	
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ToneMapper.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ToneMapper.cpp	(revision 2965)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ToneMapper.cpp	(revision 2965)
@@ -0,0 +1,100 @@
+#include "ToneMapper.h"
+#include "FrameBufferObject.h"
+
+
+namespace CHCDemoEngine 
+{
+
+ToneMapper::ToneMapper(): mImageKey(.0f), mPreviousImageKey(.0f), mCurrentImageKey(.0f)
+{
+}
+
+
+bool ToneMapper::CalcLuminance(ColorBufferObject *colorBuffer)
+{
+	int i = 0, j = 0;
+	float Rfloat, Gfloat, Bfloat;
+
+	int pixRGBE;
+
+	float pixLum = 0; 
+	float totalLum = 0;
+	float pixNum = 0;
+	
+	float *pixels = (float *)colorBuffer->ReadTexture();
+
+	/*
+	V_RETURN( pd3dDevice->GetRenderTargetData( pSourceRenderTarget, pPixelData ) );
+	 
+	D3DSURFACE_DESC descSrc;
+    pPixelData->GetDesc( &descSrc );
+	
+	number_of_pixels = (float)(descSrc.Height * descSrc.Width);
+
+	// Lock the source texture for reading
+    D3DLOCKED_RECT rcSrc;
+    V_RETURN( pPixelData->LockRect( &rcSrc, NULL, D3DLOCK_READONLY ) );
+	
+	// Location of texture data
+	D3DXFLOAT16* pSourcePixels = (D3DXFLOAT16*)rcSrc.pBits;
+
+	int localwidth = descSrc.Width;
+	int localheight = descSrc.Height; 	
+	g_start = g_myTimer.GetTime();
+	
+	// Get full scene luminance
+	for( i = 0; i < localheight; i++ )
+	{
+		for( j = 0; j < localwidth; j++ )
+		{
+			RGBEpixel = i * (localwidth) + j;
+			Rfloat =(float)pSourcePixels[4*RGBEpixel + 0]/255;
+			Gfloat =(float)pSourcePixels[4*RGBEpixel + 1]/255;
+			Bfloat =(float)pSourcePixels[4*RGBEpixel + 2]/255;
+
+			PixelLuminance = 0.2125f * Rfloat + 0.7154f * Gfloat + 0.0721f * Bfloat;
+
+			TotalLuminance += (PixelLuminance + 0.001f);
+		}
+	}
+
+	g_stop = g_myTimer.GetTime();
+
+	g_dLumCalcTime = (double)g_stop - (double)g_start;	
+
+	pPixelData->UnlockRect();	
+	
+
+	g_fCurrentImageKey = (1/number_of_pixels) * TotalLuminance;
+
+	if(g_firstrun)
+	{
+		g_fPreviousImageKey = g_fCurrentImageKey;
+		g_firstrun = !g_firstrun;
+	}
+
+	float diff = (g_fCurrentImageKey - g_fPreviousImageKey);
+
+	// Constrain the luminance change to be more realistic
+	if (diff > 0.05f)
+	{
+		g_fImageKey = g_fPreviousImageKey + 0.05f;
+		g_fPreviousImageKey = g_fImageKey;
+	}
+	else if (diff < -0.05f)
+	{
+		g_fImageKey = g_fPreviousImageKey - 0.05f;
+		g_fPreviousImageKey = g_fImageKey;
+	}
+	else
+	{
+		g_fImageKey = g_fCurrentImageKey;
+		g_fPreviousImageKey = g_fImageKey;
+	}
+	
+	return S_OK;
+	*/
+	return true;
+}
+
+}
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderState.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderState.cpp	(revision 2964)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderState.cpp	(revision 2965)
@@ -14,5 +14,4 @@
 CGprogram RenderState::sCgMrtFragmentTexProgram = NULL;
 CGparameter RenderState::sTexParam;
-CGparameter RenderState::sDirtTexParamTex;
 
 
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SceneQuery.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SceneQuery.cpp	(revision 2957)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SceneQuery.cpp	(revision 2965)
@@ -11,12 +11,8 @@
 
 
-
-
 using namespace std;
 
 const static int texWidth = 2048;
 const static int texHeight = 2048;
-
-
 
 
@@ -143,5 +139,8 @@
 
 	FrameBufferObject *fbo = new FrameBufferObject(texWidth, texHeight, FrameBufferObject::DEPTH_32, true);
-	fbo->AddColorBuffer(ColorBufferObject::BUFFER_UBYTE, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_NEAREST, false);
+	fbo->AddColorBuffer(ColorBufferObject::BUFFER_UBYTE, 
+		                ColorBufferObject::WRAP_CLAMP_TO_EDGE, 
+						ColorBufferObject::FILTER_NEAREST,
+						ColorBufferObject::FILTER_NEAREST);
 
 
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ShadowMapping.h
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ShadowMapping.h	(revision 2963)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ShadowMapping.h	(revision 2965)
@@ -3,10 +3,6 @@
 
 #include "common.h"
-#include "glInterface.h"
 #include "AxisAlignedBox3.h"
 #include "Matrix4x4.h"
-
-#include <Cg/cg.h>
-#include <Cg/cgGL.h>
 
 
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.h
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.h	(revision 2957)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.h	(revision 2965)
@@ -82,6 +82,5 @@
 	*/
 	void ComputeViewVectors(Vector3 &tl, Vector3 &tr, Vector3 &bl, Vector3 &br);
-
-
+	
 
 	////////////
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ToneMapper.h
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ToneMapper.h	(revision 2965)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ToneMapper.h	(revision 2965)
@@ -0,0 +1,32 @@
+#ifndef __TONEMAPPER_H
+#define __TONEMAPPER_H
+
+#include "common.h"
+
+namespace CHCDemoEngine 
+{
+
+class ColorBufferObject;
+
+/** Class representing a tone mapping algorithm
+*/
+class ToneMapper
+{
+public:
+	
+	ToneMapper();
+	/** Caculates scene luminance.
+	*/
+	bool CalcLuminance(ColorBufferObject *colorBuffer);
+
+
+protected:
+
+	float mImageKey;
+	float mPreviousImageKey;
+	float mCurrentImageKey;
+};
+
+}
+
+#endif // __TONEMAPPER_H
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderState.h
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderState.h	(revision 2964)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderState.h	(revision 2965)
@@ -83,6 +83,4 @@
 	static CGparameter sTexParam;
 
-	static CGparameter sDirtTexParamTex;
-
 protected:
 
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Material.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Material.cpp	(revision 2964)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Material.cpp	(revision 2965)
@@ -65,5 +65,4 @@
 			cgGLSetTextureParameter(RenderState::sTexParam, mTexture->GetId());
 			cgGLEnableTextureParameter(RenderState::sTexParam);
-			cgGLEnableTextureParameter(RenderState::sDirtTexParamTex);
 		}
 		else
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ShadowMapping.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ShadowMapping.cpp	(revision 2963)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ShadowMapping.cpp	(revision 2965)
@@ -141,6 +141,10 @@
 {
 	mFbo = new FrameBufferObject(size, size, FrameBufferObject::DEPTH_32, true);
+
 	// need a color buffer to keep opengl happy
-	mFbo->AddColorBuffer(ColorBufferObject::BUFFER_UBYTE, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_LINEAR, false);
+	mFbo->AddColorBuffer(ColorBufferObject::BUFFER_UBYTE,
+		                 ColorBufferObject::WRAP_CLAMP_TO_EDGE, 
+						 ColorBufferObject::FILTER_NEAREST);
+
 
 	mShadowCam = new Camera(mSize, mSize);
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp	(revision 2964)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp	(revision 2965)
@@ -168,5 +168,4 @@
 PerfTimer frameTimer, algTimer;
 
-Texture *dirtTexture = NULL;
 
 
@@ -458,8 +457,4 @@
 	camera->SetFar(Magnitude(bvh->GetBox().Diagonal()));
 	
-	dirtTexture = new Texture(model_path + "waterstain.jpg");
-	//dirtTexture = new Texture(model_path + "dirt.jpg");
-	dirtTexture->Create();
-
 	InitCg();
 
@@ -580,9 +575,5 @@
 
 		sMaxDepthParamTex = cgGetNamedParameter(RenderState::sCgMrtFragmentTexProgram, "maxDepth");
-		RenderState::sDirtTexParamTex = cgGetNamedParameter(RenderState::sCgMrtFragmentTexProgram, "dirtTex");
 		RenderState::sTexParam = cgGetNamedParameter(RenderState::sCgMrtFragmentTexProgram, "tex");
-
-		cgGLEnableTextureParameter(RenderState::sDirtTexParamTex);
-		cgGLSetTextureParameter(RenderState::sDirtTexParamTex, dirtTexture->GetId());
 
 		cgGLSetParameter1f(sMaxDepthParamTex, MAX_DEPTH_CONST / farDist);
@@ -625,16 +616,16 @@
 
 	// the diffuse color buffer
-	fbo->AddColorBuffer(ColorBufferObject::BUFFER_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_MIPMAP_LINEAR, true);
+	fbo->AddColorBuffer(ColorBufferObject::BUFFER_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_NEAREST, ColorBufferObject::FILTER_NEAREST);
 	//fbo->AddColorBuffer(ColorBufferObject::BUFFER_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_NEAREST, false);
 
 	// the positions buffer
-	fbo->AddColorBuffer(ColorBufferObject::BUFFER_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_MIPMAP_LINEAR, true);
+	fbo->AddColorBuffer(ColorBufferObject::BUFFER_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_NEAREST, ColorBufferObject::FILTER_NEAREST);
 	//fbo->AddColorBuffer(ColorBufferObject::BUFFER_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_NEAREST, false);
 
 	// the normals buffer
-	fbo->AddColorBuffer(ColorBufferObject::BUFFER_FLOAT_16, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_NEAREST, false);
+	fbo->AddColorBuffer(ColorBufferObject::BUFFER_FLOAT_16, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_NEAREST, ColorBufferObject::FILTER_NEAREST);
 
 	// another color buffer
-	fbo->AddColorBuffer(ColorBufferObject::BUFFER_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_NEAREST, false);
+	fbo->AddColorBuffer(ColorBufferObject::BUFFER_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_NEAREST, ColorBufferObject::FILTER_NEAREST);
 
 	PrintGLerror("fbo");
@@ -659,5 +650,5 @@
 void InitGLstate() 
 {
-	glClearColor(1.4f, 0.4f, 0.4f, 1.0f);
+	glClearColor(0.4f, 0.4f, 0.4f, 1.0f);
 	
 	glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.cpp	(revision 2952)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.cpp	(revision 2965)
@@ -229,4 +229,5 @@
 	CreateNoiseTex2D(w, h);
 
+
 	///////////
 	//-- the flip-flop fbos
@@ -234,8 +235,8 @@
 	mFbo = new FrameBufferObject(w, h, FrameBufferObject::DEPTH_NONE);
 
-	mFbo->AddColorBuffer(ColorBufferObject::BUFFER_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_LINEAR, false);
-	mFbo->AddColorBuffer(ColorBufferObject::BUFFER_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_LINEAR, false);
-	mFbo->AddColorBuffer(ColorBufferObject::BUFFER_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_LINEAR, false);
-	mFbo->AddColorBuffer(ColorBufferObject::BUFFER_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_LINEAR, false);
+	mFbo->AddColorBuffer(ColorBufferObject::BUFFER_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_LINEAR);
+	mFbo->AddColorBuffer(ColorBufferObject::BUFFER_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_LINEAR);
+	mFbo->AddColorBuffer(ColorBufferObject::BUFFER_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_LINEAR);
+	mFbo->AddColorBuffer(ColorBufferObject::BUFFER_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_LINEAR);
 }
 
@@ -1054,3 +1055,7 @@
 }
 
+
+
+
+
 } // namespace
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/FrameBufferObject.h
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/FrameBufferObject.h	(revision 2957)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/FrameBufferObject.h	(revision 2965)
@@ -16,22 +16,58 @@
 
 	enum FORMAT { BUFFER_UBYTE, BUFFER_FLOAT_16, BUFFER_FLOAT_32 };
-	enum WRAP_TYPE{ WRAP_REPEAT, WRAP_CLAMP_TO_EDGE };
-	enum FILTER_TYPE { FILTER_NEAREST, FILTER_LINEAR, FILTER_MIPMAP_LINEAR };
+	enum WRAP_TYPE { WRAP_REPEAT, WRAP_CLAMP_TO_EDGE };
+	enum FILTER_TYPE { FILTER_NEAREST, FILTER_LINEAR };
 
+
+	/** Creates color buffer without mipmap. attachment_idx describes
+		the number of the render target the buffer is attached to
+	*/
 	ColorBufferObject(int w, int h, 
-		              FORMAT c, 
+		              int attachment_idx  ,           
+					  FORMAT c, 
+					  WRAP_TYPE wrapType, 
+					  FILTER_TYPE filterType);
+
+	/** Same as above, with mipmapping enabled.
+	*/
+	ColorBufferObject(int w, int h, 
+		              int attachment_idx,        
+					  FORMAT c, 
 					  WRAP_TYPE wrapType, 
 					  FILTER_TYPE filterType, 
-					  bool useMipMap, 
-					  int attachment_idx);
+					  FILTER_TYPE filterTypeMipMap
+					  );
 
 	~ColorBufferObject();
 
-	unsigned int GetTexture() const {return mTexId;}
+	unsigned int GetTexture() const { return mTexId; }
+
+	/** Returns texture data.
+	*/
+	void *ReadTexture() const;
+
 
 protected:
 
+	void Init(int w, int h, 
+		      int attachment_idx,
+		      FORMAT format, 
+			  WRAP_TYPE wrapType, 
+			  FILTER_TYPE filterType, 
+			  bool useMipMap, 
+			  FILTER_TYPE filterTypeMipMap
+			  );
+
+
+
+	///////////
+
+	int mGlFormat;
+	int mInternalFormat;
 	unsigned int mId;
 	unsigned int mTexId;
+
+	int mWidth;
+	int mHeight;
 };
 
@@ -43,5 +79,5 @@
 public:
 
-	enum DEPTH_FORMAT { DEPTH_NONE, DEPTH_16, DEPTH_24, DEPTH_32 };
+	enum DEPTH_FORMAT {DEPTH_NONE, DEPTH_16, DEPTH_24, DEPTH_32};
 
 	/** constructor requesting an opengl occlusion query.
@@ -55,6 +91,12 @@
 	int AddColorBuffer(ColorBufferObject::FORMAT col, 
 		               ColorBufferObject::WRAP_TYPE wrapType, 
-					   ColorBufferObject::FILTER_TYPE filterType, 
-					   bool useMipMap);
+					   ColorBufferObject::FILTER_TYPE filterType);
+
+	/** Same as above, but enables mipmapping using the specified filter.
+	*/
+	int AddColorBuffer(ColorBufferObject::FORMAT col, 
+		               ColorBufferObject::WRAP_TYPE wrapType, 
+					   ColorBufferObject::FILTER_TYPE filterType,
+					   ColorBufferObject::FILTER_TYPE filterTypeMipMap);
 
 	/** Returns the color buffer object on position i.
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/FriendlyCulling.vcproj
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/FriendlyCulling.vcproj	(revision 2961)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/FriendlyCulling.vcproj	(revision 2965)
@@ -283,4 +283,12 @@
 				>
 			</File>
+			<File
+				RelativePath=".\src\ToneMapper.cpp"
+				>
+			</File>
+			<File
+				RelativePath=".\src\ToneMapper.h"
+				>
+			</File>
 			<Filter
 				Name="timer"
