Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Transform3.h
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Transform3.h	(revision 3070)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Transform3.h	(revision 3113)
@@ -33,4 +33,7 @@
 	*/
 	inline Matrix4x4 GetMatrix() const  { return mMatrix; }
+	/** Returns pointer to trafo matrix
+	*/
+	inline const Matrix4x4 *GetPMatrix() const { return &mMatrix; }
 	/** See Get
 	*/
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ShaderProgram.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ShaderProgram.cpp	(revision 3112)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ShaderProgram.cpp	(revision 3113)
@@ -138,5 +138,5 @@
 
 
-void GPUProgramParameters::SetMatrix(int idx, Matrix4x4 *mat)
+void GPUProgramParameters::SetMatrix(int idx, const Matrix4x4 &mat)
 {
 	if (mMatrices.size() < idx + 1)
@@ -207,5 +207,5 @@
 
 
-void GPUProgramParameters::SetMatrix(const string &name, Matrix4x4 *mat)
+void GPUProgramParameters::SetMatrix(const string &name, const Matrix4x4 &mat)
 {
 	SetMatrix(mProgram->GetParamIdxByName(name), mat);
@@ -263,6 +263,5 @@
 		const MatrixParam &p = mMatrices[i];
 
-		if (p.mValid)
-			mProgram->SetMatrix(i, *p.mValue);
+		if (p.mValid) mProgram->SetMatrix(i, p.mValue);
 	}
 	
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ShaderManager.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ShaderManager.cpp	(revision 3112)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ShaderManager.cpp	(revision 3113)
@@ -4,4 +4,5 @@
 #include "ShaderProgram.h"
 #include "ShaderManager.h"
+#include "Matrix4x4.h"
 #include <Cg/cg.h>
 #include <Cg/cgGL.h>
@@ -45,11 +46,11 @@
 	if(lastError)
 	{
+		printf("Cg error, exiting...\n");
+
 		Debug << "\n" << cgGetErrorString(lastError) << endl;
 		Debug << "\n" << cgGetLastListing(sCgContext) << endl;
-		/*printf("%s\n\n", cgGetErrorString(lastError));
+
+		printf("%s\n\n", cgGetErrorString(lastError));
 		printf("%s\n", cgGetLastListing(sCgContext));
-		*/
-		printf("Cg error, exiting...\n");
-
 
 		exit(0);
@@ -85,7 +86,15 @@
 	fragmentProgMrtTex = CreateFragmentProgram("mrt", "fragtex", "defaultFragmentTexMrt");
 
-	// provide the current view matrix
+	// provide the current view matrix:
+	// this is an automatic parameter that is updated each frame
 	fragmentProgMrt->AddParameter("viewMatrix", 0);
 	fragmentProgMrtTex->AddParameter("viewMatrix", 0);
+
+	vertexProgMrt->AddParameter("viewMatrix", 0);
+	
+	// these parameters are used for ssao
+	vertexProgMrt->AddParameter("modelMatrix", 1);
+	vertexProgMrt->AddParameter("oldModelMatrix", 2);
+	
 
 	// add a texture parameter
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/mrt.cg
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/mrt.cg	(revision 3110)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/mrt.cg	(revision 3113)
@@ -18,4 +18,6 @@
 	float4 eyePos: TEXCOORD1; // eye position
 	float4 normal: TEXCOORD2;
+	float4 worldPos: TEXCOORD3;
+	float4 oldWorldPos: TEXCOORD4;
 };
 
@@ -25,5 +27,4 @@
 {
 	float4 color: COLOR0;  
-	//float4 position: POSITION;
 	float4 texCoord: TEXCOORD0;    
 
@@ -31,4 +32,6 @@
 	float4 eyePos: TEXCOORD1; // eye position
 	float4 normal: TEXCOORD2;
+	float4 worldPos: TEXCOORD3;
+	float4 oldWorldPos: TEXCOORD4;
 };
 
@@ -38,5 +41,5 @@
 	float4 col: COLOR0;
 	float3 norm: COLOR1;
-	float3 id: COLOR2;
+	float3 offsVec: COLOR2;
 };
 
@@ -44,5 +47,8 @@
 #pragma position_invariant vtx
 
-vtxout vtx(vtxin IN)
+vtxout vtx(vtxin IN, 
+		   uniform float4x4 viewMatrix,
+		   uniform float4x4 modelMatrix,
+		   uniform float4x4 oldModelMatrix)
 {
 	vtxout OUT;
@@ -56,6 +62,12 @@
 	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);
+	// transform the old vertex position into world space
+	OUT.oldWorldPos = mul(oldModelMatrix, IN.position);
+	
 	return OUT;
 }
@@ -79,11 +91,14 @@
 	// save world space normal in rt => transform back into world space by
 	// multiplying with inverse view. since transforming normal with T means to 
-	// multiply with the inverse transpose of T, we multiple with Transp(Inv(Inv(view))) = Transp(view)
-	pix.norm = mul(transpose(viewMatrix), IN.normal);
+	// multiply with the inverse transpose of T, we multiple with 
+	// Transp(Inv(Inv(view))) = Transp(view)
+	pix.norm = mul(transpose(viewMatrix), IN.normal).xyz;
 	// compute eye linear depth
 	pix.col.w = length(IN.eyePos.xyz);
+
 	// the scene entity id
-	pix.id = glstate.fog.color.xyz;
-	//pix.id = float3(1,1,1);
+	//pix.id = glstate.fog.color.xyz;
+	// the offset to the world pos from old frame
+	pix.offsVec = IN.oldWorldPos.xyz - IN.worldPos.xyz;
 
 	return pix;
@@ -99,10 +114,12 @@
 	// multiplying with inverse view. since transforming normal with T means to 
 	// multiply with the inverse transpose of T, we multiple with Transp(Inv(Inv(view))) = Transp(view)
-	pix.norm = mul(transpose(viewMatrix), IN.normal);
+	pix.norm = mul(transpose(viewMatrix), IN.normal).xyz;
 	// eye space depth
 	pix.col.w = length(IN.eyePos.xyz);
 	// the scene entity id
-	pix.id = glstate.fog.color.xyz;
-	
+	//pix.id = glstate.fog.color.xyz;
+	// the offset to the world pos from old frame
+	pix.offsVec = IN.oldWorldPos.xyz - IN.worldPos.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 3112)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg	(revision 3113)
@@ -124,40 +124,28 @@
 								float2 texcoord0,
 								float3 oldEyePos,
-								uniform sampler2D oldTex,
-								uniform float4x4 oldModelViewProj,
-								uniform float temporalCoherence,
-								uniform sampler2D colors,
-								uniform float3 bl,
-								uniform float3 br,
-								uniform float3 tl,
-								uniform float3 tr, 
+								sampler2D oldTex,
+								float4x4 oldModelViewProj,
+								float temporalCoherence,
+								sampler2D colors,
+								float3 bl,
+								float3 br,
+								float3 tl,
+								float3 tr, 
 								float3 projPos,
 								float invW,
-								float4x4 inverseModelTrafos[2],
-								float id,
-								uniform sampler2D noiseTex,
-								uniform float2 samples[NUM_SAMPLES],
+								sampler2D noiseTex,
+								float2 samples[NUM_SAMPLES],
 								float scaleFactor,
-								uniform float3 oldbl,
-								uniform float3 oldbr,
-								uniform float3 oldtl,
-								uniform  float3 oldtr
+								float3 oldbl,
+								float3 oldbr,
+								float3 oldtl,
+								float3 oldtr,
+								float3 diffVec
 								)
 {
 	float4 illum_col;
 
-
-	////////////
-	//-- dynamic objects
-	/*float4x4 dummy;
-	uniform mat4 ident = float4x4(1);
-	x = dot(vec, ident[n]);
-*/
-	float4x4 dummyTrafo = inverseModelTrafos[(int)id];
-	//float4x4 trafo = (id < 10.0f) ? oldModelViewProj : mul(oldModelViewProj, inverseModelTrafo);
-	float4x4 trafo = mul(oldModelViewProj, dummyTrafo);
-
-	// compute translational portion
-	const float3 translatedPt = worldPos.xyz - oldEyePos;
+	// compute position from old frame for dynamic objects + translational portion
+	const float3 translatedPt = worldPos.xyz - oldEyePos + diffVec;
 
 
@@ -166,5 +154,5 @@
 
 	// note: the old model view matrix only holds the view orientation part
-	float4 backProjPos = mul(trafo, float4(translatedPt, 1.0f));
+	float4 backProjPos = mul(oldModelViewProj, float4(translatedPt, 1.0f));
 	backProjPos /= backProjPos.w;
 	
@@ -256,5 +244,5 @@
 
 	illum_col.z = invW;
-	//illum_col.y = depthDif;
+	//illum_col.x = length(diffVec*50.0f);
 
 	return illum_col;
@@ -356,6 +344,5 @@
 		   uniform float3 oldtl,
 		   uniform float3 oldtr,
-		   uniform sampler2D attribsTex,
-		   uniform float4x4 inverseModelTrafos[2]
+		   uniform sampler2D attribsTex
 		   )
 {
@@ -386,8 +373,9 @@
 
 
+	//float3 id = tex2Dlod(attribsTex, float4(IN.texCoord, 0, 0)).xyz;
+	float3 diffVec = tex2Dlod(attribsTex, float4(IN.texCoord, 0, 0)).xyz;
+
 	/////////////////
-	//-- compute temporally smoothing
-
-	float3 id = tex2Dlod(attribsTex, float4(IN.texCoord, 0, 0)).xyz;
+	//-- compute temporal reprojection
 
 	OUT.illum_col = temporalSmoothing(eyeSpacePos, eyeSpaceDepth, ao, IN.texCoord, oldEyePos,
@@ -397,10 +385,9 @@
 									  projPos.xyz, 
 									  invw, 
-									  inverseModelTrafos,
-									  id.z,
 									  noiseTex, 
 									  samples, 
 									  scaleFactor, 
-									  oldbl, oldbr, oldtl, oldtr);
+									  oldbl, oldbr, oldtl, oldtr,
+									  diffVec);
 
 	//OUT.illum_col.xyz = id;
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ResourceManager.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ResourceManager.cpp	(revision 3071)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ResourceManager.cpp	(revision 3113)
@@ -127,6 +127,10 @@
 	}
 
-	static ShaderProgram *sTreeAnimationProgram = ShaderManager::GetSingleton()->GetShaderProgram("treeAnimation");
-	static ShaderProgram *sTreeAnimationProgramMrt = ShaderManager::GetSingleton()->GetShaderProgram("treeAnimationMrt");
+
+	static ShaderProgram *sTreeAnimationProgram = 
+		ShaderManager::GetSingleton()->GetShaderProgram("treeAnimation");
+	static ShaderProgram *sTreeAnimationProgramMrt = 
+		ShaderManager::GetSingleton()->GetShaderProgram("treeAnimationMrt");
+
 
 	///////////
@@ -168,4 +172,5 @@
 					/// use a timer to simulate the moving of the tree in the wind
 					vtxParams->SetTimerParam(0);
+
 					// wind direction
 					static Vector3 windDir = Normalize(Vector3(0.8f, 0.2f, 0.0f));
@@ -298,4 +303,11 @@
 
 	deferred->SetVertexProgram(sDefaultVertexProgramMrt);
+
+	static Matrix4x4 identity = IdentityMatrix();
+
+	// default values: these are only updated for dynamic objects
+	deferred->GetVertexProgramParameters()->SetMatrix(1, identity);
+	deferred->GetVertexProgramParameters()->SetMatrix(2, identity);
+
 	mat->AddTechnique(deferred);
 	
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ShaderProgram.h
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ShaderProgram.h	(revision 3112)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ShaderProgram.h	(revision 3113)
@@ -4,5 +4,5 @@
 #include "common.h"
 #include "glInterface.h"
-
+#include "Matrix4x4.h"
 #include <Cg/cg.h>
 #include <Cg/cgGL.h>
@@ -17,5 +17,4 @@
 class Vector3;
 class Camera;
-class Matrix4x4;
 class ShadowMap;
 class DirectionalLight;
@@ -56,13 +55,14 @@
 	void SetArray2f(int idx, float *vals, int numElements);
 	void SetArray3f(int idx, float *vals, int numElements);
-	/** Sets the texture parameter.
+	/** Sets a texture parameter.
 	*/
 	void SetTexture(int idx, unsigned int tex);
-	/** Sets the matrix parameter.
-	*/
-	void SetMatrix(int idx, Matrix4x4 *mat);
+	/** Sets a matrix parameter.
+	*/
+	void SetMatrix(int idx, const Matrix4x4 &mat);
 	/** Sets an array of matrices
 	*/
 	void SetMatrixArray(int idx, float *vals, int numElements);
+
 
 	////////////
@@ -104,9 +104,8 @@
 	/** Sets the matrix parameter.
 	*/
-	void SetMatrix(const std::string &name, Matrix4x4 *mat);
+	void SetMatrix(const std::string &name, const Matrix4x4 &mat);
 	/** Sets an array of matrices
 	*/
 	void SetMatrixArray(const std::string &name, float *vals, int numElements);
-
 	/** Feeds the shader program with the parameter values.
 	*/
@@ -146,11 +145,11 @@
 	struct MatrixParam
 	{
-		MatrixParam(): mValue(NULL), mValid(false) {}
-
-		MatrixParam(Matrix4x4 *mat): mValue(mat), mValid(true)
+		MatrixParam(): mValue(IdentityMatrix()), mValid(false) {}
+
+		MatrixParam(const Matrix4x4 &mat): mValue(mat), mValid(true)
 		{}
 
 		bool mValid;
-		Matrix4x4 *mValue;
+		Matrix4x4 mValue;
 	};
 
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SceneEntity.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SceneEntity.cpp	(revision 3110)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SceneEntity.cpp	(revision 3113)
@@ -164,5 +164,4 @@
 {
 	if (mTransform->IsIdentity()) return mCenter;
-
 	return mTransform->GetMatrix() *  mCenter;
 }
@@ -171,8 +170,8 @@
 void SceneEntity::Prepare(RenderState *state)
 {
-	int id[] = {(mId / (255 * 255)) % 255, (mId / 255) % 255, mId % 255, 0};
+	/*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);
+	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 3112)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp	(revision 3113)
@@ -54,5 +54,6 @@
 #include "ShaderManager.h"
 #include "MotionPath.h"
-
+#include "ShaderProgram.h"
+#include "Shape.h"
 
 
@@ -573,5 +574,7 @@
 	fbo->AddColorBuffer(ColorBufferObject::RGB_FLOAT_16, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_NEAREST);
 	// a rgb buffer which could hold material properties
-	fbo->AddColorBuffer(ColorBufferObject::RGB_UBYTE, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_NEAREST);
+	//fbo->AddColorBuffer(ColorBufferObject::RGB_UBYTE, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_NEAREST);
+	// 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);
@@ -899,9 +902,19 @@
 void MainLoop() 
 {	
-	static Matrix4x4 invTrafo = IdentityMatrix();
+	GPUProgramParameters *vtxParams = 
+		buddha->GetShape(0)->GetMaterial()->GetTechnique(1)->GetVertexProgramParameters();
+
+	static Matrix4x4 oldTrafo;
+
+	oldTrafo = buddha->GetTransform()->GetMatrix();
+	vtxParams->SetMatrix(2, oldTrafo);
 
 	Vector3 buddhaPos = motionPath->GetCurrentPosition();
 	Matrix4x4 trafo = TranslationMatrix(buddhaPos);
+	
 	buddha->GetTransform()->SetMatrix(trafo);
+
+	vtxParams->SetMatrix(1, buddha->GetTransform()->GetMatrix());
+
 
 	/////////////
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.cpp	(revision 3112)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.cpp	(revision 3113)
@@ -340,6 +340,6 @@
 		 "samples", "bl", "br", "tl", "tr", 
 		 "modelViewProj", "oldModelViewProj", "oldEyePos", "oldbl", "oldbr", 
-		 "oldtl", "oldtr", "attribsTex", "inverseModelTrafos"};
-	sCgSsaoProgram->AddParameters(ssaoParams, 0, 19);
+		 "oldtl", "oldtr", "attribsTex"};
+	sCgSsaoProgram->AddParameters(ssaoParams, 0, 18);
 	
 	string giParams[] = 
@@ -574,5 +574,5 @@
 		trafos[i+16] = ((const float *)identity.x)[i];
 
-	sCgSsaoProgram->SetMatrixArray(i ++, trafos, 2);
+	//sCgSsaoProgram->SetMatrixArray(i ++, trafos, 2);
 	//sCgSsaoProgram->SetMatrix(i ++, IdentityMatrix());
 
