Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Material.h
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Material.h	(revision 3034)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Material.h	(revision 3036)
@@ -80,9 +80,16 @@
 	void InitMaterial();
 
-	GPUProgramParameters *mGPUVertexParameters;
-	GPUProgramParameters *mGPUFragmentParameters;
+	void SetFragmentProgram(ShaderProgram *p);
+	void SetVertexProgram(ShaderProgram *p);
 
-	ShaderProgram *mFragmentProgram;
-	ShaderProgram *mVertexProgram;
+	ShaderProgram *GetFragmentProgram() { return mFragmentProgram; }
+	ShaderProgram *GetVertexProgram() { return mVertexProgram; }
+
+	void SetFragmentProgramParameters(GPUProgramParameters *p) { mGPUFragmentParameters = p; }
+	void SetVertexProgramParameters(GPUProgramParameters *p) { mGPUVertexParameters = p; }
+
+	GPUProgramParameters *GetFragmentProgramParameters() { return mGPUFragmentParameters; }
+	GPUProgramParameters *GetVertexProgramParameters() { return mGPUVertexParameters; }
+
 
 protected:
@@ -99,4 +106,10 @@
 	/// the associated texture
 	Texture *mTexture;
+
+	GPUProgramParameters *mGPUVertexParameters;
+	GPUProgramParameters *mGPUFragmentParameters;
+
+	ShaderProgram *mFragmentProgram;
+	ShaderProgram *mVertexProgram;
 };
 
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ShaderProgram.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ShaderProgram.cpp	(revision 3034)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ShaderProgram.cpp	(revision 3036)
@@ -14,6 +14,20 @@
 }
 
+
+void GPUProgramParameters::Reset()
+{
+	mFloats.clear();
+	mTextures.clear();
+	mMatrices.clear();
+	mArrays.clear();
+}
+
+
 void GPUProgramParameters::SetValue1f(int idx, float value)
 {
+	if (mFloats.size() < idx + 1)
+		mFloats.resize(idx + 1);
+
+	mFloats[idx] = FloatParam(&value, 1);
 }
 
@@ -21,9 +35,21 @@
 void GPUProgramParameters::SetValue2f(int idx, float val1, float val2)
 {
-}
-
-
-void GPUProgramParameters::SetValue3f(int idx, float val1, float val, float val3)
-{
+	if (mFloats.size() < idx + 1)
+		mFloats.resize(idx + 1);
+
+	float vals[] = {val1, val2};
+
+	mFloats[idx] = FloatParam(vals, 2);
+}
+
+
+void GPUProgramParameters::SetValue3f(int idx, float val1, float val2, float val3)
+{
+	if (mFloats.size() < idx + 1)
+		mFloats.resize(idx + 1);
+
+	float vals[] = {val1, val2, val3};
+
+	mFloats[idx] = FloatParam(vals, 3);
 }
 
@@ -31,4 +57,8 @@
 void GPUProgramParameters::SetArray1f(int idx, float *vals, int numElements)
 {
+	if (mArrays.size() < idx + 1)
+		mArrays.resize(idx + 1);
+
+	mArrays[idx] = ArrayParam(vals, 1, numElements);
 }
 
@@ -36,4 +66,8 @@
 void GPUProgramParameters::SetArray2f(int idx, float *vals, int numElements)
 {
+	if (mArrays.size() < idx + 1)
+		mArrays.resize(idx + 1);
+
+	mArrays[idx] = ArrayParam(vals, 2, numElements);
 }
 
@@ -41,4 +75,8 @@
 void GPUProgramParameters::SetArray3f(int idx, float *vals, int numElements)
 {
+	if (mArrays.size() < idx + 1)
+		mArrays.resize(idx + 1);
+
+	mArrays[idx] = ArrayParam(vals, 3, numElements);
 }
 
@@ -46,5 +84,8 @@
 void GPUProgramParameters::SetTexture(int idx, unsigned int tex)
 {
-	mTextures.push_back(IntParam(idx, tex));
+	if (mTextures.size() < idx + 1)
+		mTextures.resize(idx + 1);
+
+	mTextures[idx] = IntParam(tex);
 }
 
@@ -52,4 +93,8 @@
 void GPUProgramParameters::SetMatrix(int idx, Matrix4x4 *mat)
 {
+	if (mMatrices.size() < idx + 1)
+		mMatrices.resize(idx + 1);
+
+	mMatrices[idx] = MatrixParam(mat);
 }
 
@@ -105,34 +150,62 @@
 void GPUProgramParameters::UpdateParameters()
 {
-	for (size_t i = 0; i < mFloats.size(); ++ i)
+	for (int i = 0; i < (int)mFloats.size(); ++ i)
 	{
 		const FloatParam &p = mFloats[i];
+
+		if (!p.mValid) continue;
 
 		switch (p.mNumComponents)
 		{
 		case 1:
-			mProgram->SetValue1f(p.mIndex, p.mValues[0]);
+			mProgram->SetValue1f(i, p.mValues[0]);
 			break;
 		case 2:
-			mProgram->SetValue2f(p.mIndex, p.mValues[0], p.mValues[1]);
+			mProgram->SetValue2f(i, p.mValues[0], p.mValues[1]);
 			break;
 		case 3:
-			mProgram->SetValue3f(p.mIndex, p.mValues[0], p.mValues[1], p.mValues[2]);
+			mProgram->SetValue3f(i, p.mValues[0], p.mValues[1], p.mValues[2]);
 			break;
 		default:
-			mProgram->SetValue1f(p.mIndex, p.mValues[0]);
+			mProgram->SetValue1f(i, p.mValues[0]);
 		}
 	}
 
-	for (size_t i = 0; i < mTextures.size(); ++ i)
+	for (int i = 0; i < (int)mTextures.size(); ++ i)
 	{
 		const IntParam &p = mTextures[i];
-		mProgram->SetTexture(p.mIndex, p.mValue);
-	}
-
-	for (size_t i = 0; i < mMatrices.size(); ++ i)
+
+		if (p.mValid)
+			mProgram->SetTexture(i, p.mValue);
+	}
+
+	for (int i = 0; i < (int)mMatrices.size(); ++ i)
 	{
 		const MatrixParam &p = mMatrices[i];
-		mProgram->SetMatrix(p.mIndex, *p.mValue);
+
+		if (p.mValid)
+			mProgram->SetMatrix(i, *p.mValue);
+	}
+	
+	for (int i = 0; i < (int)mArrays.size(); ++ i)
+	{
+		const ArrayParam &p = mArrays[i];
+
+		if (!p.mValid) continue;
+
+		switch (p.mNumComponents)
+		{
+		case 1:
+			mProgram->SetArray1f(i, p.mValues, p.mNumEntries);
+			break;
+		case 2:
+			mProgram->SetArray2f(i, p.mValues, p.mNumEntries);
+			break;
+		case 3:
+			mProgram->SetArray3f(i, p.mValues, p.mNumEntries);
+			break;
+		default:
+			mProgram->SetArray1f(i, p.mValues, p.mNumEntries);
+		}
 	}
 }
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderState.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderState.cpp	(revision 3034)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderState.cpp	(revision 3036)
@@ -152,13 +152,13 @@
 	if (mRenderType == DEFERRED)
 	{
-		if (mat->mFragmentProgram && (mat->mFragmentProgram != mCurrentFragmentProgram))
-		{
-			mCurrentFragmentProgram = mat->mFragmentProgram;
+		if (mat->GetFragmentProgram() && (mat->GetFragmentProgram() != mCurrentFragmentProgram))
+		{
+			mCurrentFragmentProgram = mat->GetFragmentProgram();
 			mCurrentFragmentProgram->Bind();
 		}
 	
-		if (mat->mVertexProgram && (mat->mVertexProgram != mCurrentVertexProgram))
-		{
-			mCurrentVertexProgram = mat->mVertexProgram;
+		if (mat->GetVertexProgram() && (mat->GetVertexProgram() != mCurrentVertexProgram))
+		{
+			mCurrentVertexProgram = mat->GetVertexProgram();
 			mCurrentVertexProgram->Bind();
 		}
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ResourceManager.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ResourceManager.cpp	(revision 3034)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ResourceManager.cpp	(revision 3036)
@@ -43,4 +43,5 @@
 	CLEAR_CONTAINER(mShapes);
 	CLEAR_CONTAINER(mLODs);
+	CLEAR_CONTAINER(mGPUParameters);
 }
 
@@ -206,5 +207,5 @@
 		mat->mFragmentProgram = RenderState::sCgMrtFragmentTexProgram;
 
-		mat->mGPUFragmentParameters = new GPUProgramParameters(mat->mFragmentProgram);
+		mat->mGPUFragmentParameters = CreateGPUProgramParameters(mat->mFragmentProgram);
 		mat->mGPUFragmentParameters->SetTexture(0, mat->GetTexture()->GetId());
 	}	
@@ -212,8 +213,8 @@
 	{
 		mat->mFragmentProgram = RenderState::sCgMrtFragmentProgram;
-		mat->mGPUFragmentParameters = new GPUProgramParameters(mat->mFragmentProgram);
-	}
-
-	mat->mGPUVertexParameters = new GPUProgramParameters(RenderState::sCgMrtVertexProgram);
+		mat->mGPUFragmentParameters = CreateGPUProgramParameters(mat->mFragmentProgram);
+	}
+
+	mat->mGPUVertexParameters = CreateGPUProgramParameters(RenderState::sCgMrtVertexProgram);
 
 	return mat;
@@ -314,3 +315,13 @@
 }
 
-}
+
+GPUProgramParameters *ResourceManager::CreateGPUProgramParameters(ShaderProgram *p)
+{
+	GPUProgramParameters *gpuParams = new GPUProgramParameters(p);
+	mGPUParameters.push_back(gpuParams);
+
+	return gpuParams;
+}
+
+}
+
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SkyPreetham.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SkyPreetham.cpp	(revision 3021)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SkyPreetham.cpp	(revision 3036)
@@ -6,4 +6,7 @@
 #include "Camera.h"
 #include "RenderState.h"
+#include "ShaderProgram.h"
+#include "Shape.h"
+#include "Material.h"
 
 
@@ -23,17 +26,6 @@
 
 
-static CGprogram sCgSkyProgram = NULL;
-static CGprogram sCgMrtFragmentSkyDomeProgram = NULL;
-
-
-static CGparameter sLightDirParam;
-static CGparameter sThetaSunParam;
-static CGparameter sZenithColorParam;
-static CGparameter sAColorParam;
-static CGparameter sBColorParam;
-static CGparameter sCColorParam;
-static CGparameter sDColorParam;
-static CGparameter sEColorParam;
-static CGparameter sMultiplierParam;
+static ShaderProgram *sCgSkyProgram = NULL;
+static ShaderProgram *sCgMrtFragmentSkyDomeProgram = NULL;
 
 ShaderContainer SkyPreetham::sShaders;
@@ -54,53 +46,37 @@
 void SkyPreetham::InitCG(CGcontext context)
 {	
-	ShaderProgram *pr;
-
-	sCgSkyProgram = 
-		cgCreateProgramFromFile(context, 
-								CG_SOURCE,
-								"src/shaders/sky_preetham.cg", 
-								RenderState::sCgVertexProfile,
-								"default_vs",
-								NULL);
-
-	if (sCgSkyProgram != NULL)
+	sCgSkyProgram = new ShaderProgram(context, 
+		                              "src/shaders/sky_preetham.cg",
+									  RenderState::sCgVertexProfile,	
+									  "default_vs");
+
+	if (sCgSkyProgram->IsValid())
 	{
-		cgGLLoadProgram(sCgSkyProgram);
-
-		sLightDirParam = cgGetNamedParameter(sCgSkyProgram, "lightDir");
-		sThetaSunParam = cgGetNamedParameter(sCgSkyProgram, "thetaSun");
-		sZenithColorParam = cgGetNamedParameter(sCgSkyProgram, "zenithColor");
-		sAColorParam = cgGetNamedParameter(sCgSkyProgram, "aColor");
-		sBColorParam = cgGetNamedParameter(sCgSkyProgram, "bColor");
-		sCColorParam = cgGetNamedParameter(sCgSkyProgram, "cColor");
-		sDColorParam = cgGetNamedParameter(sCgSkyProgram, "dColor");
-		sEColorParam = cgGetNamedParameter(sCgSkyProgram, "eColor");
-
-		sMultiplierParam = cgGetNamedParameter(sCgSkyProgram, "multiplier");
-
-		pr = new ShaderProgram(sCgSkyProgram);
-		sShaders.push_back(pr);
+		sCgSkyProgram->AddParameter("lightDir", 0);
+		sCgSkyProgram->AddParameter("thetaSun", 1);
+		sCgSkyProgram->AddParameter("zenithColor", 2);
+		sCgSkyProgram->AddParameter("aColor", 3);
+		sCgSkyProgram->AddParameter("bColor", 4);
+		sCgSkyProgram->AddParameter("cColor", 5);
+		sCgSkyProgram->AddParameter("dColor", 6);
+		sCgSkyProgram->AddParameter("eColor", 7);
+		sCgSkyProgram->AddParameter("multiplier", 8);
 	}
 	else
 		cerr << "sky program failed to load" << endl;
 
+		sShaders.push_back(sCgSkyProgram);
+
 	sCgMrtFragmentSkyDomeProgram = 
-		cgCreateProgramFromFile(context, 
-								CG_SOURCE,
-								"src/shaders/sky_preetham.cg", 
-								RenderState::sCgFragmentProfile,
-								"frag_skydome",
-								NULL);
-
-	if (sCgMrtFragmentSkyDomeProgram != NULL)
-	{
-		cgGLLoadProgram(sCgMrtFragmentSkyDomeProgram);
-		//cgGLSetParameter1f(sMaxDepthParam, MAX_DEPTH_CONST / farDist);
-
-		pr = new ShaderProgram(sCgMrtFragmentSkyDomeProgram);
-		sShaders.push_back(pr);
-	}
-	else
+		new ShaderProgram(context, 
+		                  "src/shaders/sky_preetham.cg", 
+						  RenderState::sCgFragmentProfile,
+						  "frag_skydome");
+
+	// simple shader used for just pushing out the fragments to the mrts
+	if (!sCgMrtFragmentSkyDomeProgram->IsValid())
 		cerr << "fragment skyprogram failed to load" << endl;
+	
+	sShaders.push_back(sCgMrtFragmentSkyDomeProgram);
 }
 
@@ -118,4 +94,10 @@
 {
 	CreateSunQuad();
+	Shape *shape = mSkyDome->GetShape(0);
+
+	Material *mat = shape->GetMaterial();
+
+	mat->SetFragmentProgram(sCgMrtFragmentSkyDomeProgram);
+	mat->SetVertexProgram(sCgSkyProgram);
 }
 
@@ -135,4 +117,5 @@
 	Vector3 zenithColor;
 	vector<Vector3> ABCDE;
+
 	ComputeFactors(sunDir, zenithColor, ABCDE, sun_theta);
 
@@ -149,34 +132,29 @@
 	mSkyDome->GetTransform()->SetMatrix(s * m);
 	
-	cgGLSetParameter3f(sLightDirParam, sunDir.x, sunDir.y, sunDir.z);
-	cgGLSetParameter2f(sThetaSunParam, sun_theta.first, sun_theta.second);
-	cgGLSetParameter3f(sZenithColorParam, zenithColor.x, zenithColor.y, zenithColor.z);
-
-	cgGLSetParameter3f(sAColorParam, ABCDE[0].x, ABCDE[0].y, ABCDE[0].z);
-	cgGLSetParameter3f(sBColorParam, ABCDE[1].x, ABCDE[1].y, ABCDE[1].z);
-	cgGLSetParameter3f(sCColorParam, ABCDE[2].x, ABCDE[2].y, ABCDE[2].z);
-	cgGLSetParameter3f(sDColorParam, ABCDE[3].x, ABCDE[3].y, ABCDE[3].z);
-	cgGLSetParameter3f(sEColorParam, ABCDE[4].x, ABCDE[4].y, ABCDE[4].z);
-
-	if (state->GetRenderPassType() == RenderState::DEFERRED)
-	{
-		cgGLEnableProfile(RenderState::sCgFragmentProfile);
-		cgGLBindProgram(sCgMrtFragmentSkyDomeProgram);
-
-	}
+	GPUProgramParameters *vtxParams = mSkyDome->GetShape(0)->GetMaterial()->GetVertexProgramParameters();
+
+	vtxParams->SetValue3f(0, sunDir.x, sunDir.y, sunDir.z);
+	vtxParams->SetValue2f(1, sun_theta.first, sun_theta.second);
+	vtxParams->SetValue3f(2, zenithColor.x, zenithColor.y, zenithColor.z);
+
+	vtxParams->SetValue3f(3, ABCDE[0].x, ABCDE[0].y, ABCDE[0].z);
+	vtxParams->SetValue3f(4, ABCDE[1].x, ABCDE[1].y, ABCDE[1].z);
+	vtxParams->SetValue3f(5, ABCDE[2].x, ABCDE[2].y, ABCDE[2].z);
+	vtxParams->SetValue3f(6, ABCDE[3].x, ABCDE[3].y, ABCDE[3].z);
+	vtxParams->SetValue3f(7, ABCDE[4].x, ABCDE[4].y, ABCDE[4].z);
+
 
 	if (!scaleToRange)
 	{	
 		// use tone mapping
-		cgGLSetParameter1f(sMultiplierParam, 1.0f);
+		sCgSkyProgram->SetValue1f(8, 1.0f);
 	}
 	else
 	{
 		// no tone mapping => scale
-		cgGLSetParameter1f(sMultiplierParam, 8e-5f);
+		sCgSkyProgram->SetValue1f(8, 8e-5f);
 	}
 
 	cgGLEnableProfile(RenderState::sCgVertexProfile);
-	cgGLBindProgram(sCgSkyProgram);
 
 	// Render sky dome.
@@ -185,6 +163,4 @@
 	// Render additively blended sun disc.
 	//RenderSunDisk(sunDir, camera);
-
-	cgGLDisableProfile(RenderState::sCgFragmentProfile);
 }
 
@@ -192,4 +168,5 @@
 void SkyPreetham::RenderSunDisk(const Vector3 &sunDir, Camera *camera)
 {
+#if TODOD
 	// Move skybox with camera.
 	Vector3 position = camera->GetPosition();
@@ -212,6 +189,6 @@
 	sunPos *= rotx;;
 
-	//sunposition.rotateAroundY(-D().getScene().getLight().getHorizontalOrientation() + 90.0f);
-	//sunposition.rotateAroundX(-D().getScene().getLight().getVerticalOrientation());
+	sunposition.rotateAroundY(-D().getScene().getLight().getHorizontalOrientation() + 90.0f);
+	sunposition.rotateAroundX(-D().getScene().getLight().getVerticalOrientation());
 	
 	glMatrixMode(GL_MODELVIEW);
@@ -222,18 +199,19 @@
 	glMaterialfv(GL_FRONT, GL_AMBIENT, ambient);
 
-	//Float size = 0.5f + (1.0f - lightdirection.y) * 0.5f;
-
-	//mSunEffect->setVariableVector3("LightDiffuseColor", D().getScene().getLight().getDiffuseColor());
-	//mSunEffect->setVariableFloat("SunSize", size);
-	//mSunEffect->setVariableTexture2D("SunTexture", mSunTexture);
-
-	/*mSunEffect->activate();
+	Float size = 0.5f + (1.0f - lightdirection.y) * 0.5f;
+
+	mSunEffect->setVariableVector3("LightDiffuseColor", D().getScene().getLight().getDiffuseColor());
+	mSunEffect->setVariableFloat("SunSize", size);
+	mSunEffect->setVariableTexture2D("SunTexture", mSunTexture);
+
+	mSunEffect->activate();
 	
 	mSunQuad->render();
 
 	mSunEffect->deactivate();
-	F().getRenderDevice().setDefaultBlendingMode(FRenderDevice::BLENDING_NONE);*/
+	F().getRenderDevice().setDefaultBlendingMode(FRenderDevice::BLENDING_NONE);
 
 	glPopMatrix();
+#endif
 }
 
@@ -241,5 +219,5 @@
 void SkyPreetham::CreateSunQuad()
 {
-	/*
+#if TODO
 	mSunQuad = new FVertexBuffer();
 	mSunQuad->setupPrimitiveType(FVertexBuffer::PRIMITIVES_TRIANGLES);
@@ -263,5 +241,5 @@
 	mSunQuad->setIndex(4, 1);
 	mSunQuad->setIndex(5, 3);
-	*/
+#endif
 }
 
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ShaderProgram.h
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ShaderProgram.h	(revision 3034)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ShaderProgram.h	(revision 3036)
@@ -36,4 +36,14 @@
 public:
 
+	/** Constructor which initialized this parameter set for a given program.
+	*/
+	GPUProgramParameters(ShaderProgram *p);
+
+	void SetProgram(ShaderProgram *p) { mProgram = p; }
+	/** Resets this parameter set.
+	*/
+	void Reset();
+
+
 	///////////
 	//-- set parameters by index
@@ -66,5 +76,4 @@
 	void SetArray2f(const std::string &name, float *vals, int numElements);
 	void SetArray3f(const std::string &name, float *vals, int numElements);
-
 	/** Sets the texture parameter.
 	*/
@@ -76,8 +85,5 @@
 	*/
 	void UpdateParameters();
-
-
-	GPUProgramParameters(ShaderProgram *p);
-
+	
 
 protected:
@@ -85,5 +91,16 @@
 	struct FloatParam
 	{
-		int mIndex;
+		FloatParam(): mValid(false), mNumComponents(0) {}
+
+		FloatParam(float *val, int comp): 
+		mNumComponents(comp), mValid(true)
+		{
+			for (int i = 0; i < mNumComponents; ++ i)
+			{
+				mValues[i] = val[i];
+			}
+		}
+
+		bool mValid;
 		float mValues[4];
 		int mNumComponents;
@@ -92,7 +109,8 @@
 	struct IntParam
 	{
-		IntParam(int idx, float val): mIndex(idx), mValue(val) {}
-
-		int mIndex;
+		IntParam(): mValid(false) {}
+		IntParam(float val): mValue(val), mValid(true) {}
+
+		bool mValid;
 		float mValue;
 	};
@@ -100,5 +118,10 @@
 	struct MatrixParam
 	{
-		int mIndex;
+		MatrixParam(): mValue(NULL), mValid(false) {}
+
+		MatrixParam(Matrix4x4 *mat): mValue(mat), mValid(true)
+		{}
+
+		bool mValid;
 		Matrix4x4 *mValue;
 	};
@@ -106,9 +129,13 @@
 	struct ArrayParam
 	{
-		int mIndex;
-
+		ArrayParam(): mValues(NULL), mNumEntries(0), mNumComponents(0), mValid(false) {}
+		ArrayParam(float *val, int comp, int numEntries): 
+		mValues(val), mNumComponents(comp), mNumEntries(numEntries), mValid(true)
+		{}
+
+		bool mValid;
 		float *mValues;
+
 		int mNumEntries;
-
 		int mNumComponents;
 	};
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ResourceManager.h
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ResourceManager.h	(revision 3020)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ResourceManager.h	(revision 3036)
@@ -23,4 +23,6 @@
 class Matrix4x4;
 class Transform3;
+class ShaderProgram;
+class GPUProgramParameters;
 
 
@@ -37,4 +39,8 @@
 
 	int GetNumEntities() const { return (int)mSceneEntities.size(); }
+
+	/** Creates new gpu program parameters.
+	*/
+	GPUProgramParameters *CreateGPUProgramParameters(ShaderProgram *p);
 
 protected:
@@ -54,9 +60,10 @@
 
 	// these are kept to be able to delete these resources afterwards
-	std::vector<Texture *> mTextures;
-	std::vector<Material *> mMaterials;
-	std::vector<Geometry *> mGeometry;
-	std::vector<Transform3 *> mTrafos;
-	
+	TextureContainer mTextures;
+	MaterialContainer mMaterials;
+	GeometryContainer mGeometry;
+	TransformContainer mTrafos;
+	GPUParamContainer mGPUParameters;
+
 	ShapeContainer mShapes;
 
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Material.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Material.cpp	(revision 3034)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Material.cpp	(revision 3036)
@@ -44,6 +44,6 @@
 Material::~Material()
 {
-	DEL_PTR(mGPUFragmentParameters);
-	DEL_PTR(mGPUVertexParameters);
+	//DEL_PTR(mGPUFragmentParameters);
+	//DEL_PTR(mGPUVertexParameters);
 }
 
@@ -93,3 +93,20 @@
 
 
+void Material::SetFragmentProgram(ShaderProgram *p) 
+{ 
+	mFragmentProgram = p; 
+
+	mGPUFragmentParameters->Reset();
+	mGPUFragmentParameters->SetProgram(p);
 }
+	
+
+void Material::SetVertexProgram(ShaderProgram *p) 
+{ 
+	mVertexProgram = p; 
+
+	mGPUVertexParameters->Reset();
+	mGPUVertexParameters->SetProgram(p);
+}
+
+}
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp	(revision 3034)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp	(revision 3036)
@@ -1967,5 +1967,7 @@
 		state.SetRenderPassType(RenderState::DEFERRED);
 
-	const bool useToneMapping = ((renderMethod == RENDER_DEPTH_PASS_DEFERRED) || (renderMethod == RENDER_DEFERRED)) && useHDR;
+	const bool useToneMapping = 
+		((renderMethod == RENDER_DEPTH_PASS_DEFERRED) || 
+		 (renderMethod == RENDER_DEFERRED)) && useHDR;
 
 	preetham->RenderSkyDome(-light->GetDirection(), camera, &state, !useToneMapping);
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.cpp	(revision 3035)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.cpp	(revision 3036)
@@ -382,4 +382,13 @@
 	sCgDeferredShadowProgram->AddParameter("weights", 9);
 
+	sCgCombineIllumProgram->AddParameter("colors", 0);
+	sCgCombineIllumProgram->AddParameter("ssaoTex", 1);
+	sCgCombineIllumProgram->AddParameter("illumTex", 2);
+
+	sCgCombineSsaoProgram->AddParameter("colors", 0);
+	sCgCombineSsaoProgram->AddParameter("ssaoTex", 1);
+	sCgCombineSsaoProgram->AddParameter("filterOffs", 2);
+	sCgCombineSsaoProgram->AddParameter("filterWeights", 3);
+
 
 	float filterWeights[NUM_PCF_TABS];
@@ -726,7 +735,7 @@
 	glDrawBuffers(1, mrt + colorBufferIdx);
 
-	sCgCombineIllumProgram->SetTexture("colors", colorsTex);
-	sCgCombineIllumProgram->SetTexture("ssaoTex", ssaoTex);
-	sCgCombineIllumProgram->SetTexture("illumTex", illumTex);
+	sCgCombineIllumProgram->SetTexture(0, colorsTex);
+	sCgCombineIllumProgram->SetTexture(1, ssaoTex);
+	sCgCombineIllumProgram->SetTexture(2, illumTex);
 	
 	DrawQuad(sCgCombineIllumProgram);
@@ -769,10 +778,10 @@
 	}
 
-	//ComputeSampleOffsets(filterOffsets, fbo->GetWidth(), fbo->GetHeight());
-	sCgCombineSsaoProgram->SetArray2f("filterOffs", (float *)filterOffsets, NUM_DOWNSAMPLES);
-	sCgCombineSsaoProgram->SetArray1f("filterWeights", (float *)filterWeights, NUM_DOWNSAMPLES);
-
-	sCgCombineSsaoProgram->SetTexture("colors", colorsTex);
-	sCgCombineSsaoProgram->SetTexture("ssaoTex", ssaoTex);
+	
+	sCgCombineSsaoProgram->SetTexture(0, colorsTex);
+	sCgCombineSsaoProgram->SetTexture(1, ssaoTex);
+
+	sCgCombineSsaoProgram->SetArray2f(2, (float *)filterOffsets, NUM_DOWNSAMPLES);
+	sCgCombineSsaoProgram->SetArray1f(3, (float *)filterWeights, NUM_DOWNSAMPLES);
 	
 	DrawQuad(sCgCombineSsaoProgram);
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/common.h
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/common.h	(revision 3022)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/common.h	(revision 3036)
@@ -28,9 +28,14 @@
 
 class Shape;
-struct LODLevel;
 class Polygon3;
 class Vector3;
 class Geometry;
+class GPUProgramParameters;
+class Transform3;
+class Texture;
+class Material;
+
 struct LODLevel;
+
 
 
@@ -481,5 +486,4 @@
 typedef std::queue<BvhNode *> BvhNodeQueue;
 
-
 typedef std::vector<Shape *> ShapeContainer;
 typedef std::vector<Geometry *> GeometryContainer;
@@ -487,4 +491,8 @@
 typedef std::vector<Polygon3 *> PolygonContainer;
 typedef std::vector<LODLevel *> LODContainer;
+typedef std::vector<Transform3 *> TransformContainer;
+typedef std::vector<Texture *> TextureContainer;
+typedef std::vector<Material *> MaterialContainer;
+typedef std::vector<GPUProgramParameters *> GPUParamContainer;
 
 typedef std::vector<Vector3> VertexArray;
