Index: /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SceneEntity.h
===================================================================
--- /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SceneEntity.h	(revision 3109)
+++ /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SceneEntity.h	(revision 3110)
@@ -92,11 +92,23 @@
 	*/
 	Vector3 GetWorldCenter() const;
+	/** Prepare this scene entity for rendering, i.e., sets the state and the transform. 
+		This is used with the render queue. When a shape belonging to this scene entity
+		is rendered, this function is called in beforehand.
+	*/
+	void Prepare(RenderState *state);
+
+
+	/////////////
+	//-- static functions
+
 	/** If false, the highest (most detailed) LOD level is used for all entities.
 	*/
 	static void SetUseLODs(bool useLODs) { sUseLODs = useLODs; }
-
+	/** See set
+	*/
 	static bool GetUseLODs() { return sUseLODs; }
 
 
+	int mId;
 
 protected:
@@ -109,4 +121,6 @@
 	int GetCurrentLODLevel();
 
+
+	/////////////////////
 
 	/// the bounding box
@@ -127,6 +141,4 @@
 	Vector3 mCenter;
 
-	int mId;
-
 	static bool sUseLODs;
 	static int sCurrentId;
Index: /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/sky_preetham.cg
===================================================================
--- /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/sky_preetham.cg	(revision 3041)
+++ /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/sky_preetham.cg	(revision 3110)
@@ -37,5 +37,5 @@
 	float4 col: COLOR0;
 	float3 norm: COLOR1;
-	float3 pos: COLOR2;
+	float3 id: COLOR2;
 };
 
@@ -83,6 +83,7 @@
 			      0.055648f, -0.204043f,  1.057311f);
 
-	float3 hcol = mul(conv_Mat, XYZ);
-	OUT.color = float4(hcol, 1.0f);
+	//float3 hcol = mul(conv_Mat, XYZ);
+	//OUT.color = float4(hcol, 1.0f);
+	OUT.color = float4(mul(conv_Mat, XYZ), 1.0f);
 
 	OUT.color.rgb *= multiplier;
@@ -91,5 +92,5 @@
 
 	OUT.normal = IN.normal;
-
+	
 	return OUT;
 }
@@ -103,5 +104,7 @@
 	pix.col.w = 1e20f;
 	pix.norm = IN.normal;
-	
+	// the scene entity id
+	pix.id = glstate.fog.color.xyz;
+
 	return pix;
 }
Index: /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/mrt.cg
===================================================================
--- /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/mrt.cg	(revision 3092)
+++ /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/mrt.cg	(revision 3110)
@@ -38,5 +38,5 @@
 	float4 col: COLOR0;
 	float3 norm: COLOR1;
-	float3 pos: COLOR2;
+	float3 id: COLOR2;
 };
 
@@ -83,6 +83,7 @@
 	// compute eye linear depth
 	pix.col.w = length(IN.eyePos.xyz);
-	// hack: squeeze some information about ambient into the texture
-	//pix.col.w = glstate.material.emission.x;
+	// the scene entity id
+	pix.id = glstate.fog.color.xyz;
+	//pix.id = float3(1,1,1);
 
 	return pix;
@@ -101,7 +102,7 @@
 	// eye space depth
 	pix.col.w = length(IN.eyePos.xyz);
-	// hack: squeeze some information about the ambient term into the target
-	//pix.col.w = glstate.material.emission.x;
-
+	// the scene entity id
+	pix.id = glstate.fog.color.xyz;
+	
 	return pix;
 }
Index: /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg
===================================================================
--- /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg	(revision 3109)
+++ /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg	(revision 3110)
@@ -150,6 +150,8 @@
 	float4x4 trafo;
 	
-	if (id > 20) trafo = oldModelViewProj;
-	else trafo = inverseModelTrafo * oldModelViewProj;
+	if (id < 10) 
+		trafo = oldModelViewProj;
+	else 
+		trafo = inverseModelTrafo * oldModelViewProj;
 
 	// compute translational portion
@@ -350,5 +352,5 @@
 		   uniform float3 oldtl,
 		   uniform float3 oldtr,
-		   uniform sampler2D attribs,
+		   uniform sampler2D attribsTex,
 		   uniform float4x4 inverseModelTrafo
 		   )
@@ -383,11 +385,12 @@
 	//-- compute temporally smoothing
 
-	float id = tex2Dlod(attribs, float4(IN.texCoord, 0, 0)).x;
+	float3 id = tex2Dlod(attribsTex, float4(IN.texCoord, 0, 0)).xyz;
 
 	OUT.illum_col = temporalSmoothing(eyeSpacePos, eyeSpaceDepth, ao, IN.texCoord, oldEyePos,
 		                              oldTex, oldModelViewProj, temporalCoherence,
-		                              colors, w, bl, br, tl, tr, projPos, inverseModelTrafo, id,
+		                              colors, w, bl, br, tl, tr, projPos, inverseModelTrafo, id.z,
 									  noiseTex, samples, scaleFactor, oldbl, oldbr, oldtl, oldtr);
 
+	//OUT.illum_col.xyz = id;
 	//OUT.illum_col.xyz = normal * 0.5f + 0.5f;
 	return OUT;
@@ -405,5 +408,5 @@
 
 	for (int i = 0; i < NUM_SSAO_FILTERSAMPLES; ++ i)
-	{
+	{	
 		average += filterWeights[i] * tex2Dlod(ssaoTex, float4(texCoord + filterOffs[i] * scale, 0, 0)).x;
 		w += filterWeights[i];
@@ -428,10 +431,11 @@
 	float4 ao = tex2Dlod(ssaoTex, float4(IN.texCoord, 0, 0));
 
-	if ((ao.y < 10.0f) && (col.w < 1e10f))
-		ao.x = Filter(IN.texCoord, ssaoTex, filterOffs, filterWeights, 1.0f / (1.0f + ao.y));//ao.z);
-
-	OUT.illum_col = col * ao.x;
+	//if ((ao.y < 10.0f) && (col.w < 1e10f))
+	//	ao.x = Filter(IN.texCoord, ssaoTex, filterOffs, filterWeights, 1.0f / (1.0f + ao.y));//ao.z);
+
+	//OUT.illum_col = col * ao.x;
 	//OUT.illum_col = float4(ao.y, ao.y, ao.y, col.w);
-	//OUT.illum_col = float4(ao.x, ao.x, ao.x, col.w);
+	//OUT.illum_col = float4(ao.x, ao.y, ao.z, col.w);
+	OUT.illum_col = float4(ao.x, ao.x, ao.x, col.w);
 	//OUT.illum_col.xyz = float3(1.0f - ao.x, 1.0f - ao.y * 1e-2f, 1);
 	//OUT.illum_col.xyz = float3(1.0f - ao.x, ao.y, 0);
Index: /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderQueue.cpp
===================================================================
--- /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderQueue.cpp	(revision 3071)
+++ /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderQueue.cpp	(revision 3110)
@@ -80,10 +80,10 @@
 	for (; sit != sit_end; ++ sit)
 	{
-		Enqueue(*sit, entity->GetTransform());
-	}
-}
-
-
-void RenderQueue::Enqueue(Shape *shape, Transform3 *trafo)
+		Enqueue(*sit, entity);
+	}
+}
+
+
+void RenderQueue::Enqueue(Shape *shape, SceneEntity *containingEnt)
 {
 	Technique *tech = shape->GetMaterial()->GetTechnique(mState->GetRenderTechnique());
@@ -159,5 +159,5 @@
 	}
 
-	bucket->mShapes.push_back(ShapePair(shape, trafo));
+	bucket->mShapes.push_back(ShapePair(shape, containingEnt));
 }
 
@@ -193,9 +193,9 @@
 
 			Shape *shape = s.first;
-			Transform3 *t = s.second;
-
-			t->Load(mState);
+			SceneEntity *ent = s.second;
+
+			if (ent) ent->Prepare(mState);
 			shape->Render(mState);
-			t->Unload(mState);
+			if (ent) ent->GetTransform()->Unload(mState);
 		}
 	}
Index: /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderQueue.h
===================================================================
--- /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderQueue.h	(revision 3071)
+++ /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderQueue.h	(revision 3110)
@@ -11,5 +11,5 @@
 class Camera;
 
-typedef std::pair<Shape *, Transform3 *> ShapePair;
+typedef std::pair<Shape *, SceneEntity *> ShapePair;
 typedef std::vector<ShapePair> ShapePairArray;
 
@@ -19,4 +19,5 @@
 {
 	inline bool IsEmpty() const { return mShapes.empty();}
+
 
 	////////
@@ -41,10 +42,8 @@
 	ShaderProgram *mVertexProgram;
 	ShaderProgram *mFragmentProgram;
-
+	/// the shapes that belong to a bucket
+	ShapePairArray mShapes;
 	/// minimal distance to the camera
 	//float mMinDistance;
-
-	/// the shapes that belong to a bucket
-	ShapePairArray mShapes;
 };
 
@@ -69,10 +68,10 @@
 
 	~RenderQueue();
-	/** Enqueues an entity.
+	/** Enqueues all the shapes of an entity.
 	*/
 	void Enqueue(SceneEntity *entity);
-	/** Enqueues a single shape.
+	/** Enqueues a single shape. We also have to pass the entity which contains the shape.
 	*/
-	void Enqueue(Shape *shape, Transform3 *trafo);
+	void Enqueue(Shape *shape, SceneEntity *containingEnt);
 	/** Sets the current render state
 	*/
Index: /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SceneEntity.cpp
===================================================================
--- /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SceneEntity.cpp	(revision 3109)
+++ /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SceneEntity.cpp	(revision 3110)
@@ -6,5 +6,5 @@
 #include "Transform3.h"
 #include "Camera.h"
-
+#include "glInterface.h"
 
 
@@ -97,5 +97,5 @@
 	}
 
-	mTransform->Load(state);
+	Prepare(state);
 
 	for (; sit != sit_end; ++ sit)
@@ -149,5 +149,4 @@
 {
 	if (mTransform->IsIdentity()) return mBox;
-
 	Matrix4x4 mat = mTransform->GetMatrix();
 
@@ -164,6 +163,5 @@
 Vector3 SceneEntity::GetWorldCenter() const
 {
-	if (mTransform->IsIdentity())
-		return mCenter;
+	if (mTransform->IsIdentity()) return mCenter;
 
 	return mTransform->GetMatrix() *  mCenter;
@@ -171,3 +169,14 @@
 
 
+void SceneEntity::Prepare(RenderState *state)
+{
+	int id[] = {(mId / (255 * 255)) % 255, (mId / 255) % 255, mId % 255, 0};
+
+	GLfloat fogColor[4] = {(float)id[0] / 255.0f, (float)id[1] / 255.0f, (float)id[2] / 255.0f, .0f};
+	glFogfv(GL_FOG_COLOR, fogColor);
+
+	mTransform->Load(state);
 }
+
+
+}
Index: /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp
===================================================================
--- /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp	(revision 3107)
+++ /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp	(revision 3110)
@@ -523,4 +523,11 @@
 	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 = 50;
+
 
 	//////////
@@ -878,14 +885,7 @@
 	// draw to 3 color buffers
 	// a color, normal, and positions buffer
-	if (sCurrentMrtSet == 0)
-	{
-		DeferredRenderer::colorBufferIdx = 0;
-		glDrawBuffers(2, mrt);
-	}
-	else 
-	{
-		DeferredRenderer::colorBufferIdx = 3;
-		glDrawBuffers(2, mrt2);
-	}
+	DeferredRenderer::colorBufferIdx = 3 - DeferredRenderer::colorBufferIdx;
+	if (sCurrentMrtSet == 0) glDrawBuffers(3, mrt);
+	else glDrawBuffers(3, mrt2);
 
 	sCurrentMrtSet = 1 - sCurrentMrtSet;
@@ -897,7 +897,10 @@
 void MainLoop() 
 {	
+	Vector3 oldPos = motionPath->GetCurrentPosition();
+
 	//motionPath->Move(0.3f);
 	motionPath->Move(0.01f);
 
+	nMatrix mat = 
 	Vector3 planepos = motionPath->GetCurrentPosition();
 
@@ -2039,5 +2042,5 @@
 
 
-/** Toach each material once in order to preload the render queue 
+/** Touch each material once in order to preload the render queue 
 	bucket id of each material
 */
@@ -2054,5 +2057,5 @@
 		{
 			static Transform3 dummy(IdentityMatrix());
-			renderQueue->Enqueue(*sit, &dummy);
+			renderQueue->Enqueue(*sit, NULL);
 		}
 	
Index: /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.cpp
===================================================================
--- /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.cpp	(revision 3107)
+++ /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.cpp	(revision 3110)
@@ -72,5 +72,5 @@
 
 
-int DeferredRenderer::colorBufferIdx = 0;
+int DeferredRenderer::colorBufferIdx = 3;
 
 
@@ -91,5 +91,5 @@
 static float GaussianDistribution(float x, float y, float rho)
 {
-    float g = 1.0f / sqrtf(2.0f * M_PI * rho * rho);
+	float g = 1.0f / sqrtf(2.0f * M_PI * rho * rho);
     g *= expf( -(x*x + y*y) / (2.0f * rho * rho));
 
@@ -338,6 +338,6 @@
 		{"colors", "normals", "oldTex", "noiseTex", "temporalCoherence", 
 		 "samples", "bl", "br", "tl", "tr", "modelViewProj", "oldModelViewProj",
-		 "oldEyePos", "oldbl", "oldbr", "oldtl", "oldtr"};
-	sCgSsaoProgram->AddParameters(ssaoParams, 0, 17);
+		 "oldEyePos", "oldbl", "oldbr", "oldtl", "oldtr", "attribsTex", "inverseModelTrafo"};
+	sCgSsaoProgram->AddParameters(ssaoParams, 0, 19);
 	
 	string giParams[] = 
@@ -559,4 +559,9 @@
 		sCgSsaoProgram->SetValue3f(i, mOldCornersView[j].x, mOldCornersView[j].y, mOldCornersView[j].z);
 
+	GLuint attribsTex = fbo->GetColorBuffer(2)->GetTexture();
+	sCgSsaoProgram->SetTexture(i ++, attribsTex);
+
+	sCgSsaoProgram->SetMatrix(i ++, IdentityMatrix());
+
 	DrawQuad(sCgSsaoProgram);
 
Index: /GTP/trunk/App/Demos/Vis/FriendlyCulling/VboFormatConverter/VboFormatConverter.cpp
===================================================================
--- /GTP/trunk/App/Demos/Vis/FriendlyCulling/VboFormatConverter/VboFormatConverter.cpp	(revision 3107)
+++ /GTP/trunk/App/Demos/Vis/FriendlyCulling/VboFormatConverter/VboFormatConverter.cpp	(revision 3110)
@@ -132,6 +132,6 @@
 
 void VboFormatConverter::LoadShape(const VertexArray &faceVertices,
-							 const VertexArray &faceNormals,
-							 const vector<Texcoord> &faceTexcoords)
+								   const VertexArray &faceNormals,
+								   const vector<Texcoord> &faceTexcoords)
 {
 	int numElements = (int)faceVertices.size();
Index: /GTP/trunk/App/Demos/Vis/FriendlyCulling/FriendlyCulling.vcproj
===================================================================
--- /GTP/trunk/App/Demos/Vis/FriendlyCulling/FriendlyCulling.vcproj	(revision 3103)
+++ /GTP/trunk/App/Demos/Vis/FriendlyCulling/FriendlyCulling.vcproj	(revision 3110)
@@ -585,12 +585,4 @@
 				</File>
 				<File
-					RelativePath=".\src\EntityMerger.cpp"
-					>
-				</File>
-				<File
-					RelativePath=".\src\EntityMerger.h"
-					>
-				</File>
-				<File
 					RelativePath=".\src\FrameBufferObject.cpp"
 					>
