Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ShaderProgram.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ShaderProgram.cpp	(revision 3036)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ShaderProgram.cpp	(revision 3041)
@@ -1,4 +1,5 @@
 #include "ShaderProgram.h"
 #include "Matrix4x4.h"
+#include "Timer/PerfTimer.h"
 
 
@@ -10,5 +11,5 @@
 
 GPUProgramParameters::GPUProgramParameters(ShaderProgram *p)
-: mProgram(p)
+: mProgram(p), mTimer(-1)
 {
 }
@@ -21,4 +22,6 @@
 	mMatrices.clear();
 	mArrays.clear();
+
+	mTimer = -1;
 }
 
@@ -97,4 +100,10 @@
 
 	mMatrices[idx] = MatrixParam(mat);
+}
+
+
+void GPUProgramParameters::SetTimerParam(int idx)
+{
+	mTimer = idx;
 }
 
@@ -208,4 +217,10 @@
 			mProgram->SetArray1f(i, p.mValues, p.mNumEntries);
 		}
+	}
+
+	if (mTimer >= 0)
+	{
+		static PerfTimer mytimer;
+		mProgram->SetValue1f(mTimer, mytimer.Elapsedms(false) * M_PI / 180.0f);
 	}
 }
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/sky_preetham.cg
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/sky_preetham.cg	(revision 3040)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/sky_preetham.cg	(revision 3041)
@@ -1,8 +1,2 @@
-//--------------------------------------------------------------------------------------
-// Input and Output structs
-//--------------------------------------------------------------------------------------
-
-
-
 struct vtxin
 {
@@ -17,12 +11,10 @@
 struct vtxout
 {
-	float4 position: POSITION; // eye space
+	float4 color: COLOR0;  
+	float4 position: POSITION; 
+
 	float4 texCoord: TEXCOORD0;    
-
-	float4 color: COLOR0;  
-	float4 worldPos: TEXCOORD1; // world position
-	float3 normal: TEXCOORD2;
-	float4 mypos: TEXCOORD3;
-	float4 hdrColor: TEXCOORD4;
+	float3 normal: TEXCOORD1;
+	float4 hdrColor: TEXCOORD2;
 };
 
@@ -32,17 +24,17 @@
 {
 	float4 color: COLOR0;  
-	float4 position: POSITION; // eye space
+	//float4 projPos: WPOS;
+	//float4 position: POSITION;
+
 	float4 texCoord: TEXCOORD0;    
-
-	float4 projPos: WPOS;
-	float3 normal: TEXCOORD2;
-	float4 hdrColor: TEXCOORD4;
+	float3 normal: TEXCOORD1;
+	float4 hdrColor: TEXCOORD2;
 };
 
 
-struct fragout
+struct pixel
 {
 	float4 col: COLOR0;
-	float4 norm: COLOR1;
+	float3 norm: COLOR1;
 	float3 pos: COLOR2;
 };
@@ -104,7 +96,7 @@
 
 
-fragout frag_skydome(fragin IN)
+pixel frag_skydome(fragin IN)
 {
-	fragout pix;
+	pixel pix;
 
 	pix.col = IN.hdrColor;
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/treeanimation.cg
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/treeanimation.cg	(revision 3040)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/treeanimation.cg	(revision 3041)
@@ -8,20 +8,18 @@
 	float4 position: POSITION;
 	float3 normal: NORMAL;
-	float3 color: COLOR;
-	float2 texcoord: TEXCOORD0;
+	float4 color: COLOR;
+	float4 texCoord: TEXCOORD0;
 };
-
 
 // vtx output
 struct vtxout
 {
-	float4 position: POSITION; // eye space
+	float4 position: POSITION;
 	float4 texCoord: TEXCOORD0;    
 
 	float4 color: COLOR0;  
+	float4 eyePos: TEXCOORD1; // eye position
 	float3 normal: TEXCOORD2;
-	float4 eyePos: TEXCOORD3;
 };
-
 
 
@@ -34,22 +32,25 @@
 				  uniform float3 windDir,
 				  uniform float windStrength,
-				  uniform float2 minmaxPos,
+				  uniform float frequency,
+				  uniform float2 minMaxPos,
 				  uniform float timer)
 {
 	vtxout OUT;
 
-	OUT.color = IN.color;
+	OUT.color = float4(0);//IN.color;
 	OUT.texCoord = IN.texCoord;
+		
+	const float pos = (minMaxPos.x - IN.position.z) / (minMaxPos.x - minMaxPos.y);
+
+	float factor = pos * windStrength * sin(timer * frequency);
+
+	// transform the vertex position into post projection space
+	OUT.position = mul(glstate.matrix.mvp, IN.position);
+	// displace the input position
+	OUT.position += float4(factor * windDir, 0);
+
 	// transform the vertex position into eye space
 	OUT.eyePos = mul(glstate.matrix.modelview[0], IN.position);
-	
-	const float pos = (minmaxPos.x - IN.position.y / (minmaxPos.x - minmaxPos.y);
-
-	float factor = windStrength * sin(timer);
-
-	// displace the input position
-	float4 newPos = IN.position + float4(factor * windDir, 0.0f);
-	// transform the vertex position into post projection space
-	OUT.position = mul(glstate.matrix.mvp, IN.position);
+	OUT.eyePos += float4(factor * windDir, 0);
 
 	OUT.normal = IN.normal;
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/mrt.cg
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/mrt.cg	(revision 3034)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/mrt.cg	(revision 3041)
@@ -8,13 +8,14 @@
 };
 
+
 // vtx output
 struct vtxout
 {
-  float4 position: POSITION; // eye space
-  float4 texCoord: TEXCOORD0;    
+	float4 position: POSITION;
+	float4 texCoord: TEXCOORD0;    
 
-  float4 color: COLOR0;  
-  float4 eyePos: TEXCOORD1; // eye position
-  float3 normal: TEXCOORD2;
+	float4 color: COLOR0;  
+	float4 eyePos: TEXCOORD1; // eye position
+	float3 normal: TEXCOORD2;
 };
 
@@ -60,5 +61,4 @@
 }
 
-//#pragma position_invariant fragtex
 
 pixel fragtex(fragin IN, 
@@ -78,10 +78,8 @@
 	// save world space normal in rt
 	pix.norm = IN.normal;
-
+	// 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;
-
-	// compute eye linear depth
-	pix.col.w = length(IN.eyePos.xyz);
 
 	return pix;
@@ -92,12 +90,10 @@
 {
 	pixel pix;
-
 	// hack: use comination of emmisive + diffuse (emmisive used as constant ambient term)
 	pix.col = glstate.material.diffuse + glstate.material.emission;
-
+	// save world space normal in rt
 	pix.norm = IN.normal;
-
+	// 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;
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ResourceManager.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ResourceManager.cpp	(revision 3039)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ResourceManager.cpp	(revision 3041)
@@ -42,5 +42,5 @@
 static CGprofile sCgFragmentProfile;
 static CGprofile sCgVertexProfile; 
-
+static ShaderProgram *sTreeAnimation;
 
 // only instance of the resource manager
@@ -141,5 +141,5 @@
 			// create shape
 			Shape *shape = new Shape(geom, mat, sceneGeom);
-			
+
 			mShapes.push_back(shape);
 
@@ -150,4 +150,37 @@
 		mLODs.push_back(lodLevel);
 		sceneGeom->AddLODLevel(lodLevel);
+	}
+
+	///////////
+	//-- hack: tree animation
+
+	if (numLODs > 1)
+	{
+		for (int i = 0; i < min(numLODs, 2); ++ i)
+		{
+			ShapeContainer::iterator sstart, send;
+			sceneGeom->GetLODLevel(i, sstart, send);
+
+			for (ShapeContainer::iterator it = sstart; it != send; ++ it)
+			{
+				Shape *shape = *it;
+				Material *mat = shape->GetMaterial();
+				mat->SetVertexProgram(sTreeAnimation);
+
+				GPUProgramParameters *vtxParams = mat->GetVertexProgramParameters();
+
+				vtxParams->SetTimerParam(0);
+				// wind direction
+				static Vector3 windDir = Normalize(Vector3(0.8f, 0.2f, 0.0f));
+				vtxParams->SetValue3f(1, windDir.x, windDir.y, windDir.z);
+				// amplitude
+				vtxParams->SetValue1f(2, 0.3f);
+
+				AxisAlignedBox3 box = sceneGeom->GetBoundingBox();
+				vtxParams->SetValue2f(3, box.Min().z, box.Max().z);
+				// frequency
+				vtxParams->SetValue1f(4, 0.1f);
+			}
+		}
 	}
 
@@ -256,5 +289,5 @@
 	mat->mVertexProgram = mMrtDefaultVertexProgram;
 	mat->mGPUVertexParameters = CreateGPUProgramParameters(mat->mVertexProgram);
-
+	
 	return mat;
 }
@@ -424,4 +457,12 @@
 	mMrtDefaultFragmentTexProgram->AddParameter("tex", 0);
 
+	sTreeAnimation = CreateVertexProgram("treeanimation", "animateVtx");
+
+	sTreeAnimation->AddParameter("timer", 0);
+	sTreeAnimation->AddParameter("windDir", 1);
+	sTreeAnimation->AddParameter("windStrength", 2);
+	sTreeAnimation->AddParameter("minMaxPos", 3);
+	sTreeAnimation->AddParameter("frequency", 4);
+
 	cout << "cg initialization successful" << endl;
 }
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SkyPreetham.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SkyPreetham.cpp	(revision 3039)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SkyPreetham.cpp	(revision 3041)
@@ -141,4 +141,7 @@
 	mSkyDome->GetShape(0)->GetMaterial()->GetVertexProgram()->Bind();
 
+	mSkyDome->GetShape(0)->GetMaterial()->GetFragmentProgramParameters()->UpdateParameters();
+	mSkyDome->GetShape(0)->GetMaterial()->GetFragmentProgram()->Bind();
+
 	// Render sky dome.
 	mSkyDome->Render(state);
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ShaderProgram.h
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ShaderProgram.h	(revision 3038)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ShaderProgram.h	(revision 3041)
@@ -53,4 +53,6 @@
 	void SetArray2f(int idx, float *vals, int numElements);
 	void SetArray3f(int idx, float *vals, int numElements);
+
+	void SetTimerParam(int idx);
 
 	/** Sets the texture parameter.
@@ -142,4 +144,5 @@
 	ShaderProgram *mProgram;
 
+	int mTimer;
 	std::vector<FloatParam> mFloats;
 	std::vector<IntParam> mTextures;
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp	(revision 3040)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp	(revision 3041)
@@ -477,6 +477,4 @@
 	skyDome = sceneEntities.back();
 
-	//InitCg();
-	ShaderProgram *treeAnimation = loader->CreateVertexProgram("treeanimation", "animateVtx");
 	const float turbitiy = 5.0f;
 	preetham = new SkyPreetham(turbitiy, skyDome);
