Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Transform3.h
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Transform3.h	(revision 3113)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Transform3.h	(revision 3114)
@@ -30,13 +30,4 @@
 	*/
 	void Unload(RenderState *state);
-	/** Returns the trafo matrix.
-	*/
-	inline Matrix4x4 GetMatrix() const  { return mMatrix; }
-	/** Returns pointer to trafo matrix
-	*/
-	inline const Matrix4x4 *GetPMatrix() const { return &mMatrix; }
-	/** See Get
-	*/
-	inline void SetMatrix(const Matrix4x4 &trafo) { mIsIdentity = false; mMatrix = trafo; }
 	/** Right multiplies with the given matrix.
 	*/
@@ -45,4 +36,13 @@
 	*/
 	void Reset();
+	/** Returns the trafo matrix.
+	*/
+	inline Matrix4x4 GetMatrix() const { return mMatrix; }
+	/** See Get
+	*/
+	inline void SetMatrix(const Matrix4x4 &trafo) ;
+	/** Returns the old trafo matrix.
+	*/
+	inline Matrix4x4 GetOldMatrix() const { return mOldMatrix; }
 	/** Returns true if this transformation is the identity.
 	*/
@@ -54,4 +54,6 @@
 	/// transform matrix 
 	Matrix4x4 mMatrix;
+	/// the previous transformation matrix
+	Matrix4x4 mOldMatrix;
 	/// if this matrix is still the identity matrix
 	bool mIsIdentity;
@@ -59,4 +61,12 @@
 
 
+void Transform3::SetMatrix(const Matrix4x4 &trafo) 
+{ 
+	mIsIdentity = false; 
+	mOldMatrix = mMatrix; 
+	mMatrix = trafo;
+}
+
+
 }
 
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Material.h
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Material.h	(revision 3065)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Material.h	(revision 3114)
@@ -48,6 +48,8 @@
 class Technique 
 {
+
 friend class ResourceManager;
 friend class RenderQueue;
+friend class Material;
 
 public:
@@ -61,5 +63,5 @@
 	/** Renders this technique.
 	*/
-	void Render(RenderState *state);
+	void Render(RenderState *state, SceneEntity *parent = NULL);
 	/** Initialize this technique material with default values
 	*/
@@ -126,4 +128,5 @@
 	ShaderProgram *mFragmentProgram;
 	ShaderProgram *mVertexProgram;
+
 	/// if this material can write colors
 	bool mColorWriteEnabled;
@@ -149,5 +152,5 @@
 	/** Renders this material.
 	*/
-	void Render(RenderState *state);
+	void Render(RenderState *state, SceneEntity *parent);
 
 	void AddTechnique(Technique *t);
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ShaderProgram.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ShaderProgram.cpp	(revision 3113)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ShaderProgram.cpp	(revision 3114)
@@ -5,5 +5,6 @@
 #include "Camera.h"
 #include "Light.h"
-
+#include "SceneEntity.h"
+#include "Transform3.h"
 
 using namespace std;
@@ -32,5 +33,7 @@
 mViewDirParam(-1),
 mViewMatrixParam(-1),
-mLightDirParam(-1)
+mLightDirParam(-1),
+mModelMatrixParam(-1),
+mOldModelMatrixParam(-1)
 {
 }
@@ -42,5 +45,7 @@
 mViewDirParam(-1),
 mViewMatrixParam(-1),
-mLightDirParam(-1)
+mLightDirParam(-1),
+mModelMatrixParam(-1),
+mOldModelMatrixParam(-1)
 {
 }
@@ -59,4 +64,7 @@
 	mLightDirParam = -1;
 	mViewMatrixParam = -1;
+
+	mModelMatrixParam = -1;
+	mOldModelMatrixParam = -1;
 }
 
@@ -171,4 +179,16 @@
 
 
+void GPUProgramParameters::SetModelMatrixParam(int idx)
+{
+	mModelMatrixParam = idx;
+}
+
+
+void GPUProgramParameters::SetOldModelMatrixParam(int idx)
+{
+	mOldModelMatrixParam = idx;
+}
+
+
 void GPUProgramParameters::SetValue1f(const string &name, float val)
 {
@@ -225,5 +245,5 @@
 
 
-void GPUProgramParameters::UpdateParameters()
+void GPUProgramParameters::UpdateParameters(SceneEntity *ent)
 {
 	if (!mProgram) return;
@@ -305,4 +325,12 @@
 	if (mViewMatrixParam >= 0)
 		mProgram->SetMatrix(mViewMatrixParam, sCurrentViewMatrix);
+
+	if (ent)
+	{
+		if (mModelMatrixParam >= 0)
+			mProgram->SetMatrix(mModelMatrixParam, ent->GetTransform()->GetMatrix());
+		if (mOldModelMatrixParam >= 0)
+			mProgram->SetMatrix(mOldModelMatrixParam, ent->GetTransform()->GetOldMatrix());
+	}
 }
 
@@ -347,7 +375,5 @@
 
 	for (int i = 0; i < maxParams; ++ i)
-	{
 		mParameters[i] = NULL;
-	}
 }
 
@@ -391,7 +417,5 @@
 {
 	for (int i = 0; i < numElements; ++ i)
-	{
 		AddParameter(params[i], startIdx + i);
-	}
 }
 
@@ -403,11 +427,7 @@
 
 	if (it == mParamHash.end())
-	{
 		p = cgGetNamedParameter(mProgram, name.c_str());
-	}
 	else
-	{
 		p = mParameters[(*it).second];
-	}
 
 	//cout << "name: " << name << " " << p << " " << mProgram << endl;
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Shape.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Shape.cpp	(revision 3074)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Shape.cpp	(revision 3114)
@@ -24,7 +24,7 @@
 
 
-void Shape::Render(RenderState *state)
+void Shape::Render(RenderState *state, SceneEntity *ent)
 {
-	if (mMaterial) mMaterial->Render(state);
+	if (mMaterial) mMaterial->Render(state, ent);
 	
 	mGeometry->Render(state);
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ShaderManager.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ShaderManager.cpp	(revision 3113)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ShaderManager.cpp	(revision 3114)
@@ -91,7 +91,8 @@
 	fragmentProgMrtTex->AddParameter("viewMatrix", 0);
 
+
+	// vertex program
 	vertexProgMrt->AddParameter("viewMatrix", 0);
-	
-	// these parameters are used for ssao
+	// needed for for ssao
 	vertexProgMrt->AddParameter("modelMatrix", 1);
 	vertexProgMrt->AddParameter("oldModelMatrix", 2);
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg	(revision 3113)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg	(revision 3114)
@@ -110,5 +110,6 @@
 	const float projectedEyeSpaceDepth = length(translatedPos) * invlen;
 	
-	float depthDif = (abs(eyeSpaceDepth - sampleEyeSpaceDepth) > 5.0f) ? 0 : abs(oldEyeSpaceDepth - projectedEyeSpaceDepth);
+	float depthDif = (abs(eyeSpaceDepth - sampleEyeSpaceDepth) > 5.0f) ? 
+		0 : abs(oldEyeSpaceDepth - projectedEyeSpaceDepth);
 
 	return depthDif;
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderState.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderState.cpp	(revision 3074)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderState.cpp	(revision 3114)
@@ -136,8 +136,7 @@
 
 	
-void RenderState::SetState(Technique *tech)
-{
-	if (mCurrentTechnique == tech)
-		return;
+void RenderState::SetState(Technique *tech, SceneEntity *ent)
+{
+	//if (mCurrentTechnique == tech) return;
 
 	mCurrentTechnique = tech;
@@ -152,4 +151,5 @@
 	const bool depthWrite = tech->IsDepthWriteEnabled();
 
+
 	if (mDepthWriteEnabled && !depthWrite) 
 	{
@@ -256,5 +256,5 @@
 		}
 			
-		tech->GetFragmentProgramParameters()->UpdateParameters();
+		tech->GetFragmentProgramParameters()->UpdateParameters(ent);
 	}
 	else
@@ -267,7 +267,7 @@
 	}
 
-	ShaderProgram *vert = tech->GetVertexProgram();
-
-	if (vert)
+	ShaderProgram *vtx = tech->GetVertexProgram();
+
+	if (vtx)
 	{
 		if (!mVertexProgramEnabled)
@@ -277,11 +277,11 @@
 		}
 
-		if (vert != mCurrentVertexProgram)
-		{
-			mCurrentVertexProgram = vert;
+		if (vtx != mCurrentVertexProgram)
+		{
+			mCurrentVertexProgram = vtx;
 			mCurrentVertexProgram->Bind();
 		}
 		
-		tech->GetVertexProgramParameters()->UpdateParameters();
+		tech->GetVertexProgramParameters()->UpdateParameters(ent);
 	}
 	else
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ResourceManager.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ResourceManager.cpp	(revision 3113)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ResourceManager.cpp	(revision 3114)
@@ -304,9 +304,6 @@
 	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);
+	deferred->GetVertexProgramParameters()->SetModelMatrixParam(1);
+	deferred->GetVertexProgramParameters()->SetOldModelMatrixParam(2);
 
 	mat->AddTechnique(deferred);
@@ -317,4 +314,5 @@
 
 	Technique *depthPass = new Technique(*tech);
+
 	depthPass->SetColorWriteEnabled(false);
 	depthPass->SetLightingEnabled(false);
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderQueue.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderQueue.cpp	(revision 3110)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderQueue.cpp	(revision 3114)
@@ -196,5 +196,5 @@
 
 			if (ent) ent->Prepare(mState);
-			shape->Render(mState);
+			shape->Render(mState, ent);
 			if (ent) ent->GetTransform()->Unload(mState);
 		}
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ShaderProgram.h
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ShaderProgram.h	(revision 3113)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ShaderProgram.h	(revision 3114)
@@ -34,9 +34,9 @@
 	*/
 	GPUProgramParameters();
-
-	/** Constructor which initialized this parameter set for a given program.
+	/** Constructor which initializes this parameter set for a given program.
 	*/
 	GPUProgramParameters(ShaderProgram *p);
-
+	/** Sets the assoziated program (a 1:n relationship)
+	*/
 	void SetProgram(ShaderProgram *p) { mProgram = p; }
 	/** Resets this parameter set.
@@ -84,6 +84,14 @@
 	*/
 	void SetLightDirParam(int idx);
-
-	
+	/** This parameter is connected to the current light direction 
+		that is updated once per frame.
+	*/
+	void SetModelMatrixParam(int idx);
+	/** This parameter is connected to the current light direction 
+		that is updated once per frame.
+	*/
+	void SetOldModelMatrixParam(int idx);
+
+
 
 	///////////
@@ -110,5 +118,5 @@
 	/** Feeds the shader program with the parameter values.
 	*/
-	void UpdateParameters();
+	void UpdateParameters(SceneEntity *ent = NULL);
 	/** Function should be called once per frame to update frame related parameters.
 	*/
@@ -190,4 +198,6 @@
 	int mLightDirParam;
 	int mViewMatrixParam;
+	int mModelMatrixParam;
+	int mOldModelMatrixParam;
 
 	std::vector<FloatParam> mFloats;
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Shape.h
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Shape.h	(revision 3072)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Shape.h	(revision 3114)
@@ -34,5 +34,5 @@
 	/** Renders this node.
 	*/
-	void Render(RenderState *state);	
+	void Render(RenderState *state, SceneEntity *ent = NULL);	
 	/** Set pointer to the geometry
 	*/
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderState.h
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderState.h	(revision 3068)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderState.h	(revision 3114)
@@ -33,7 +33,7 @@
 	*/
 	bool SetMode(Mode mode);
-	/** Sets the current render state.
+	/** Sets the current render state with the current technique + scene entity
 	*/
-	void SetState(Technique *tech);
+	void SetState(Technique *tech, SceneEntity *ent = NULL);
 	/** Returns the current render state.
 	*/
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SceneEntity.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SceneEntity.cpp	(revision 3113)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SceneEntity.cpp	(revision 3114)
@@ -100,5 +100,5 @@
 
 	for (; sit != sit_end; ++ sit)
-		(*sit)->Render(state);
+		(*sit)->Render(state, this);
 
 	mTransform->Unload(state);
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Material.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Material.cpp	(revision 3068)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Material.cpp	(revision 3114)
@@ -61,5 +61,5 @@
 
 
-void Technique::Render(RenderState *state)
+void Technique::Render(RenderState *state, SceneEntity *ent)
 {
 	glMaterialfv(GL_FRONT, GL_AMBIENT, (float *)&mAmbientColor.r);
@@ -68,5 +68,5 @@
 	glMaterialfv(GL_FRONT, GL_SPECULAR, (float *)&mSpecularColor.r);
 
-	state->SetState(this);
+	state->SetState(this, ent);
 }
 
@@ -94,9 +94,9 @@
 
 
-void Material::Render(RenderState *state)
+void Material::Render(RenderState *state, SceneEntity *parent)
 {
 	// set technique if available
 	int idx = min((int)mTechniques.size() - 1 , state->GetRenderTechnique());
-	mTechniques[idx]->Render(state);
+	mTechniques[idx]->Render(state, parent);
 }
 
@@ -117,5 +117,4 @@
 {
 	Technique *tech = new Technique();
-
 	mTechniques.push_back(tech);
 }
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Transform3.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Transform3.cpp	(revision 3089)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Transform3.cpp	(revision 3114)
@@ -14,5 +14,6 @@
 
 
-Transform3::Transform3(const Matrix4x4 &trafo): mMatrix(trafo)
+Transform3::Transform3(const Matrix4x4 &trafo): 
+mMatrix(trafo), mOldMatrix(trafo)
 {
 	mIsIdentity = false;
@@ -32,8 +33,5 @@
 void Transform3::Unload(RenderState *state)
 {
-	if (!mIsIdentity)
-	{
-		glPopMatrix();
-	}
+	if (!mIsIdentity) glPopMatrix();
 }
 
@@ -42,4 +40,5 @@
 {
 	mIsIdentity = false;
+	mOldMatrix = mMatrix;
 	mMatrix = mMatrix * trafo;
 }
@@ -50,4 +49,5 @@
 	mIsIdentity = true;
 	mMatrix = IdentityMatrix();
+	mOldMatrix = mMatrix;
 }
 
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp	(revision 3113)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp	(revision 3114)
@@ -908,5 +908,5 @@
 
 	oldTrafo = buddha->GetTransform()->GetMatrix();
-	vtxParams->SetMatrix(2, oldTrafo);
+	//vtxParams->SetMatrix(2, oldTrafo);
 
 	Vector3 buddhaPos = motionPath->GetCurrentPosition();
@@ -915,5 +915,5 @@
 	buddha->GetTransform()->SetMatrix(trafo);
 
-	vtxParams->SetMatrix(1, buddha->GetTransform()->GetMatrix());
+	//vtxParams->SetMatrix(1, buddha->GetTransform()->GetMatrix());
 
 
