Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/tonemap.cg
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/tonemap.cg	(revision 3005)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/tonemap.cg	(revision 3006)
@@ -28,10 +28,10 @@
     for(int i = 0; i < 4; ++ i)
     {
-        average += tex2D(colors, IN.texCoord + downSampleOffs[i]);
+        average += tex2Dlod(colors, float4(IN.texCoord + downSampleOffs[i],0,0));
     }
         
     average *= 1.0f / 4.0f;
 
-    return tex2D(colors, IN.texCoord);//average;
+    return average;
 }
     
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg	(revision 3005)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg	(revision 3006)
@@ -6,5 +6,5 @@
 
 
-#define USE_EYE_SPACE_DEPTH 0
+#define USE_EYE_SPACE_DEPTH 1
 
 
@@ -71,5 +71,5 @@
 		   uniform float2 samples[NUM_SAMPLES],
 		   uniform float3 currentNormal,
-		   uniform float4 centerPosition,
+		   uniform float3 centerPosition,
 		   uniform float scaleFactor,
 		   uniform float3 eyePos,
@@ -161,9 +161,7 @@
 	pixel OUT;
 
-	float4 norm = tex2D(normals, IN.texCoord.xy);
+	float4 norm = tex2Dlod(normals, float4(IN.texCoord, 0 ,0));
 	float3 normal = normalize(norm.xyz);
 
-	// a constant ambient term
-	const float amb = norm.w;
 	// the w coordinate from the persp. projection
 	float w = norm.w;
@@ -173,9 +171,8 @@
 	/// reconstruct position from the eye space depth
 	float3 viewDir = IN.view;
-	const float eyeDepth = tex2D(colors, IN.texCoord.xy).w;
-
-	float4 centerPosition;
+	const float eyeDepth = tex2Dlod(colors, float4(IN.texCoord, 0, 0)).w;
+
+	float3 centerPosition;
 	centerPosition.xyz = eyePos - viewDir * eyeDepth;
-	centerPosition.w = centerPosition.w;
 
 	const float2 ao = ssao(IN, colors, noiseTexture, samples, normal, centerPosition, w, eyePos, bl, br, tl, tr);
@@ -183,5 +180,5 @@
 
 	// the current world position
-	const float4 centerPosition = tex2D(positions, IN.texCoord.xy);
+	const float3 centerPosition = tex2Dlod(positions, float4(IN.texCoord, 0, 0)).xyz;
 
 	const float2 ao = ssao(IN, positions, noiseTexture, samples, normal, centerPosition, w, eyePos, bl, br, tl, tr);
@@ -192,11 +189,8 @@
 	//-- compute temporally smoothing
 
-	float4 realPos = centerPosition * maxDepth;
-	realPos.w = 1.0f;
-
-	// calulcate the current depth
-	//const float currentDepth = centerPosition.w;
-	
-	// apply modelview matrix
+	float4 realPos = float4(centerPosition * maxDepth, 1.0f);
+
+
+	// calculcate the current projected depth for next frame
 	float4 currentPos = mul(modelViewProj, realPos);
 	currentPos /= currentPos.w;
@@ -217,12 +211,13 @@
 	float2 tex = (projPos.xy) * 0.5f + 0.5f;
 
-	// optain the sample from the last frame
+	// retrieve the sample from the last frame
 	float4 oldCol = tex2D(oldTex, tex);
 
 	const float oldDepth = oldCol.w;
+	const float depthDif = 1.0f - projDepth / oldDepth;
+
+
 	//const float oldNumSamples = oldCol.y;
 	const float oldWeight = clamp(oldCol.z, 0, temporalCoherence);
-
-	const float depthDif = 1.0f - projDepth / oldDepth;
 
 	float newWeight;
@@ -264,6 +259,6 @@
 	pixel OUT;
 
-	float4 col = tex2Dlod(colors, float4(IN.texCoord.xy, 0, 0));
-	float4 ao = tex2D(ssaoTex, IN.texCoord.xy);
+	float4 col = tex2Dlod(colors, float4(IN.texCoord, 0, 0));
+	float4 ao = tex2Dlod(ssaoTex, float4(IN.texCoord, 0, 0));
 
 	OUT.illum_col = col * ao.x;
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/globillum.cg
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/globillum.cg	(revision 3003)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/globillum.cg	(revision 3006)
@@ -62,5 +62,5 @@
 				   uniform float2 samples[NUM_SAMPLES],
 				   uniform float3 currentNormal,
-				   uniform float4 centerPosition,
+				   uniform float3 centerPosition,
 				   float w,
 				   uniform float3 eyePos,
@@ -103,5 +103,7 @@
 		//if ((texcoord.x <= 1.0f) && (texcoord.x >= 0.0f) && (texcoord.y <= 1.0f) && (texcoord.y >= 0.0f)) ++ numSamples;
 
-		// reconstruct world space position from sample
+		//////////
+		//-- reconstruct world space position from sample
+
 		float4 sample = tex2Dlod(colors, float4(texcoord, 0, SSAO_MIPMAP_LEVEL));
 		const float eyeSpaceDepth = sample.w;
@@ -118,5 +120,5 @@
 		float3 direction_to_sample = vector_to_sample / length_to_sample;
 
-		// Angle between current normal and direction to sample controls AO intensity.
+		// use angle between current normal and direction to sample controls AO intensity.
 		float cos_angle = max(dot(direction_to_sample, currentNormal), 0);
 
@@ -153,4 +155,5 @@
 		   uniform sampler2D oldIllumTex,
 		   const uniform float4x4 oldModelViewProj,
+		   const uniform float4x4 modelViewProj,
 		   uniform float maxDepth,
 		   uniform float temporalCoherence,
@@ -166,30 +169,25 @@
 	float4 norm = tex2D(normals, IN.texCoord.xy);
 	float3 normal = normalize(norm.xyz);	
-	// something like a constant ambient term
-	const float amb = norm.w;
-	
-	/// the current view direction
-	//float3 viewDir = normalize(IN.view);
 
 	// the w coordinate from the persp. projection
 	float w = norm.w;
-	// the current world position
-	const float4 centerPosition2 = tex2D(positions, IN.texCoord.xy);
-
-	/// reconstruct position from the eye space depth
-	float3 viewDir = normalize(IN.view);
-	const float eyeDepth = tex2D(colors, IN.texCoord.xy).w;
-	
-	float4 centerPosition;
+
+
+	/////////////
+	//-- reconstruct position from the eye space depth
+
+	float3 viewDir = Interpol(IN.texCoord.xy, bl, br, tl, tr);//IN.view;
+	const float eyeDepth = tex2Dlod(colors, float4(IN.texCoord.xy, 0, 0)).w;
+	
+	float3 centerPosition;
 	centerPosition.xyz = eyePos - viewDir * eyeDepth;
-
-	centerPosition.w = centerPosition2.w;
-
-	// the current color
-	const float4 currentCol = tex2Dlod(colors, float4(IN.texCoord.xy, 0, 0));
-	// the current depth is stored in the w component
-	const float currentDepth = centerPosition.w;
-
-	GiStruct gi = globIllum(IN, colors, noiseTexture, samples, normal, centerPosition2, w, eyePos, bl, br, tl, tr);
+	
+	//const float3 centerPosition = tex2D(positions, IN.texCoord.xy).xyz;
+
+
+	///////////
+	//-- compute color bleeding + ao
+
+	GiStruct gi = globIllum(IN, colors, noiseTexture, samples, normal, centerPosition, w, eyePos, bl, br, tl, tr);
 	
 
@@ -197,24 +195,39 @@
 	//-- compute temporally smoothing
 
-	float4 realPos = centerPosition * maxDepth;
-	realPos.w = 1.0f;
-
-	float4 oldPos = mul(oldModelViewProj, realPos);
-
-	const float newDepth = oldPos.z / oldPos.w;
-
-	float2 tex = (oldPos.xy / oldPos.w) * 0.5f + 0.5f;
-
+	float4 realPos = float4(centerPosition * maxDepth, 1.0f);
+
+
+	// calculcate the current projected depth for next frame
+	float4 currentPos = mul(modelViewProj, realPos);
+	currentPos /= currentPos.w;
+	const float currentDepth = currentPos.z;
+	
+
+	///////////
+	//-- reprojection new frame into old one 
+	
+	// calculate projected depth
+	float4 projPos = mul(oldModelViewProj, realPos);
+	projPos /= projPos.w;
+
+	// the current depth projected into the old frame
+	const float projDepth = projPos.z;
+
+	// fit from unit cube into 0 .. 1
+	float2 tex = (projPos.xy) * 0.5f + 0.5f;
+
+	// retrieve the sample from the last frame
 	float4 oldSsao = tex2D(oldSsaoTex, tex);
 	float4 oldIllum = tex2D(oldIllumTex, tex);
 
 	const float oldDepth = oldSsao.w;
-	const float depthDif = 1.0f - newDepth / oldDepth;
+	const float depthDif = 1.0f - projDepth / oldDepth;
 
 	float oldWeight = clamp(oldSsao.z, 0, temporalCoherence);
+
 	float newWeight;
 
-	const float oldNumSamples = oldSsao.y;
-	const float oldAvgDepth = oldSsao.z;
+	//const float oldNumSamples = oldSsao.y;
+	//const float oldAvgDepth = oldSsao.z;
 
 	if (//(temporalCoherence > 0.0f) &&
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.h
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.h	(revision 2994)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.h	(revision 3006)
@@ -72,5 +72,5 @@
 					 const Matrix4x4 &projViewMatrix);
 
-	void ComputeGlobIllum(FrameBufferObject *fbo, float tempCohFactor, const Matrix4x4 &oldProjViewMatrix);
+	void ComputeGlobIllum(FrameBufferObject *fbo, float tempCohFactor, const Matrix4x4 &projViewMatrix, const Matrix4x4 &oldProjViewMatrix);
 
 	void FirstPass(FrameBufferObject *fbo, DirectionalLight *light);
@@ -90,7 +90,10 @@
 	*/
 	void ComputeViewVectors(Vector3 &tl, Vector3 &tr, Vector3 &bl, Vector3 &br);
-	
-	void DownSample(FrameBufferObject *fbo);
 
+	/** Downsample buffer of fbo to buffer of downSampleFbo. The downSampleFbo must have half the
+		resolution of fbo.
+	*/
+	void DownSample(FrameBufferObject *fbo, int bufferIdx,
+					FrameBufferObject *downSampleFbo, int downSampleBufferIdx);
 
 
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.cpp	(revision 3005)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.cpp	(revision 3006)
@@ -87,4 +87,5 @@
 
 static CGparameter sOldModelViewProjMatrixGiParam;
+static CGparameter sModelViewProjMatrixGiParam;
 static CGparameter sMaxDepthGiParam;
 static CGparameter sSamplesGiParam; 
@@ -286,5 +287,5 @@
 	//-- the flip-flop fbos
 
-	mFbo = new FrameBufferObject(w, h, FrameBufferObject::DEPTH_NONE);
+	mFbo = new FrameBufferObject(w / 2, h / 2, FrameBufferObject::DEPTH_NONE);
 
 	mFbo->AddColorBuffer(ColorBufferObject::RGBA_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_LINEAR);
@@ -297,6 +298,5 @@
 	mDownSampleFbo->AddColorBuffer(ColorBufferObject::RGBA_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_LINEAR);
 	mDownSampleFbo->AddColorBuffer(ColorBufferObject::RGBA_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_LINEAR);
-	mDownSampleFbo->AddColorBuffer(ColorBufferObject::RGBA_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_LINEAR);
-	mDownSampleFbo->AddColorBuffer(ColorBufferObject::RGBA_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_LINEAR);
+	mDownSampleFbo->AddColorBuffer(ColorBufferObject::RGBA_FLOAT_16, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_LINEAR);
 }
 
@@ -406,4 +406,5 @@
 		
 		sOldModelViewProjMatrixGiParam = cgGetNamedParameter(sCgGiProgram, "oldModelViewProj");
+		sModelViewProjMatrixGiParam = cgGetNamedParameter(sCgGiProgram, "modelViewProj");
 		sMaxDepthGiParam = cgGetNamedParameter(sCgGiProgram, "maxDepth");
 		sTemporalCoherenceGiParam = cgGetNamedParameter(sCgGiProgram, "temporalCoherence");
@@ -576,6 +577,6 @@
 		float h = 768;
 
-		float xoffs = 1 / w;
-		float yoffs = 1 / h;
+		float xoffs = 0.5f / w;
+		float yoffs = 0.5f / h;
 
 		downSampleOffsets[0] =  xoffs; downSampleOffsets[1] =  yoffs;
@@ -609,4 +610,5 @@
 	mFboIndex = 2 - mFboIndex;
 	
+
 	FrameBufferObject::Release();
 	cgGLEnableProfile(RenderState::sCgFragmentProfile);
@@ -638,10 +640,15 @@
 	{
 	case SSAO:
+		DownSample(fbo, colorBufferIdx, mDownSampleFbo, 0);
+		DownSample(fbo, 1, mDownSampleFbo, 1);
+		DownSample(fbo, 2, mDownSampleFbo, 2);
+
 		ComputeSsao(fbo, tempCohFactor, oldProjViewMatrix, projViewMatrix);
 		CombineSsao(fbo);
 		break;
 	case GI:
-		DownSample(fbo);
-		ComputeGlobIllum(fbo, tempCohFactor, oldProjViewMatrix);
+		DownSample(fbo, colorBufferIdx, mDownSampleFbo, 0);
+		DownSample(fbo, 2, mDownSampleFbo, 2);
+		ComputeGlobIllum(fbo, tempCohFactor, projViewMatrix, oldProjViewMatrix);
 		CombineIllum(fbo);
 		break;
@@ -698,11 +705,14 @@
 	cgGLSetMatrixParameterfc(sOldModelViewProjMatrixParam, (const float *)oldProjViewMatrix.x);
 
-	GLuint colorsTex = fbo->GetColorBuffer(colorBufferIdx)->GetTexture();
-	GLuint positionsTex = fbo->GetColorBuffer(1)->GetTexture();
-	GLuint normalsTex = fbo->GetColorBuffer(2)->GetTexture();
-
-	// generate mip map levels of position in order to improve texture lookup performance
-	//glBindTexture(GL_TEXTURE_2D, positionsTex); glGenerateMipmapEXT(GL_TEXTURE_2D);
-	//glBindTexture(GL_TEXTURE_2D, colorsTex); glGenerateMipmapEXT(GL_TEXTURE_2D);
+	//GLuint colorsTex = fbo->GetColorBuffer(colorBufferIdx)->GetTexture();
+	//GLuint positionsTex = fbo->GetColorBuffer(1)->GetTexture();
+	//GLuint normalsTex = fbo->GetColorBuffer(2)->GetTexture();
+
+	GLuint colorsTex = mDownSampleFbo->GetColorBuffer(0)->GetTexture();
+	GLuint positionsTex = mDownSampleFbo->GetColorBuffer(1)->GetTexture();
+	GLuint normalsTex = mDownSampleFbo->GetColorBuffer(2)->GetTexture();
+
+	glPushAttrib(GL_VIEWPORT_BIT);
+	glViewport(0, 0, mFbo->GetWidth(), mFbo->GetHeight());
 
 	// read the second buffer, write to the first buffer
@@ -711,8 +721,6 @@
 
 	GLuint oldTex = mFbo->GetColorBuffer(2 - mFboIndex)->GetTexture();
-
 	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
 
-	cgGLEnableProfile(RenderState::sCgFragmentProfile);
 	cgGLBindProgram(sCgSsaoProgram);
 
@@ -782,5 +790,5 @@
 	cgGLDisableTextureParameter(sOldTexParam);
 
-
+	glPopAttrib();
 	FrameBufferObject::Release();
 
@@ -823,8 +831,5 @@
 	GLuint colorsTex = colorBuffer->GetTexture();
 	GLuint normalsTex = fbo->GetColorBuffer(2)->GetTexture();
-	
 	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
-
-	cgGLEnableProfile(RenderState::sCgFragmentProfile);
 	cgGLBindProgram(sCgAntiAliasingProgram);
 	
@@ -868,8 +873,7 @@
 	colorBufferIdx = 3 - colorBufferIdx;
 	glDrawBuffers(1, mrt + colorBufferIdx);
-
+	
 	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
-	cgGLEnableProfile(RenderState::sCgFragmentProfile);
-
+	
 	cgGLBindProgram(sCgDeferredProgram);
 
@@ -904,6 +908,4 @@
 	cgGLDisableTextureParameter(sNormalsTexDeferredParam);
 
-	cgGLDisableProfile(RenderState::sCgFragmentProfile);
-
 	FrameBufferObject::Release();
 
@@ -915,15 +917,17 @@
 void DeferredRenderer::ComputeGlobIllum(FrameBufferObject *fbo, 
 										float tempCohFactor,
+										const Matrix4x4 &projViewMatrix,
 										const Matrix4x4 &oldProjViewMatrix)
 {
 	cgGLSetMatrixParameterfc(sOldModelViewProjMatrixGiParam, (const float *)oldProjViewMatrix.x);
-
-//	GLuint colorsTex = fbo->GetColorBuffer(colorBufferIdx)->GetTexture();
+	cgGLSetMatrixParameterfc(sModelViewProjMatrixGiParam, (const float *)projViewMatrix.x);
+
+	//GLuint colorsTex = fbo->GetColorBuffer(colorBufferIdx)->GetTexture();
 	GLuint colorsTex = mDownSampleFbo->GetColorBuffer(0)->GetTexture();
 	GLuint positionsTex = fbo->GetColorBuffer(1)->GetTexture();
-	GLuint normalsTex = fbo->GetColorBuffer(2)->GetTexture();
-
-	// generate mip map levels for position texture
-	//glBindTexture(GL_TEXTURE_2D, positionsTex); glGenerateMipmapEXT(GL_TEXTURE_2D);
+	GLuint normalsTex = mDownSampleFbo->GetColorBuffer(2)->GetTexture();
+
+	glPushAttrib(GL_VIEWPORT_BIT);
+	glViewport(0, 0, mFbo->GetWidth(), mFbo->GetHeight());
 
 	// read the second buffer, write to the first buffer
@@ -934,8 +938,7 @@
 	GLuint oldSsaoTex = mFbo->GetColorBuffer(2 - mFboIndex)->GetTexture();
 	GLuint oldIllumTex = mFbo->GetColorBuffer(2 - mFboIndex + 1)->GetTexture();
-
+	
 	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
 
-	cgGLEnableProfile(RenderState::sCgFragmentProfile);
 	cgGLBindProgram(sCgGiProgram);
 
@@ -1015,4 +1018,6 @@
 	FrameBufferObject::Release();
 
+	glPopAttrib();
+
 	PrintGLerror("globillum first pass");
 }
@@ -1033,6 +1038,4 @@
 
 	glDrawBuffers(1, mrt + colorBufferIdx);
-
-	cgGLEnableProfile(RenderState::sCgFragmentProfile);
 
 	cgGLBindProgram(sCgCombinedIllumProgram);
@@ -1067,6 +1070,4 @@
 	cgGLDisableTextureParameter(sIllumTexCombinedIllumParam);
 
-	cgGLDisableProfile(RenderState::sCgFragmentProfile);
-
 	FrameBufferObject::Release();
 
@@ -1089,6 +1090,4 @@
 	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
 	
-	cgGLEnableProfile(RenderState::sCgFragmentProfile);
-
 	cgGLBindProgram(sCgCombinedSsaoProgram);
 
@@ -1116,6 +1115,4 @@
 	cgGLDisableTextureParameter(sSsaoTexCombinedSsaoParam);
 	
-	cgGLDisableProfile(RenderState::sCgFragmentProfile);
-
 	FrameBufferObject::Release();
 
@@ -1250,8 +1247,6 @@
 	glDrawBuffers(1, mrt + colorBufferIdx);
 	
-
 	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
 
-	cgGLEnableProfile(RenderState::sCgFragmentProfile);
 	cgGLBindProgram(sCgLogLumProgram);
 	
@@ -1314,10 +1309,14 @@
 
 
-void DeferredRenderer::DownSample(FrameBufferObject *fbo)
-{
-	ColorBufferObject *colorBuffer = fbo->GetColorBuffer(colorBufferIdx);
+void DeferredRenderer::DownSample(FrameBufferObject *fbo, int bufferIdx,
+								  FrameBufferObject *downSampleFbo, 
+								  int downSampleBufferIdx)
+{
+	ColorBufferObject *colorBuffer = fbo->GetColorBuffer(bufferIdx);
 	GLuint colorsTex = colorBuffer->GetTexture();
-	
-	cgGLEnableProfile(RenderState::sCgFragmentProfile);
+
+	glPushAttrib(GL_VIEWPORT_BIT);
+	glViewport(0, 0, downSampleFbo->GetWidth(), downSampleFbo->GetHeight());
+
 	cgGLBindProgram(sCgDownSampleProgram);
 	
@@ -1326,26 +1325,9 @@
 
 	mDownSampleFbo->Bind();
-
-	glDrawBuffers(1, mrt);
-	
+	glDrawBuffers(1, mrt + downSampleBufferIdx);
+
 	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
-
-	cgGLEnableProfile(RenderState::sCgFragmentProfile);
 	cgGLBindProgram(sCgDownSampleProgram);
-
-	//glPushAttrib(GL_VIEWPORT_BIT);
-	glViewport(0, 0, mWidth / 2, mHeight / 2);
-	
-	glMatrixMode(GL_PROJECTION);
-	glPushMatrix();
-	glLoadIdentity();
-
-	const float offs2 = 0.5f;
-	glOrtho(-offs2, offs2, -offs2, offs2, 0, 1);
-
-	glMatrixMode(GL_MODELVIEW);
-	glPushMatrix();
-	glLoadIdentity();
-
+	
 	const float offs = 0.5f;
 
@@ -1360,22 +1342,13 @@
 
 	cgGLDisableTextureParameter(sColorsTexDownSampleParam);
-
 	FrameBufferObject::Release();
 
-	float *data = (float *)mDownSampleFbo->GetColorBuffer(0)->ReadTexture();
-	//float *data = (float *)mFbo->GetColorBuffer(colorBufferIdx)->ReadTexture();
+	/*float *data = (float *)mDownSampleFbo->GetColorBuffer(0)->ReadTexture();
 	ExportData(data, mWidth / 2, mHeight / 2);
-	//ExportData(data, mWidth, mHeight);
-
-	glMatrixMode(GL_PROJECTION);
-	glPopMatrix();
-	glMatrixMode(GL_MODELVIEW);
-	glPopMatrix();
-
-	//glPopAttrib();
-	glViewport(0, 0, mWidth, mHeight);
+	delete [] data;*/
+
+	glPopAttrib();
+	
 	PrintGLerror("downsample");
-
-	delete [] data;
 }
 
@@ -1394,8 +1367,6 @@
 	colorBufferIdx = 3 - colorBufferIdx;
 	glDrawBuffers(1, mrt + colorBufferIdx);
-	
 	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
 
-	cgGLEnableProfile(RenderState::sCgFragmentProfile);
 	cgGLBindProgram(sCgToneProgram);
 	
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/FrameBufferObject.h
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/FrameBufferObject.h	(revision 3005)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/FrameBufferObject.h	(revision 3006)
@@ -116,4 +116,9 @@
 	unsigned int GetDepthTex() const { return mDepthTexId; }
 
+	inline int GetWidth() { return mWidth; }
+
+	inline int GetHeight() { return mHeight; }
+
+
 protected:
 
