Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ShaderProgram.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ShaderProgram.cpp	(revision 3045)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ShaderProgram.cpp	(revision 3046)
@@ -4,4 +4,5 @@
 #include "Vector3.h"
 #include "Camera.h"
+#include "Light.h"
 
 
@@ -13,7 +14,14 @@
 //////////
 //-- changing shader parameters
+
 static float sCurrentTimer = 0;
 static Matrix4x4 sCurrentViewMatrix = IdentityMatrix();
-static Vector3 sCurrentViewVector = Vector3::UNIT_Y();
+static Vector3 sCurrentViewDir = Vector3::UNIT_Y();
+static Vector3 sCurrentLightDir = Vector3::UNIT_Y();
+
+
+/*********************************************************/
+/*         GPUProgramParameters implementation           */
+/*********************************************************/
 
 
@@ -21,6 +29,7 @@
 mProgram(p), 
 mTimerParam(-1),
-mViewVectorParam(-1),
-mViewMatrixParam(-1)
+mViewDirParam(-1),
+mViewMatrixParam(-1),
+mLightDirParam(-1)
 {
 }
@@ -30,6 +39,7 @@
 mProgram(NULL),
 mTimerParam(-1),
-mViewVectorParam(-1),
-mViewMatrixParam(-1)
+mViewDirParam(-1),
+mViewMatrixParam(-1),
+mLightDirParam(-1)
 {
 }
@@ -44,5 +54,6 @@
 
 	mTimerParam = -1;
-	mViewVectorParam = -1;
+	mViewDirParam = -1;
+	mLightDirParam = -1;
 	mViewMatrixParam = -1;
 }
@@ -137,7 +148,13 @@
 
 
-void GPUProgramParameters::SetViewVectorParam(int idx)
-{
-	mViewVectorParam = idx;
+void GPUProgramParameters::SetViewDirParam(int idx)
+{
+	mViewDirParam = idx;
+}
+
+
+void GPUProgramParameters::SetLightDirParam(int idx)
+{
+	mLightDirParam = idx;
 }
 
@@ -258,7 +275,8 @@
 		mProgram->SetValue1f(mTimerParam, sCurrentTimer);
 
-	if (mViewVectorParam >= 0)
-		mProgram->SetValue3f(mViewVectorParam, sCurrentViewVector.x, sCurrentViewVector.y, sCurrentViewVector.z);
-
+	if (mViewDirParam >= 0)
+		mProgram->SetValue3f(mViewDirParam, sCurrentViewDir.x, sCurrentViewDir.y, sCurrentViewDir.z);
+	if (mLightDirParam >= 0)
+		mProgram->SetValue3f(mLightDirParam, sCurrentLightDir.x, sCurrentLightDir.y, sCurrentLightDir.z);
 	if (mViewMatrixParam >= 0)
 		mProgram->SetMatrix(mViewMatrixParam, sCurrentViewMatrix);
@@ -266,5 +284,5 @@
 
 
-void GPUProgramParameters::InitFrame(Camera *cam)
+void GPUProgramParameters::InitFrame(Camera *cam, DirectionalLight *light)
 {
 	static PerfTimer mytimer;
@@ -272,5 +290,11 @@
 
 	cam->GetModelViewMatrix(sCurrentViewMatrix);
-	sCurrentViewVector = cam->GetDirection();
+	sCurrentViewDir = cam->GetDirection();
+
+	Matrix4x4 vo;
+	// transform to view space
+	cam->GetViewOrientationMatrix(vo);
+	//sCurrentLightDir = /*vo **/ -light->GetDirection();
+	sCurrentLightDir = vo * -light->GetDirection();
 }
 
@@ -318,5 +342,5 @@
 
 
-/*void ShaderProgram::Release()
+void ShaderProgram::Release()
 {
 	CGParameterArray::const_iterator it, it_end = mTextureParams.end();
@@ -325,5 +349,5 @@
 	for (it = mTextureParams.begin(); it != it_end; ++ it)
 		cgGLDisableTextureParameter(*it);
-}*/
+}
 
 
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/treeanimation.cg
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/treeanimation.cg	(revision 3045)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/treeanimation.cg	(revision 3046)
@@ -24,5 +24,5 @@
 	//float4 color1: COLOR1;  
 	float4 eyePos: TEXCOORD1; // eye position
-	float3 normal: TEXCOORD2;
+	float4 normal: TEXCOORD2;
 };
 
@@ -40,35 +40,4 @@
 {
 	vtxout OUT;
-
-/*
-// Transform vertex position into homogenous clip-space.
-OUT.HPosition = mul(ModelViewProj, IN.Position);
-// Transform normal from model-space to view-space.
-float3 normalVec = normalize(mul(ModelViewIT,
-IN.Normal).xyz);
-// Store normalized light vector.
-float3 lightVec = normalize(LightVec.xyz);
-// Calculate half angle vector.
-float3 eyeVec = float3(0.0, 0.0, 1.0);
-float3 halfVec = normalize(lightVec + eyeVec);
-// Calculate diffuse component.
-float diffuse = dot(normalVec, lightVec);
-// Calculate specular component.
-float specular = dot(normalVec, halfVec);
-// Use the lit function to compute lighting vector from
-// diffuse and specular values.
-float4 lighting = lit(diffuse, specular, 32);
-// Blue diffuse material
-float3 diffuseMaterial = float3(0.0, 0.0, 1.0);
-// White specular material
-float3 specularMaterial = float3(1.0, 1.0, 1.0);
-// Combine diffuse and specular contributions and
-// output final vertex color.
-OUT.Color.rgb = lighting.y * diffuseMaterial +
-lighting.z * specularMaterial;
-OUT.Color.a = 1.0;
-return OUT;
-}
-*/
 	OUT.texCoord = IN.texCoord;
 		
@@ -81,14 +50,18 @@
 	OUT.position += float4(factor * windDir, 0);
 
-	OUT.normal = mul(glstate.matrix.invtrans.modelview[0], IN.normal);
+	OUT.normal = normalize(mul(glstate.matrix.invtrans.modelview[0], IN.normal));
+	//const float3 l = normalize(mul(glstate.matrix.modelview[0], float4(lightDir, 0))).xyz;
+	const float3 l = normalize(lightDir);
 
-	Out.color = IN.color * max(0, dot(OUT.normal, lightDir));
-	//OUT.color1 = IN.color1;
+	const float dif = max(.0f, dot(OUT.normal.xyz, l));
 
+	//OUT.color.xyz = IN.color.xyz * max(0, dot(OUT.normal.xyz, normalize(lightDir)));
+	OUT.color = glstate.material.ambient + glstate.material.front.diffuse * dif;
+	OUT.color.w = IN.color.w;
 	return OUT;
 }
 
-/** vertex shader which conducts an simple tree animation
-	that bends the tree depending quadratically on the height
+/** vertex shader which provides an simple tree animation
+	that bends the tree depending quadratically on the height using vertex displacement.
 	This version of the shader is used for deferred shading and thus only 
 	displaces the vertices and outputs the color, put does not do any shading.
@@ -104,6 +77,4 @@
 
 	OUT.color = IN.color;
-	//OUT.color1 = IN.color1;
-
 	OUT.texCoord = IN.texCoord;
 		
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/mrt.cg
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/mrt.cg	(revision 3045)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/mrt.cg	(revision 3046)
@@ -90,5 +90,5 @@
 
 
-pixel frag(fragin IN,  uniform float4x4 viewMatrix)
+pixel frag(fragin IN, uniform float4x4 viewMatrix)
 {
 	pixel pix;
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ResourceManager.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ResourceManager.cpp	(revision 3045)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ResourceManager.cpp	(revision 3046)
@@ -42,5 +42,8 @@
 static CGprofile sCgFragmentProfile;
 static CGprofile sCgVertexProfile; 
-static ShaderProgram *sTreeAnimation;
+
+static ShaderProgram *sTreeAnimationProgramMrt;
+static ShaderProgram *sTreeAnimationProgram;
+
 
 // only instance of the resource manager
@@ -153,9 +156,10 @@
 
 	///////////
-	//-- hack: tree animation
+	//-- hack: add tree animation
 
 	if (numLODs > 1)
 	{
-		for (int i = 0; i < min(numLODs, 2); ++ i)
+		//for (int i = 0; i < min(numLODs, 2); ++ i)
+		for (int i = 0; i < numLODs; ++ i)
 		{
 			ShapeContainer::iterator sstart, send;
@@ -172,8 +176,18 @@
 				{
 					Technique *tech = mat->GetTechnique(i);
-					tech->SetVertexProgram(sTreeAnimation);
 
 					GPUProgramParameters *vtxParams = tech->GetVertexProgramParameters();
 
+					if (i == 0)
+					{
+						tech->SetVertexProgram(sTreeAnimationProgram);
+						vtxParams->SetLightDirParam(5);
+					}
+					else
+					{
+						tech->SetVertexProgram(sTreeAnimationProgramMrt);
+					}
+
+					/// use a timer to simulate the moving of the tree in the wind
 					vtxParams->SetTimerParam(0);
 					// wind direction
@@ -352,5 +366,6 @@
 
 
-void ResourceManager::LoadSceneEntities(igzstream &str, SceneEntityContainer &entities)
+void ResourceManager::LoadSceneEntities(igzstream &str, 
+										SceneEntityContainer &entities)
 {
 	int entityCount;
@@ -373,5 +388,6 @@
 
 
-bool ResourceManager::Load(const std::string &filename, SceneEntityContainer &entities)
+bool ResourceManager::Load(const std::string &filename,
+						   SceneEntityContainer &entities)
 {
 	igzstream istr(filename.c_str());
@@ -468,15 +484,26 @@
 	mMrtDefaultFragmentProgram->AddParameter("viewMatrix", 0);
 	mMrtDefaultFragmentTexProgram->AddParameter("viewMatrix", 0);
-
 	// add a texture parameter
 	mMrtDefaultFragmentTexProgram->AddParameter("tex", 1);
 
-	sTreeAnimation = CreateVertexProgram("treeanimation", "animateVtxMrt");
-
-	sTreeAnimation->AddParameter("timer", 0);
-	sTreeAnimation->AddParameter("windDir", 1);
-	sTreeAnimation->AddParameter("windStrength", 2);
-	sTreeAnimation->AddParameter("minMaxPos", 3);
-	sTreeAnimation->AddParameter("frequency", 4);
+
+	////////////
+	//-- hack: apply hardcoded tree animation (should be provided with a material script!)
+
+	sTreeAnimationProgram = CreateVertexProgram("treeanimation", "animateVtx");
+	sTreeAnimationProgramMrt = CreateVertexProgram("treeanimation", "animateVtxMrt");
+
+	sTreeAnimationProgram->AddParameter("timer", 0);
+	sTreeAnimationProgram->AddParameter("windDir", 1);
+	sTreeAnimationProgram->AddParameter("windStrength", 2);
+	sTreeAnimationProgram->AddParameter("minMaxPos", 3);
+	sTreeAnimationProgram->AddParameter("frequency", 4);
+	sTreeAnimationProgram->AddParameter("lightDir", 5);
+
+	sTreeAnimationProgramMrt->AddParameter("timer", 0);
+	sTreeAnimationProgramMrt->AddParameter("windDir", 1);
+	sTreeAnimationProgramMrt->AddParameter("windStrength", 2);
+	sTreeAnimationProgramMrt->AddParameter("minMaxPos", 3);
+	sTreeAnimationProgramMrt->AddParameter("frequency", 4);
 
 	cout << "cg initialization successful" << endl;
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ShaderProgram.h
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ShaderProgram.h	(revision 3045)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ShaderProgram.h	(revision 3046)
@@ -70,12 +70,16 @@
 	*/
 	void SetTimerParam(int idx);
-	/** This parameter is connected to the current view matrix that is updated
-		once per frame.
+	/** This parameter is connected to the current view matrix
+		that is updated once per frame.
 	*/
 	void SetViewMatrixParam(int idx);
-	/** This parameter is connected to the current view vector that is updated
-		once per frame.
-	*/
-	void SetViewVectorParam(int idx);
+	/** This parameter is connected to the current view direction 
+		that is updated	once per frame.
+	*/
+	void SetViewDirParam(int idx);
+	/** This parameter is connected to the current light direction 
+		that is updated once per frame.
+	*/
+	void SetLightDirParam(int idx);
 
 	
@@ -103,5 +107,5 @@
 	/** Function should be called once per frame to update frame related parameters.
 	*/
-	static void InitFrame(Camera *cam);
+	static void InitFrame(Camera *cam, DirectionalLight *light);
 
 
@@ -164,5 +168,6 @@
 
 	int mTimerParam;
-	int mViewVectorParam;
+	int mViewDirParam;
+	int mLightDirParam;
 	int mViewMatrixParam;
 
@@ -222,10 +227,10 @@
 	void SetArray2f(const std::string &name, float *vals, int numElements);
 	void SetArray3f(const std::string &name, float *vals, int numElements);
-	/// Sets a matrix parameter
+	/** Sets a matrix parameter
+	*/
 	void SetMatrix(const std::string &name, const Matrix4x4 &mat);
 	/** Sets the texture parameter.
 	*/
 	void SetTexture(const std::string &name, unsigned int tex);
-
 	/** Binds the program.
 	*/
@@ -234,9 +239,7 @@
 	*/
 	inline bool IsValid() const { return mProgram != NULL; }
-	/** Enable / disable a texture parameter.
-	*/
-	//void EnableTexture(const std::string &name);
-	//void DisableTexture(const std::string &name);
-
+	/** Releases all texture resources.
+	*/
+	void Release();
 
 
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp	(revision 3045)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp	(revision 3046)
@@ -714,5 +714,8 @@
 	
 
-	const bool useToneMapping = ((renderMethod == RENDER_DEPTH_PASS_DEFERRED) || (renderMethod == RENDER_DEFERRED)) && useHDR;
+	const bool useToneMapping = 
+		((renderMethod == RENDER_DEPTH_PASS_DEFERRED) || 
+		 (renderMethod == RENDER_DEFERRED)) && useHDR;
+
 
 	Vector3 sunAmbient;
@@ -883,5 +886,5 @@
 
 	// set GPU related parameters
-	GPUProgramParameters::InitFrame(camera);
+	GPUProgramParameters::InitFrame(camera, light);
 
 
