Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/FrameBufferObject.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/FrameBufferObject.cpp	(revision 3021)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/FrameBufferObject.cpp	(revision 3117)
@@ -364,3 +364,14 @@
 
 
+void FrameBufferObject::InitBuffer(FrameBufferObject *fbo, int index)
+{
+	// read the second buffer, write to the first buffer
+	fbo->Bind();
+	glDrawBuffers(1, mrt + index);
+
+	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+
+	FrameBufferObject::Release();
+}
+
 } // namespace
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/mrt.cg
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/mrt.cg	(revision 3113)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/mrt.cg	(revision 3117)
@@ -16,5 +16,6 @@
 
 	float4 color: COLOR0;  
-	float4 eyePos: TEXCOORD1; // eye position
+	 // eye position
+	float4 eyePos: TEXCOORD1;
 	float4 normal: TEXCOORD2;
 	float4 worldPos: TEXCOORD3;
@@ -30,5 +31,6 @@
 
 	float4 winPos: WPOS;
-	float4 eyePos: TEXCOORD1; // eye position
+	// eye position
+	float4 eyePos: TEXCOORD1;
 	float4 normal: TEXCOORD2;
 	float4 worldPos: TEXCOORD3;
@@ -61,8 +63,6 @@
 	// transform the vertex position into post projection space
 	OUT.position = mul(glstate.matrix.mvp, IN.position);
-
 	// the normal has to be correctly transformed with the inverse transpose
 	OUT.normal = mul(glstate.matrix.invtrans.modelview[0], IN.normal);
-
 	// transform the old vertex position into world space
 	OUT.worldPos = mul(modelMatrix, IN.position);
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg	(revision 3115)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg	(revision 3117)
@@ -177,4 +177,5 @@
 
 #else
+
 	// calculate eye space position of sample in old frame
 	const float oldDepth = oldPixel.w;
@@ -182,4 +183,5 @@
 	// vector from eye pos to old sample 
 	const float depthDif = abs(projectedDepth - oldDepth);
+
 #endif
 
@@ -210,9 +212,4 @@
 	}
 
-
-	// the number of valid samples in this frame
-	//const float newNumSamples = ao.y;
-	//const float oldNumSamples = oldCol.y;
-
 	const float oldWeight = clamp(oldPixel.y, .0f, temporalCoherence);
 	float newWeight;
@@ -256,15 +253,16 @@
 */
 float2 ssao(fragment IN,
-			uniform sampler2D colors,
-			uniform sampler2D noiseTex,
-			uniform float2 samples[NUM_SAMPLES],
-			uniform float3 normal,
-			uniform float3 centerPosition,
-			uniform float scaleFactor,
-			uniform float3 bl,
-			uniform float3 br,
-			uniform float3 tl,
-			uniform float3 tr, 
-			uniform float3 viewDir
+			sampler2D colors,
+			sampler2D noiseTex,
+			float2 samples[NUM_SAMPLES],
+			float3 normal,
+			float3 centerPosition,
+			float scaleFactor,
+			float3 bl,
+			float3 br,
+			float3 tl,
+			float3 tr, 
+			float3 viewDir
+			//,float2 noiseOffs
 			)
 {
@@ -285,4 +283,5 @@
 		//-- add random noise: reflect around random normal vector (rather slow!)
 
+		//float2 mynoise = tex2Dlod(noiseTex, float4(IN.texCoord * 4.0f + noiseOffs, 0, 0)).xy;
 		float2 mynoise = tex2Dlod(noiseTex, float4(IN.texCoord * 4.0f, 0, 0)).xy;
 		const float2 offsetTransformed = myreflect(offset, mynoise);
@@ -374,5 +373,5 @@
 	{
 		ao = ssao(IN, colors, noiseTex, samples, normal, 
-		          eyeSpacePos.xyz, scaleFactor, bl, br, tl, tr, normalize(viewDir));
+		          eyeSpacePos.xyz, scaleFactor, bl, br, tl, tr, normalize(viewDir));//, noiseOffs);
 	}
 
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderState.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderState.cpp	(revision 3114)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderState.cpp	(revision 3117)
@@ -139,5 +139,4 @@
 {
 	//if (mCurrentTechnique == tech) return;
-
 	mCurrentTechnique = tech;
 
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp	(revision 3115)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp	(revision 3117)
@@ -361,15 +361,14 @@
 		env.GetIntParam(string("winWidth"), winWidth);
 		env.GetIntParam(string("winHeight"), winHeight);
-
-		env.GetBoolParam(string("useFullScreen"), useFullScreen);
 		env.GetFloatParam(string("tempCohFactor"), ssaoTempCohFactor);
 		env.GetVectorParam(string("camPosition"), camPos);
 		env.GetVectorParam(string("camDirection"), camDir);
 		env.GetVectorParam(string("lightDirection"), lightDir);
-
+		env.GetIntParam(string("shadowSize"), shadowSize);
+
+		env.GetBoolParam(string("useFullScreen"), useFullScreen);
 		env.GetBoolParam(string("useLODs"), useLODs);
-		env.GetIntParam(string("shadowSize"), shadowSize);
-
 		env.GetBoolParam(string("useHDR"), useHDR);
+
 
 		//env.GetStringParam(string("modelPath"), model_path);
@@ -464,5 +463,5 @@
 	//-- load some dynamic stuff
 
-	LoadModel("hbuddha.dem", dynamicObjects);
+/*	LoadModel("hbuddha.dem", dynamicObjects);
 	buddha = dynamicObjects.back();
 	
@@ -488,5 +487,5 @@
 		dynamicObjects.push_back(ent);
 	}
-
+*/
 
 	///////////
@@ -523,13 +522,5 @@
 	preetham = new SkyPreetham(turbitiy, skyDome);
 
-	CreateAnimation();
-
-	for (int i = 0; i < sceneEntities.size(); ++ i)
-		sceneEntities[i]->mId = 0;
-	for (int i = 0; i < dynamicObjects.size(); ++ i)
-		dynamicObjects[i]->mId = 0;
-	
-	//buddha->mId = 250;
-	buddha->mId = 1;
+	//CreateAnimation();
 
 
@@ -567,5 +558,4 @@
 	// we store diffuse colors, eye space depth and normals
 	fbo = new FrameBufferObject(texWidth, texHeight, FrameBufferObject::DEPTH_32);
-	//fbo = new FrameBufferObject(texWidth, texHeight, FrameBufferObject::DEPTH_24);
 
 	// the diffuse color buffer
@@ -575,10 +565,13 @@
 	// a rgb buffer which could hold material properties
 	//fbo->AddColorBuffer(ColorBufferObject::RGB_UBYTE, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_NEAREST);
-	// holding the difference vector to the old frame
+	// buffer holding the difference vector to the old frame
 	fbo->AddColorBuffer(ColorBufferObject::RGB_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_NEAREST);
 	// another color buffer
 	fbo->AddColorBuffer(ColorBufferObject::RGBA_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_LINEAR, ColorBufferObject::FILTER_NEAREST);
 
-	PrintGLerror("fbo");
+	for (int i = 0; i < 4; ++ i)
+		FrameBufferObject::InitBuffer(fbo, i);
+	
+	PrintGLerror("init fbo");
 }
 
@@ -902,5 +895,5 @@
 void MainLoop() 
 {	
-	GPUProgramParameters *vtxParams = 
+	/*GPUProgramParameters *vtxParams = 
 		buddha->GetShape(0)->GetMaterial()->GetTechnique(1)->GetVertexProgramParameters();
 
@@ -915,5 +908,5 @@
 	dynamicObjects[1]->GetTransform()->MultMatrix(rotMatrix);
 
-
+*/
 	/////////////
 
@@ -1144,5 +1137,5 @@
 	/////////////////////////
 
-	//motionPath->Move(0.3f);
+	/*//motionPath->Move(0.3f);
 	motionPath->Move(0.01f);
 	Vector3 oldBuddhaPos = buddhaPos;
@@ -1155,4 +1148,5 @@
 	invTrafo = TranslationMatrix(diff);
 	//cout<< "diff " << diff << endl;
+	*/
 }
 
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.cpp	(revision 3115)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.cpp	(revision 3117)
@@ -234,16 +234,4 @@
 
 
-static void InitBuffer(FrameBufferObject *fbo, int index)
-{
-	// read the second buffer, write to the first buffer
-	fbo->Bind();
-	glDrawBuffers(1, mrt + index);
-
-	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
-
-	FrameBufferObject::Release();
-}
-
-
 DeferredRenderer::DeferredRenderer(int w, int h, PerspectiveCamera *cam):
 mWidth(w), mHeight(h), 
@@ -270,6 +258,10 @@
 	{
 		mIllumFbo->AddColorBuffer(ColorBufferObject::RGBA_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_LINEAR);
-		InitBuffer(mIllumFbo, i);
-	}
+		FrameBufferObject::InitBuffer(mIllumFbo, i);
+	}
+
+
+	///////////////
+	//-- the downsampled ssao + color bleeding textures: as gi is inherently low frequency, we can use these to improve performance
 
 	mDownSampleFbo = new FrameBufferObject(dsw, dsh, FrameBufferObject::DEPTH_NONE);
@@ -278,4 +270,11 @@
 	// downsample buffer for the normal texture
 	mDownSampleFbo->AddColorBuffer(ColorBufferObject::RGB_FLOAT_16, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_LINEAR);
+	// downsample buffer for the offset texture
+	mDownSampleFbo->AddColorBuffer(ColorBufferObject::RGB_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_LINEAR);
+
+	for (int i = 0; i < 3; ++ i)
+	{
+		FrameBufferObject::InitBuffer(mDownSampleFbo, i);
+	}
 
 	mFBOs.push_back(mDownSampleFbo);
@@ -453,4 +452,6 @@
 		// normals
 		DownSample(fbo, 1, mDownSampleFbo, 1);
+		// offsets
+		DownSample(fbo, 2, mDownSampleFbo, 2);
 	}
 
@@ -458,5 +459,4 @@
 	{
 	case SSAO:
-
 		ComputeSsao(fbo, tempCohFactor);
 		CombineSsao(fbo);
@@ -501,4 +501,151 @@
 								   float tempCohFactor)
 {
+	GLuint colorsTex, normalsTex, attribsTex;
+
+	if (0)
+	{
+		colorsTex = fbo->GetColorBuffer(colorBufferIdx)->GetTexture();
+		normalsTex = fbo->GetColorBuffer(1)->GetTexture();
+		attribsTex = fbo->GetColorBuffer(2)->GetTexture();
+	}
+	else
+	{
+		colorsTex = mDownSampleFbo->GetColorBuffer(0)->GetTexture();
+		normalsTex = mDownSampleFbo->GetColorBuffer(1)->GetTexture();
+		attribsTex = mDownSampleFbo->GetColorBuffer(2)->GetTexture();
+	}
+
+	// flip flop between illumination buffers
+	GLuint oldTex = mIllumFbo->GetColorBuffer(2 - mIllumFboIndex)->GetTexture();
+
+	cout << colorBufferIdx;
+
+	glPushAttrib(GL_VIEWPORT_BIT);
+	glViewport(0, 0, mIllumFbo->GetWidth(), mIllumFbo->GetHeight());
+
+	// read the second buffer, write to the first buffer
+	mIllumFbo->Bind();
+	glDrawBuffers(1, mrt + mIllumFboIndex);
+
+	int i = 0;
+
+	sCgSsaoProgram->SetTexture(i ++, colorsTex);
+	sCgSsaoProgram->SetTexture(i ++, normalsTex);
+	sCgSsaoProgram->SetTexture(i ++, oldTex);
+	sCgSsaoProgram->SetTexture(i ++, noiseTex);
+
+	sCgSsaoProgram->SetValue1f(i ++, (mUseTemporalCoherence && !mRegenerateSamples) ? tempCohFactor : 0);
+	
+	if (mUseTemporalCoherence || mRegenerateSamples)
+	{
+		mRegenerateSamples = false;
+
+		// q: should we generate new samples or only rotate the old ones?
+		// in the first case, the sample patterns look nicer, but the kernel
+		// needs longer to converge
+		GenerateSamples(mSamplingMethod); 
+		sCgSsaoProgram->SetArray2f(i, (float *)samples2, NUM_SAMPLES);
+	}
+	
+	++ i;
+
+	for (int j = 0; j < 4; ++ j, ++ i)
+		sCgSsaoProgram->SetValue3f(i, mCornersView[j].x, mCornersView[j].y, mCornersView[j].z);
+
+	sCgSsaoProgram->SetMatrix(i ++, mProjViewMatrix);
+	sCgSsaoProgram->SetMatrix(i ++, mOldProjViewMatrix);
+
+	Vector3 de;
+	de.x = mOldEyePos.x - mEyePos.x;
+	de.y = mOldEyePos.y - mEyePos.y; 
+	de.z = mOldEyePos.z - mEyePos.z;
+
+	sCgSsaoProgram->SetValue3f(i ++, de.x, de.y, de.z);
+
+	for (int j = 0; j < 4; ++ j, ++ i)
+		sCgSsaoProgram->SetValue3f(i, mOldCornersView[j].x, mOldCornersView[j].y, mOldCornersView[j].z);
+
+	sCgSsaoProgram->SetTexture(i ++, attribsTex);
+
+	DrawQuad(sCgSsaoProgram);
+
+	glPopAttrib();
+
+	PrintGLerror("ssao first pass");
+}
+
+
+static void SetVertex(float x, float y, float x_offs, float y_offs)
+{
+	glMultiTexCoord2fARB(GL_TEXTURE0_ARB, x, y); // center
+	glMultiTexCoord2fARB(GL_TEXTURE1_ARB, x - x_offs, y + y_offs); // left top
+	glMultiTexCoord2fARB(GL_TEXTURE2_ARB, x + x_offs, y - y_offs); // right bottom
+	glMultiTexCoord2fARB(GL_TEXTURE3_ARB, x + x_offs, y + y_offs); // right top
+	glMultiTexCoord2fARB(GL_TEXTURE4_ARB, x - x_offs, y - y_offs); // left bottom
+
+	glMultiTexCoord4fARB(GL_TEXTURE5_ARB, x - x_offs, y, x + x_offs, y); // left right
+	glMultiTexCoord4fARB(GL_TEXTURE6_ARB, x, y + y_offs, x, y - y_offs); // top bottom
+
+	//glVertex3f(x - 0.5f, y - 0.5f, -0.5f);
+	glVertex2f(x, y);
+}
+
+
+void DeferredRenderer::AntiAliasing(FrameBufferObject *fbo, DirectionalLight *light)
+{
+	FrameBufferObject::Release();
+
+	ColorBufferObject *colorBuffer = fbo->GetColorBuffer(colorBufferIdx);
+
+	GLuint colorsTex = colorBuffer->GetTexture();
+	GLuint normalsTex = fbo->GetColorBuffer(2)->GetTexture();
+
+	sCgAntiAliasingProgram->SetTexture(0, colorsTex);
+	sCgAntiAliasingProgram->SetTexture(1, normalsTex);
+
+	sCgAntiAliasingProgram->Bind();
+
+	glBegin(GL_QUADS);
+
+	// the neighbouring texels
+	float x_offs = 1.0f / mWidth;
+	float y_offs = 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();
+
+	PrintGLerror("antialiasing");
+}
+
+
+void DeferredRenderer::FirstPass(FrameBufferObject *fbo, DirectionalLight *light)
+{
+	GLuint colorsTex = fbo->GetColorBuffer(colorBufferIdx)->GetTexture();
+	GLuint normalsTex = fbo->GetColorBuffer(1)->GetTexture();
+
+	fbo->Bind();
+
+	colorBufferIdx = 3 - colorBufferIdx;
+	glDrawBuffers(1, mrt + colorBufferIdx);
+
+	const Vector3 lightDir = -light->GetDirection();
+
+	sCgDeferredProgram->SetTexture(0, colorsTex);
+	sCgDeferredProgram->SetTexture(1, normalsTex);
+	sCgDeferredProgram->SetValue3f(2, lightDir.x, lightDir.y, lightDir.z);
+	
+	DrawQuad(sCgDeferredProgram);
+
+	PrintGLerror("deferred shading");
+}
+
+
+void DeferredRenderer::ComputeGlobIllum(FrameBufferObject *fbo, 
+										float tempCohFactor)
+{
 #if 0
 	GLuint colorsTex = fbo->GetColorBuffer(colorBufferIdx)->GetTexture();
@@ -509,7 +656,4 @@
 #endif
 
-	// flip flop between illumination buffers
-	GLuint oldTex = mIllumFbo->GetColorBuffer(2 - mIllumFboIndex)->GetTexture();
-
 	glPushAttrib(GL_VIEWPORT_BIT);
 	glViewport(0, 0, mIllumFbo->GetWidth(), mIllumFbo->GetHeight());
@@ -517,154 +661,4 @@
 	// read the second buffer, write to the first buffer
 	mIllumFbo->Bind();
-	glDrawBuffers(1, mrt + mIllumFboIndex);
-
-	int i = 0;
-
-	sCgSsaoProgram->SetTexture(i ++, colorsTex);
-	sCgSsaoProgram->SetTexture(i ++, normalsTex);
-	sCgSsaoProgram->SetTexture(i ++, oldTex);
-	sCgSsaoProgram->SetTexture(i ++, noiseTex);
-
-	sCgSsaoProgram->SetValue1f(i ++, (mUseTemporalCoherence && !mRegenerateSamples) ? tempCohFactor : 0);
-	
-	if (mUseTemporalCoherence || mRegenerateSamples)
-	{
-		mRegenerateSamples = false;
-
-		// q: should we generate new samples or only rotate the old ones?
-		// in the first case, the sample patterns look nicer, but the kernel
-		// needs longer to converge
-		GenerateSamples(mSamplingMethod); 
-		sCgSsaoProgram->SetArray2f(i, (float *)samples2, NUM_SAMPLES);
-	}
-	
-	++ i;
-
-	for (int j = 0; j < 4; ++ j, ++ i)
-		sCgSsaoProgram->SetValue3f(i, mCornersView[j].x, mCornersView[j].y, mCornersView[j].z);
-
-	sCgSsaoProgram->SetMatrix(i ++, mProjViewMatrix);
-	sCgSsaoProgram->SetMatrix(i ++, mOldProjViewMatrix);
-
-	//Vector3 de = mOldEyePos - mEyePos;
-	Vector3 de;
-	de.x = mOldEyePos.x - mEyePos.x;
-	de.y = mOldEyePos.y - mEyePos.y; 
-	de.z = mOldEyePos.z - mEyePos.z;
-	//Vector3 de = mEyePos - mOldEyePos;
-
-	sCgSsaoProgram->SetValue3f(i ++, de.x, de.y, de.z);
-
-	for (int j = 0; j < 4; ++ j, ++ i)
-		sCgSsaoProgram->SetValue3f(i, mOldCornersView[j].x, mOldCornersView[j].y, mOldCornersView[j].z);
-
-	GLuint attribsTex = fbo->GetColorBuffer(2)->GetTexture();
-	sCgSsaoProgram->SetTexture(i ++, attribsTex);
-
-	float trafos[32];
-	for (int i = 0; i < 16; ++ i)
-		trafos[i] = ((const float *)invTrafo.x)[i];
-
-	static Matrix4x4 identity = IdentityMatrix();
-
-	for (int i = 0; i < 16; ++ i)
-		trafos[i+16] = ((const float *)identity.x)[i];
-
-	//sCgSsaoProgram->SetMatrixArray(i ++, trafos, 2);
-	//sCgSsaoProgram->SetMatrix(i ++, IdentityMatrix());
-
-	DrawQuad(sCgSsaoProgram);
-
-	glPopAttrib();
-
-	PrintGLerror("ssao first pass");
-}
-
-
-static void SetVertex(float x, float y, float x_offs, float y_offs)
-{
-	glMultiTexCoord2fARB(GL_TEXTURE0_ARB, x, y); // center
-	glMultiTexCoord2fARB(GL_TEXTURE1_ARB, x - x_offs, y + y_offs); // left top
-	glMultiTexCoord2fARB(GL_TEXTURE2_ARB, x + x_offs, y - y_offs); // right bottom
-	glMultiTexCoord2fARB(GL_TEXTURE3_ARB, x + x_offs, y + y_offs); // right top
-	glMultiTexCoord2fARB(GL_TEXTURE4_ARB, x - x_offs, y - y_offs); // left bottom
-
-	glMultiTexCoord4fARB(GL_TEXTURE5_ARB, x - x_offs, y, x + x_offs, y); // left right
-	glMultiTexCoord4fARB(GL_TEXTURE6_ARB, x, y + y_offs, x, y - y_offs); // top bottom
-
-	//glVertex3f(x - 0.5f, y - 0.5f, -0.5f);
-	glVertex2f(x, y);
-}
-
-
-void DeferredRenderer::AntiAliasing(FrameBufferObject *fbo, DirectionalLight *light)
-{
-	FrameBufferObject::Release();
-
-	ColorBufferObject *colorBuffer = fbo->GetColorBuffer(colorBufferIdx);
-
-	GLuint colorsTex = colorBuffer->GetTexture();
-	GLuint normalsTex = fbo->GetColorBuffer(2)->GetTexture();
-
-	sCgAntiAliasingProgram->SetTexture(0, colorsTex);
-	sCgAntiAliasingProgram->SetTexture(1, normalsTex);
-
-	sCgAntiAliasingProgram->Bind();
-
-	glBegin(GL_QUADS);
-
-	// the neighbouring texels
-	float x_offs = 1.0f / mWidth;
-	float y_offs = 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();
-
-	PrintGLerror("antialiasing");
-}
-
-
-void DeferredRenderer::FirstPass(FrameBufferObject *fbo, DirectionalLight *light)
-{
-	GLuint colorsTex = fbo->GetColorBuffer(colorBufferIdx)->GetTexture();
-	GLuint normalsTex = fbo->GetColorBuffer(1)->GetTexture();
-
-	fbo->Bind();
-
-	colorBufferIdx = 3 - colorBufferIdx;
-	glDrawBuffers(1, mrt + colorBufferIdx);
-
-	const Vector3 lightDir = -light->GetDirection();
-
-	sCgDeferredProgram->SetTexture(0, colorsTex);
-	sCgDeferredProgram->SetTexture(1, normalsTex);
-	sCgDeferredProgram->SetValue3f(2, lightDir.x, lightDir.y, lightDir.z);
-	
-	DrawQuad(sCgDeferredProgram);
-
-	PrintGLerror("deferred shading");
-}
-
-
-void DeferredRenderer::ComputeGlobIllum(FrameBufferObject *fbo, 
-										float tempCohFactor)
-{
-#if 0
-	GLuint colorsTex = fbo->GetColorBuffer(colorBufferIdx)->GetTexture();
-	GLuint normalsTex = fbo->GetColorBuffer(1)->GetTexture();
-#else
-	GLuint colorsTex = mDownSampleFbo->GetColorBuffer(0)->GetTexture();
-	GLuint normalsTex = mDownSampleFbo->GetColorBuffer(1)->GetTexture();
-#endif
-
-	glPushAttrib(GL_VIEWPORT_BIT);
-	glViewport(0, 0, mIllumFbo->GetWidth(), mIllumFbo->GetHeight());
-
-	// read the second buffer, write to the first buffer
-	mIllumFbo->Bind();
 
 	glDrawBuffers(2, mrt + mIllumFboIndex);
@@ -672,5 +666,4 @@
 	GLuint oldSsaoTex = mIllumFbo->GetColorBuffer(2 - mIllumFboIndex)->GetTexture();
 	GLuint oldIllumTex = mIllumFbo->GetColorBuffer(2 - mIllumFboIndex + 1)->GetTexture();
-	
 
 	sCgGiProgram->SetTexture(0, colorsTex);
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/FrameBufferObject.h
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/FrameBufferObject.h	(revision 3017)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/FrameBufferObject.h	(revision 3117)
@@ -29,5 +29,4 @@
 					  WRAP_TYPE wrapType, 
 					  FILTER_TYPE filterType);
-
 	/** Same as above, with mipmapping enabled.
 	*/
@@ -41,9 +40,12 @@
 
 	~ColorBufferObject();
-
+	/** Returns associated texture id.
+	*/
 	inline unsigned int GetTexture() const { return mTexId; }
-
+	/** Returns width of render target.
+	*/
 	inline int GetWidth() { return mWidth; }
-
+	/** Returns height of render target.
+	*/
 	inline int GetHeight() { return mHeight; }
 	/** Returns texture data.
@@ -78,5 +80,5 @@
 
 
-/** This class implements a wrapper for a frame buffer object
+/** This class implements a wrapper for a frame buffer object.
 */
 class FrameBufferObject
@@ -84,4 +86,5 @@
 public:
 
+	/// Available depth formats
 	enum DEPTH_FORMAT {DEPTH_NONE, DEPTH_16, DEPTH_24, DEPTH_32};
 
@@ -89,5 +92,6 @@
 	*/
 	FrameBufferObject(int w, int h, DEPTH_FORMAT d, bool useDepthTex = false);
-	
+	/** Destructor destroying gl resources.
+	*/
 	~FrameBufferObject();
 	/** Creates and adds a color buffer to the current frame buffer object.
@@ -105,21 +109,33 @@
 					   ColorBufferObject::FILTER_TYPE filterTypeMipMap);
 
-	/** Returns the color buffer object on position i.
-	*/
-	ColorBufferObject *GetColorBuffer(int i) const { return mColorBuffers[i]; }
 	/** Binds this frame buffer object.
 	*/
 	void Bind() const;
+	
+	///////////////////
+	
+	/** Returns the color buffer object on position i.
+	*/
+	inline ColorBufferObject *GetColorBuffer(int i) const { return mColorBuffers[i]; }
+	/** Returns depth texture id
+	*/
+	inline unsigned int GetDepthTex() const { return mDepthTexId; }
+	/** Returns width of fbo
+	*/
+	inline int GetWidth() { return mWidth; }
+	/** Returns height of fbo
+	*/
+	inline int GetHeight() { return mHeight; }
+
+
+	////////////////
+
+	/** Initialise a render target (using current clear color)
+	*/
+	static void InitBuffer(FrameBufferObject *fbo, int index);
 	/** Releases any bound frame buffer object.
 	*/
 	static void Release();
 	
-	unsigned int GetDepthTex() const { return mDepthTexId; }
-
-	inline int GetWidth() { return mWidth; }
-
-	inline int GetHeight() { return mHeight; }
-
-
 protected:
 
@@ -137,4 +153,6 @@
 };
 
+
 } // namespace 
+
 #endif // _FrameBufferObject_H__
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/default.env
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/default.env	(revision 3115)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/default.env	(revision 3117)
@@ -2,21 +2,36 @@
 # environment file for the friendlyculling demo
 
+############
+## chc++ options
+
 assumedVisibleFrames=10
 maxBatchSize=50
+# triangles per bvh leaf (influences hierarchy depth vs. occlusion power)
 trianglesPerVirtualLeaf=300
-#trianglesPerVirtualLeaf=30000
-keyForwardMotion=20.0f
-keyRotation=1.5f
+
+
+# move speed
+keyForwardMotion=5.0f
+keyRotation=0.5f
+#keyForwardMotion=20.0f
+#keyRotation=1.5f
+
+
 winWidth=1024
 winHeight=768
+
+# initial positin + orientation
 camPosition=483.398f 242.364f 186.078f
 camDirection=1 0 0
+
 #lightDirection=-0.8f 1.0f -0.7f
 lightDirection=-0.3f 0.2f -0.7f
-#lightDirection=0.0f 0.0f -1.0f
+
 useFullScreen=0
 useLODs=1
 shadowSize=4096
+
 #modelPath=data/city/model/
+
 
 
